I am creating a service that access a folder path:
string localAppDataFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
Unfortunately, the folder returned is not:
C:\Users\mainuser\AppData\Local
... but:
C:\Windows\system32\config\systemprofile\AppData\Local
...instead.
mainuser is the user that is currently logged in. Is it possible for service to launch a program that is placed in current users AppData\Local? I am aware that you can go to Services-> Right click Properties-> Log on and type in password and account name, but I am looking for a programmatic solution, ideally using sc create command.
Alternatively, I can move all folders in interest to C:\ProgramData and completely avoid current user. Is there a way to keep the files in users AppData\Local and use programmatic solution without password?
In short, Services don't (and shouldn't) launch programs for users or access user information in general (unless they run as the specified user). They are agnostic of users and their profiles, their use-case is to run as part of the system
If you want to run an application when a user logs on, either use a group policy, or add it to the user settings to run on startup. If need be, set this up in the installer
This is the way every service works, and the norm for windows for a long time (with the exception of drivers)