I am using C# to write a Windows Service to monitor an application written in Python. The Python app writes some files to AppDataLocalCustomFolder of non-admin, logged-in user.
I need to monitor those files from this C# Windows Service but when I get the path:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Custom", "Folder");
it gives me the path to SYSTEM user’s folder.
How can I get the username or the path to AppDataLocal folder of the user of Python app?
And when I go to service.exe > MyService > Properties > Log On > and change the user to non-admin user, it gives me the correct path I want.
OR can I somehow pass username from Python app to this service. I tried environmental variables but I couldn’t get C# service to read that variable. I invoked Python interpreter from admin powershell and set
os.environ["CUSTOM_DIR"] = "pathtofolder"
but C# service didn’t get it.
If someone needs more code, it’s here. I have not written code to monitor the file yet. I want to resolve the path issue first.
3