Run application from "LocalAppData" on Windows Startup

1

I want to make an app, that is located on %localappdata% folder (in a subforlder of it), to run on Windows startup, when it is installed for the user. I am able to do that if I create a string value under the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run and set it to C:\Users\my_user\AppData\Local\programs\My_App\My_App.exe" --app_id=12346.

However, I don't want to put a direct reference to my user in it. So I've tried to, instead of putting C:\Users\my_user\AppData\Local, to use %localappdata% in the String value, so it looks like %localappdata%\programs\My_App\My_App.exe" --app_id=12346.

However, using the Local App Data reference doesn't work - the app doesn't launch. I wonder if there is a way of using a reference to %LocalAppData% inside a registry key - maybe I have a syntax error?

Could you help me with it?

I've already thought of creating a bat file to call my app, and put it into C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup, but it would run for all users, and I cannot guarantee all users will have my app installed. So that wouldn't be a good choice.

Leonardo Alves Machado

Posted 2016-06-16T16:58:50.393

Reputation: 246

Answers

1

Names %AppData% and %LocalAppData% contain word "Data", giving you the hint that these directories should not be used for storing executable files. Please don't do that.

I would change the design of the entire thing.

  1. Put the application into standard location for applications:

    • if it has an installer, use %ProgramFiles%\My_App\ or %ProgramFiles(x86)%\My_App\
    • if it comes without installer, I would use something like C:\Tools\My_App\
  2. Insert autorun entries either to HKCU Registry subtree (for individual user) or into HKLM subtree (for local machine = all users)

  3. When the application is launched, it has full access to name of user, paths of all user directories etc. So start doing your user-dependent stuff only after the application was launched. This way you are no longer dependent on location of EXE file or similar magic.

miroxlav

Posted 2016-06-16T16:58:50.393

Reputation: 9 376