Start App with Windows 7 all profiles vs individual profile

zipnotic
zipnotic used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017

Commented:
Why create links during install when you could include the option to start on logon as part of the programs settings.
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.

Author

Commented:
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?
Distinguished Expert 2017

Commented:
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.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Author

Commented:
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
Distinguished Expert 2017

Commented:
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.

Author

Commented:
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.
Distinguished Expert 2017
Commented:
You could iterate through every local profile, the issue deals with roaming.

Another option is to place a link to a script that on first login prompts for whether they need this apprunning, if yes, an entry the script checks for is added to the user as well as a login in the user's startup/login for the application to start minimized.

This way each user will be prompted once and will act accordingly there after.

Placing the shortcut on the desktop with default to run at startup registered on first run will be better in IMHO.

Author

Commented:
Thanks much for thoughts.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial