I'm running a serice under a local admin account. The service runs specific
DOS commands (eg. "dir c:\") upon request using "cmd.exe". I create a
ProcessStartInfo and enter the user credentials in the UserName, Password and
Domain fields. The start the process using the ProcessStartInfo. However,
running the process just hangs. I can see the "cmd.exe" process that has
started (task manager) using the specific user credentials, but it just
hangs.
If I do not impersonate the user in the service, all runs fine.
When I run the exact same service code as a console under the same
credentials as the service, then the process runs and returns results. Any
reason why the process would hang when running the service vs console?
John Duval - 03 Jul 2006 19:15 GMT
Hi Marius,
When you say CMD.EXE 'hangs', does that mean that the window never
appears? If so, I suspect that the process is running ok but it's not
running on the visible desktop. Try this as a test:
1) Open your service in the control panel
2) Change the service to "Log on as: Local System Account"
3) Check "Allow service to interact with desktop"
4) Run the test again
Another thing to try is to have your service write its output to a
file, and then check to see if that file exists when your test is
complete.
Hope this helps,
John
Marius - 04 Jul 2006 00:13 GMT
I have the "CreateNoWindow" set to true for the ProcessStartInfo. So no
window will hopefully attempt to be displayed. Right after starting the
process, I wait for the "HasExited" flag to be set to true, and then I try to
read the output from the standard output and error stream. "HasExited" is
never flagged. Watching the processes in the task manager, I can see the
"cmd.exe" task starting up under the impersonated user's account. It however
never finishes up. There may be some kind of prompt required, but not being
able to see the window makes things difficult.
If I do not impersonate another user, the command runs fine when running as
a service. It only appears to hang when impersonating another user.
> Hi Marius,
> When you say CMD.EXE 'hangs', does that mean that the window never
[quoted text clipped - 12 lines]
> Hope this helps,
> John
John Duval - 04 Jul 2006 17:08 GMT
Hi Marius,
Could you post some code? Preferably a minimal but complete program
that reproduces the behavior.
Thanks,
John
Peter Ritchie - 03 Jul 2006 20:19 GMT
What's the command line you are passing to cmd.exe? Are you using the \C
option?
Also, remember that each user can have specific actions run when cmd.exe
starts. See HKEY_CURRENT_USER\Software\Microsoft\Command Processor\Autorun.
...which could affect whether cmd.exe prompts the user from some input,
making it seem like it hangs.

Signature
http://www.peterRitchie.com/
> I'm running a serice under a local admin account. The service runs specific
> DOS commands (eg. "dir c:\") upon request using "cmd.exe". I create a
[quoted text clipped - 9 lines]
> credentials as the service, then the process runs and returns results. Any
> reason why the process would hang when running the service vs console?
Marius - 04 Jul 2006 00:00 GMT
I am running "dir c:\". I am using the "/c" option with cmd.exe. There is
nothing in the autorun for both the account that is running the service, and
the account being impersonated.
Like I said, running the eact same code as a console works fine. Running it
as a service seems to give the problem.
> What's the command line you are passing to cmd.exe? Are you using the \C
> option?
[quoted text clipped - 17 lines]
> > credentials as the service, then the process runs and returns results. Any
> > reason why the process would hang when running the service vs console?
mabra - 06 Jul 2006 13:51 GMT
Hi !
Just a thought. I am not familar with the process properties in .Net 2.0
[what looks you are using].
Each started process needs some desktop and you are possibly on the way
to start the new process in the same desktop, as the starter has. In
case of the started process users identity do has less rights than the
starter, it cannot access the startes desktop/winstation.
I found this starting processes with WMI, while I was logged on onto the
console as an admin, I tried to start a visible process with less
rights, which always fails for the mentioned reason. I used sysinternals
winobj then to modify the security attributes on the consiole users
dektop and this helped.
For process in .Net 2.0, I don't know.
As I said, just a thought.
Best regards,
Manfred
> I'm running a serice under a local admin account. The service runs specific
> DOS commands (eg. "dir c:\") upon request using "cmd.exe". I create a
[quoted text clipped - 9 lines]
> credentials as the service, then the process runs and returns results. Any
> reason why the process would hang when running the service vs console?