Archive for the 'Windows' Tag

Vb Net - Adding extensions to explorers context menu

Adding extensions to explorers context menu

This program will add a menu to a specific files explorer context menu.

I’ve never seen a good piece of source code to do this with, so here is a nice basic example which can be modified to do what you wish:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim RegKey As String = “ShockwaveFlash.ShockwaveFlash\shell\Open With AE H-Studio\command”

Try

If Registry.ClassesRoot.OpenSubKey(RegKey).GetValue(“”) = “” Then

”If the key exists but is blank, creates the subkey

Registry.ClassesRoot.CreateSubKey(RegKey).SetValue(“”, (ControlChars.Quote & Application.ExecutablePath & ControlChars.Quote & ” %1″))

MessageBox.Show(“Explorer Context Entry Added for .swf Files”, “Registry entry added:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

Exit Sub

Application.Exit()

End If

Catch ex As Exception

”If the key does not exist at all, OpenSubKey will error (No object refrence) and this will create the key

Registry.ClassesRoot.CreateSubKey(RegKey).SetValue(“”, (ControlChars.Quote & Application.ExecutablePath & ControlChars.Quote & ” %1″))

MessageBox.Show(“Explorer Context Entry Added for .swf Files”, “Registry entry added:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

Exit Sub

Application.Exit()

End Try

End Sub

Then, you have to add in the actual code that checks which file is being selected:

If Command() = “” Then

”If there is no command parameters, exit program

Application.Exit()

Exit Sub

End If

”This gets the fileinfo for the selected file, and calls the LoadSWF Function

Dim _file As New FileInfo(Interaction.Command)

LoadSWF(_file.FullName)

Application.Exit()

That can be placed in the Form Load even too, and it calls the sub LoadSWF (the selected file)

Public Sub LoadSWF(ByVal _path As String)

”This is where you would add in your code to handle the file loading.

”Currently it just creates a message box with the files name

MessageBox.Show(“Loaded File: “ & _path, “Success:”, MessageBoxButtons.OK, MessageBoxIcon.Asterisk)

End Sub

As you can see, its not that hard, and the code would be very easy to modify.

For example, to add a shell extension for a .exe file change RegKey to:

Dim RegKey As String = “exefile\shell\Open With Program Name\command”

VB Net - Randomly Move Mouse

 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim generator As New Random
Dim randomValue As Integer
Dim randomValue2 As Integer
randomValue = generator.Next(0, My.Computer.Screen.Bounds.Size.Height)
randomValue2 = generator.Next(0, My.Computer.Screen.Bounds.Size.Width)
Dim mousepos As Point
mousepos.X = randomValue
mousepos.Y = randomValue2
Windows.Forms.Cursor.Position = mousepos
End Sub

Every time the timer ticks, it will move the mouse randomly around the screen.

VB Net - Detect Windows Shutdown

Private Const WM_QUERYENDSESSION As Integer = 17

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
MyBase.WndProc(m)
If m.Msg = WM_QUERYENDSESSION Then
Application.Exit()
End If
End Sub