Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to launch cmd.exe in session 0. So far I've done the following from an elevated command prompt:

sc config UI0Detect start= auto
net start UI0Detect

And the response indicates that the service was started correctly. It is at this point that I assumed if I switched to session 0, cmd.exe would be running.

I switch to session 0 using the following command:

rundll32 winsta.dll,WinStationSwitchToServicesSession

This successfully switches me to session 0, but the only window that's available is the one that has the option to return to session 1.

How do I get cmd.exe to launch in session 0?

share|improve this question
    
Why would you want to do this? UI0Detect allows old services to pop up a message box, not starting new GUI Apps. cmd.exe has a GUI –  Peter Hahndorf May 21 '12 at 4:56
2  
@PeterHahndorf I understand that it's fun to deflect answering questions by saying "let's take a step back and see if this is what we really need to do because this sounds like a bad idea", and it's a relatively nice way to condescend fellow developers. But since this is for a debugging scenario and meant to be a quick fix (and alternative to using some 3rd party app like AlwaysUp), I don't really see how asking "why" is a helpful response. Thanks anyway. –  omghai2u May 21 '12 at 5:12
    
I think Peter has a point. The question you should have wrote is "This is what I'm trying to do." A quick fix will only involve future pain. I can't count how many times I've heard "quick fix" only to still see the "quick fix" in production three years later. . . needing another "quick fix". I'm assuming you are typing to run a batch script of some sort? –  surfasb May 21 '12 at 8:54
    
@surfasb The question you suggested is essentially the question I wrote: "I'm trying to launch cmd.exe in session 0." Please keep answers focused on that question. Thanks. And there's no chance this will make its way into production, or for it to involve future pain. The way I do it for production is already set but I can't use it for debugging. The way I currently do it for debugging is cumbersome and involves using a 3rd party app. –  omghai2u May 21 '12 at 19:20
add comment

2 Answers

To launch cmd.exe in session 0, use psexec from Sysinternals

psexec.exe -s 0 cmd.exe

Now you have a console running in session 0,

you can also start cmd.exe in session 0 and display GUI:

psexec.exe -s -i 0 cmd.exe

that way when you switch to session 0, the cmd.exe will be waiting for you there.

you have as many rights as you can get in Windows 7:

whoami /all

if you use other PsTools, remember to use the /accepteula switch:

pslist /accepteula

otherwise the program pops up a message box to ask to accept the Eula, the program will hang because there is no UI in session 0 to close the message box.

To verify that you are running in session 0, you can use qprocess:

qprocess /ID:0

you will see your 'cmd.exe' among all the service processes.

share|improve this answer
    
Awesome thanks for attempting to answer my question. This would certainly work, my specific intention (as pointed out in the comments), however was to avoid using 3rd party apps. Is there a nice way to do this that doesn't necessitate the use of SysInternals tools (or really anything that doesn't come stock on Windows)? Thanks again. –  omghai2u May 23 '12 at 23:58
    
I don't consider the Sysinternal tools '3rd party' they are from Microsoft and you don't have to install them. –  Peter Hahndorf May 24 '12 at 5:15
    
Sorry, I was considering anything not installed by default "3rd-party". –  omghai2u May 27 '12 at 23:47
    
Peter. Awesome, thank you. Works perfectly for starting a process in session 0 (which means it keeps running when you log off.) –  Daniel James Bryars Oct 22 '13 at 1:51
1  
The first command line is wrong: -s runs as SYSTEM user and doesn't take an argument. Perhaps you meant -i 0 in the first example and -s -i 0 in the second one? –  jwg Mar 5 at 9:46
add comment

It won't work. It merely starts a process as System.

Services are programs written in a special way to accept commands from the service controll manager.

MS has a utility that allows running a program as a service. It's called Srvany and is in the Windows 2003 Resource Kit Tools.

http://www.microsoft.com/en-au/download/details.aspx?id=17657

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.