2

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.

0

2 Answers 2

2

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.

2
  • Please note that the statement that these folders contain Data so should not contain executables is false. In fact, it is standard to install programs that are not installed for all users but a single user in %LocalAppData%\Programs.
    – Nils O
    Commented Dec 7, 2023 at 15:15
  • @NilsO – thank you for the note. I found a source backing your information. In this concrete question it appears that changing the architecture of OP's solution resolved their problem. Maybe the original problem were double quotes as mentioned in Chris Davies' answer.
    – miroxlav
    Commented Dec 13, 2023 at 0:05
2

Windows 10 understands %LocalAppData% in its Run and RunOnce registry entries - I'm using them successfully in a GPO.

Don't forget to ensure that if the executable path may contain spaces that the double-quotes go at both ends of the string. (Although this is four years too late for you, one reason perhaps that your own attempt didn't work is that what you've shown us has only one double-quote mark instead of a pair.)

1
  • 1
    Well, I'm not working for the same company, and I can't remember about those double-quote. But it is good to know it would work. Commented Oct 9, 2020 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .