Hello,
I'm working on an app that will start with Windows 7 log on. Each PC has about 30 users. Because I'm lazy and I've had some permission problems with a different app writing to the registry for this I just set the installer to create a link in the all user startup folder. I'd like to give individual users the option to not have it start up with their account only but leave everyone else's alone. I use the following code to handle an entry in the users startup folder but then I get two entries in that users startup folder and the program starts up in a window instead of minimized to system tray like it should. I've set the app to individual instance. My suspicions are that I'll have to manage the start up link in individual profiles at time of installation (and somehow add it to users as they are added to that PC). Is there an easy (lazy) way to manage this idea? I don't necessarily need to allow users the ability to not have it startup, was just an optional feature.
Private Sub chkStartWithWindows_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles chkStartWithWindows.CheckedChanged
If Not FormLoaded Then Exit Sub
My.Settings.StartWithWindows = Me.chkStartWithWindows.CheckState
My.Settings.Save()
Try
If Me.chkStartWithWindows.Checked Then
AddShortcut(Nothing, Nothing)
Else
DeleteStartupFolderShortcuts(Application.ExecutablePath)
End If
Catch ex As Exception
LogIt("ERROR putting startup startup path into startup folder." & ex.ToString)
End Try
End Sub
Private Sub AddShortcut(sender As System.Object, e As System.EventArgs)
Dim wshShell As New WshShellClass()
Dim shortcut As IWshRuntimeLibrary.IWshShortcut
Dim startUpFolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
' Create the shortcut
Try
'Try to remove existing if its there
DeleteStartupFolderShortcuts(Application.ExecutablePath)
shortcut = DirectCast(wshShell.CreateShortcut((startUpFolderPath & Convert.ToString("\")) + Application.ProductName + ".lnk"), IWshRuntimeLibrary.IWshShortcut)
shortcut.TargetPath = Application.ExecutablePath
shortcut.WorkingDirectory = Application.StartupPath
shortcut.Description = "Launch MyAppat startup"
shortcut.IconLocation = Application.StartupPath + "\MyApp.ico"
shortcut.Save()
Catch ex As Exception
LogIt("Error creating a startup folder entry. " & ex.ToString)
End Try
End Sub
Public Sub DeleteStartupFolderShortcuts(targetExeName As String)
Dim startUpFolderPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Startup)
Dim di As New DirectoryInfo(startUpFolderPath)
Dim files As FileInfo() = di.GetFiles("*.lnk")
For Each fi As FileInfo In files
Dim shortcutTargetFile As String = GetShortcutTargetFile(fi.FullName)
If shortcutTargetFile.EndsWith(targetExeName, StringComparison.InvariantCultureIgnoreCase) Then
System.IO.File.Delete(fi.FullName)
End If
Next
End Sub
You can have set by default, the user will have to start it once. .....
In your approach, once the app is installed, any user login will trigger the start if the app.