I have a Windows service, running using the login localhost\administrator. This service is meant to invoke another executable (MyProcess.exe), which is supposed to write some stuff to a log file. The service uses Process.Start() to create the process, like so:
var p = new Process();
p.StartInfo.FileName = processFileName;
p.StartInfo.Arguments = arg;
p.Start();
Problem is, it appears that MyProcess.exe is being denied rights to write to the log file, even though localhost\administrator unquestionably has rights to the log folder. If I run MyProcess.exe from a command line, it works perfectly.
So, is it possible that the process is being executed using a different user login?
Can you think of any other reason why MyProcess.exe is being denied rights to write the log file?
UPDATE: the log file is being written to the local machine, but using a network address, i.e. \\MyPC\LogFolder. When I change the code to refer to C:\MyFolder, everything works fine. It’s obviously having a problem with the network address (even though it’s local).
What sharing settings do I need to put on the folder so that the local system account can access the file?
I’ve worked it out.
The problem, as noted in my update, is that the process was addressing the log folder using a network share address,
\\MyPC\LogFolder, and when we switched the configuration so that it wrote instead toc:\Logfolder, it worked fine.So it seems that when you address a local folder, the
localhost\Administratoraccount is deemed to have sufficient rights. But when you go via the network share, you need to present valid network credentials, andlocalhost\Administratorjust doesn’t cut it. If you change to useMYDOMAIN\MyUser, it works even using the network share address.