Avatar of zipnotic
zipnotic
Flag for United States of America 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_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
.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
zipnotic

8/22/2022 - Mon
arnold

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.
zipnotic

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?
arnold

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
zipnotic

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
arnold

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.
zipnotic

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
zipnotic

ASKER
Thanks much for thoughts.