Difference between revisions of "SYSTEM user Command Prompt"

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search
m
Line 15: Line 15:
 
>NUL 2>NUL sc delete systemcmd
 
>NUL 2>NUL sc delete systemcmd
 
</source>
 
</source>
 +
  
 
To verify that it worked, run the command '''<tt>set user</tt>''' at the prompt.  The output should look like:
 
To verify that it worked, run the command '''<tt>set user</tt>''' at the prompt.  The output should look like:

Revision as of 16:56, 25 May 2010

Sometimes while testing or debugging scripts and applications, it is useful to run programs as the SYSTEM user (also called NT AUTHORITY\SYSTEM or LocalService account). This is the user context under which most services run. So, for example, if one is testing a workstation startup script, he would want to execute it as the SYSTEM user since that is the user account that runs system startup scripts.

Usage

Copy and paste the following lines into a text file and save it as systemcmd.bat. When you execute the script, you should be presented with a Command Prompt with a current working directory of c:\windows\system32.

@ECHO OFF
::  systemcmd.bat
::
::  This bat file starts a command window (cmd.exe) under the SYSTEM (aka LocalSystem)
::  user context.  Running this script requires Administrator rights on the local 
::  workstation.

>NUL 2>NUL sc create systemcmd binpath= "cmd /C start" type= own type= interact
>NUL 2>NUL net start systemcmd
>NUL 2>NUL sc delete systemcmd


To verify that it worked, run the command set user at the prompt. The output should look like:

c:\windows\system32>set user
USERPROFILE=C:\Documents and Settings\LocalService

c:\windows\system32>