FredMunro

Hello,

As the title says is is possible for a checkbox to create a shortcut in the start menu at a specified folder

I know I would have to use the syntax

if checkstate = checked then "create shortcut"

(not accurate but you should get the general idea)

Is this possible

Thanks in advance

Fred Munro



Re: Visual Basic Language Checkbox Creating Shortcuts(VB, VS05)

nobugz

Creating shortcuts is tricky. Check this thread for a C# code sample.





Re: Visual Basic Language Checkbox Creating Shortcuts(VB, VS05)

Daniel fred Munro

Thanks for your reply,

As the shortcut is not possible is there a different way of getting my project to load with windows, but with the option to turn off/on inside the application (prefereably by checkbox)

Thanks in advance

Fred Munro





Re: Visual Basic Language Checkbox Creating Shortcuts(VB, VS05)

nobugz

The link I gave showed code that *could* create a shortcut. That's not what you want to do however. Just add a registry value to the HKCU\ Software\ Microsoft\ Windows\ CurrentVersion\ Run key. Use HKLM instead of HKCU if it should run for all users. Add a new class to your project and paste this code:

Imports Microsoft.Win32

Public Class AppLaunchAtStartup
Private Shared mKnowEnabled As Boolean
Private Shared mEnabled As Boolean
Public Shared Property Enabled() As Boolean
Get
If mKnowEnabled Then Return mEnabled
mEnabled = RunKey().GetValue(AppName) IsNot Nothing
mKnowEnabled = True
Return mEnabled
End Get
Set(ByVal value As Boolean)
If mKnowEnabled AndAlso value = mEnabled Then Exit Property
If value Then
RunKey().SetValue(AppName, Application.ExecutablePath)
Else
RunKey().DeleteValue(AppName)
End If
End Set
End Property
Private Shared Function RunKey() As RegistryKey
Return Registry.CurrentUser.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Run", True)
End Function
Private Shared Function AppName() As String
Return System.IO.Path.GetFileName(Application.ExecutablePath)
End Function
End Class

Now make your form look like this:

Public Class Form1
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
AppLaunchAtStartup.Enabled = CheckBox1.Checked
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CheckBox1.Checked = AppLaunchAtStartup.Enabled
End Sub
End Class