views:

14486

answers:

5

I'm currently running Vista and I would like to manually complete the same operations as my Windows Service. Since the Windows Service is running under the Local System Account, I would like to emulate this same behavior. Basically, I would like to run CMD.EXE under the Local System Account.

I found information online which suggests lauching the CMD.exe using the DOS Task Scheduler AT command, but I received a Vista warning that "due to security enhancements, this task will run at the time excepted but not interactively." Here's a sample command:

AT 12:00 /interactive cmd.exe

Another solution suggested creating a secondary Windows Service via the Service Control (sc.exe) which merely launches CMD.exe.

C:\sc create RunCMDAsLSA binpath= "cmd" type=own type=interact
C:\sc start RunCMDAsLSA

In this case the service fails to start and results it the following error message:

FAILED 1053: The service did not respond to the start or control request in a timely fashion.

The third suggestion was to launch CMD.exe via a Scheduled Task. Though you may run scheduled tasks under various accounts, I don't believe the Local System Account is one of them.

I've tried using the Runas as well, but think I'm running into the same restriction as found when running a scheduled task.

Thus far, each of my attempts have ended in failure. Any suggestions?

A: 

Found an answer here which seems to solve the problem by adding /k start to the binPath parameter. So that would give you:

sc create testsvc binpath= "cmd /K start" type= own type= interact

However, Ben said that didn't work for him and when I tried it on Windows Server 2008 it did create the cmd.exe process under local system, but it wasn't interactive (I couldn't see the window).

I don't think there is an easy way to do what you ask, but I'm wondering why you're doing it at all? Are you just trying to see what is happening when you run your service? Seems like you could just use logging to determine what is happening instead of having to run the exe as local system...

Bryant
Hi Bryant. This solution is essentially outlined in the question. Does it actually work for you? It is resulting in a failure for me. Thanks.
Ben Griswold
Bryant, I have a Service which manages the install and uninstall of another component. I want give our support group an easy way to "forcefully" uninstall the component if my Service fails to do its job. While testing, I would like to be able to "force" the uninstall as well. Thx for the help..
Ben Griswold
A: 

if you can write a batch file that does not need to be interactive, try running that batch file as a service, to do what needs to be done.

A: 

I can see wanting to do this, but I'd really consider creating a user for this service instead.

But if you must, Bryant's method, although hacky, seems to work fine.

+4  A: 

I would recommend you work out the minimum permission set that your service really needs and use that, rather than the far too privileged Local System context. For example, Local Service.

Interactive services no longer work - or at least, no longer show UI - on Windows Vista and Windows Server 2008 due to session 0 isolation.

Mike Dimmick
Mike, thanks for the response. Though I agree with your recommendation and I think everyone will benefit from your answer, I don't believe you have answered the question.
Ben Griswold
@Ben Griswold: He does, however, point out exactly what it is that makes the old way fail in Vista. +1.
SamB
+10  A: 

Though I haven't personally tested, I have good reason to believe that the above stated AT COMMAND solution will work for XP, 2000 and Server 2003. Per my and Bryant's testing, we've identified that the same approach does not work with Vista or Windows Server 2008 -- most probably due to added security and the /interactive switch being depreciated.

However, I came across this article which demonstrates the use of PSTools from SysInternals (which was acquired by Microsoft in July, 2006.) I launched the command line via the following and suddenly I was running under the Local Admin Account like magic:

psexec -i -s cmd.exe

PSTools worked great. It's a lightweight, well-documented set of tools which, in my opinion, provide an appropriate solution to my problem.

Many thanks to those who offered help.

Ben Griswold
Glad you found a solution!
Bryant
I like this better with `-d` added, so that I can continue to use the console I launched it from.
SamB
I just tried on Vista x64 and got "The PsExec service running on ... is an incompatible version."Tried direct from \\live.sysinternals.com\tools\psexec and latest binary. There doesn't seem to be x64 version
ZXX