Testing Under the Local System Account |
If your MSIs normally get automatically deployed and installed under the SYSTEM account then you would probably want to test your MSIs in a manner as close as possible to this.
To do any initial testing (particularly while developing or modifying the MSI), the deployment process is probably either impossible or too time (or effort) consuming for you to duplicate the "proper" install mechanism.
Once you have opened up a command prompt you can then install the MSI. Just remember to add any MSI properties or flags that the deployment process might add to the MSIEXEC.EXE command line ("ALLUSERS=1" is probably one you will always need unless this is built into your MSIs).
I have described all of the ways I have used to open command prompts under the local system account as one or more may fail on some machines. If none of the approaches works (which I have seen on some boxes), this will likely be because of policies on the box preventing it.
Use Batch File With 'SC.EXE' |
This batch file requires "SC.EXE" to be available:
@echo off @REM ************************************************************************ @rem *** Version 08.240, written By: Dennis Bareis (dbareis at gmail.com) *** @rem *** BASED ON "http://blogs.msdn.com/adioltean/articles/271063.aspx" *** @REM ************************************************************************ cls SetLocal for %%x in (".") do set CurrentDir=%%~fx set ServiceDesc=$CMD.EXE (under SYSTEM account) set ServiceCmd=cmd.exe /C start \"%ServiceDesc% - %CurrentDir%\" CMD.EXE /K CD /D "%CurrentDir%" sc.exe create $LocalSystem binpath= "%ServiceCmd%" type= own type= interact DisplayName= "%ServiceDesc%" sc.exe start $LocalSystem sc.exe delete $LocalSystem
The batch file will open the prompt at the current directory. Just ignore the error message that may (probably will) appear (as long as the new command prompt opens) as "CMD.EXE" wasn't designed to be used as a service.
Use SysInternals 'PsExec.EXE' |
This shows how ths sysinternals program "PSEXEC.EXE" can be used to open a command prompt running under the system account:
PsExec.exe -s CMD.EXE
The above step does create a permanent service which runs "PSEXESVC.EXE".
Use 'CmdAsUser.EXE' |
This program (available from "http://www.pluralsight.com/books/pws/samples.htm") allows you to open up a Windows command prompt running under the SYSTEM account (or any other user account).
The command to use is:
CmdAsUser.exe LocalSystem