zipnotic
asked on
Start App with Windows 7 all profiles vs individual profile
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_Checke dChanged(s ender As System.Object, e As System.EventArgs) Handles chkStartWithWindows.Checke dChanged
If Not FormLoaded Then Exit Sub
My.Settings.StartWithWindo ws = Me.chkStartWithWindows.Che ckState
My.Settings.Save()
Try
If Me.chkStartWithWindows.Che cked Then
AddShortcut(Nothing, Nothing)
Else
DeleteStartupFolderShortcu ts(Applica tion.Execu tablePath)
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.IWshSho rtcut
Dim startUpFolderPath As String = Environment.GetFolderPath( Environmen t.SpecialF older.Star tup)
' Create the shortcut
Try
'Try to remove existing if its there
DeleteStartupFolderShortcu ts(Applica tion.Execu tablePath)
shortcut = DirectCast(wshShell.Create Shortcut(( startUpFol derPath & Convert.ToString("\")) + Application.ProductName + ".lnk"), IWshRuntimeLibrary.IWshSho rtcut)
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 DeleteStartupFolderShortcu ts(targetE xeName As String)
Dim startUpFolderPath As String = Environment.GetFolderPath( Environmen t.SpecialF older.Star tup)
Dim di As New DirectoryInfo(startUpFolde rPath)
Dim files As FileInfo() = di.GetFiles("*.lnk")
For Each fi As FileInfo In files
Dim shortcutTargetFile As String = GetShortcutTargetFile(fi.F ullName)
If shortcutTargetFile.EndsWit h(targetEx eName, StringComparison.Invariant CultureIgn oreCase) Then
System.IO.File.Delete(fi.F ullName)
End If
Next
End Sub
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_Checke
If Not FormLoaded Then Exit Sub
My.Settings.StartWithWindo
My.Settings.Save()
Try
If Me.chkStartWithWindows.Che
AddShortcut(Nothing, Nothing)
Else
DeleteStartupFolderShortcu
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.IWshSho
Dim startUpFolderPath As String = Environment.GetFolderPath(
' Create the shortcut
Try
'Try to remove existing if its there
DeleteStartupFolderShortcu
shortcut = DirectCast(wshShell.Create
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 DeleteStartupFolderShortcu
Dim startUpFolderPath As String = Environment.GetFolderPath(
Dim di As New DirectoryInfo(startUpFolde
Dim files As FileInfo() = di.GetFiles("*.lnk")
For Each fi As FileInfo In files
Dim shortcutTargetFile As String = GetShortcutTargetFile(fi.F
If shortcutTargetFile.EndsWit
System.IO.File.Delete(fi.F
End If
Next
End Sub
ASKER
Funny story. That was my initial approach but I found the users were too afraid/ could t find/ didn't bother to run it ONCE. Since they need it running they complained "something was wrong".
Perhaps iterating through the user folders found during install and placing there?
Perhaps iterating through the user folders found during install and placing there?
Instead of auto starting it for every logon, do you create a shortcut link on the desktop, start page?
That might be a better approach I.e they do not have to search for the application in the start, programs menu.
That might be a better approach I.e they do not have to search for the application in the start, programs menu.
ASKER
I created a start up entry that shows up in everyone's folder. Removing it from one profile removes it from all. My code places an entry in that users folder which looks to be the same place but is actually a different roaming /user folder
I do not understand your last post.
During the install you can not account for all possible variations.
During the install, instead of linking into the all users profile consider adding it to the default user, but the issue will remain with existing user profiles, the default user will only impact new users.
During the install you can not account for all possible variations.
During the install, instead of linking into the all users profile consider adding it to the default user, but the issue will remain with existing user profiles, the default user will only impact new users.
ASKER
The installer currently creates an entry in the startup folder for all users. It works out OK but the app is thenrunning for everyone regardless if they need it or not. It should be possible to iterate through every profile and put a link in each users startup? Can I run that code as part of the installer? Will I have permission problems?
Maybe its better just to leave it since 97% of the time users will want the program and if they don't need it then it won't bother anyone. It just takes info from one program and transforms it for another.
Maybe its better just to leave it since 97% of the time users will want the program and if they don't need it then it won't bother anyone. It just takes info from one program and transforms it for another.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks much for thoughts.
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.