I have created software that start's a program in my AppData folder.
What I wanted to do however is to let it run with a dynamic path.
The current path I used is:
new ProcessStartInfo(@"C:\Users\user\AppData\Local\SOFTWAREPROGRAM\File\program.exe")
I want it however to make it possible to not just run on 'user' but on all users with the AppData folder. I tried the following path (which works when browsing in directories):
new ProcessStartInfo(@"%USERPROFILE%\AppData\Local\SOFTWAREPROGRAM\File\program.exe")
With this however, I get the 'file not found'-error.
How would I correct this? I want it to work on different users.
EDIT
The answer works in my program but doesn't work in the service I'm trying to develop. I have tried:
(the answer)
new ProcessStartInfo(Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\AppData\Local\SOFTWAREPROGRAM\File\program.exe"))
and
string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string specificFile = Path.Combine(folder, @"\Local\SOFTWAREPROGRAM\File\program.exe");
ProcessStartInfo(specificFile)
This works in a program (console project) but not in a service. Why is this?
I output the specificFile while running but it only contains \Local\SOFTWAREPROGRAM\File\program.exe