0

I have a windows service that runs and manages multiple processes. All the processes are running under the user account as per the task manager details tab. So one of the processes is executing a PowerShell script to do some operation that requires a local user account.

I tried logging $env:username, it says the PowerShell script is executed under the system account.

If I manually start the process without any help from the windows service then the PowerShell script executes successfully and also logs that the $env:username is locally logged in user account.

Note: the windows service is starting those processes using CreateProcessAsUser method which supposedly starts the child process under local user account. But somehow it seems that the task manager shows its running under user account but behind the scenes, it's running under the system account.

Can anyone tell me how I can execute the script under a local user account?

The cmd that I use to run the PowerShell script is

Powershell.exe -NoProfile -ExecutionPolicy Unrestricted -Command ../powershellscript.ps1
Nazim
  • 639
  • 2
  • 10
  • 26
  • 1
    while i am quite ignorant about this sort of thing, your post reads like the problem is in your c# call, not in powershell. – Lee_Dailey Jun 11 '20 at 19:44
  • You mean the call from the windows service or from the child process? – user13730021 Jun 11 '20 at 19:45
  • 1
    i don't know enuf to answer that. however, your entire post reads like the "what ever is calling powershell" is not actually doing so with the intended user account. powershell is reporting the user is one thing and you state that it otta be another ... that makes the problem something _before powershell starts_. – Lee_Dailey Jun 11 '20 at 19:47

0 Answers0