Search This Blog

Wednesday, January 14, 2015

Run command in system context

Sometimes I need to test program, scripts and so on running in system context, just to see if its working.

For this I always use an old friend from sysinternals PSEXEC.

http://technet.microsoft.com/en-us/sysinternals/bb897553

So let start a command prompt as SYSTEM:

Use the command: psexec -s cmd.exe

image

First time you start PSEXEC you must accept License Terms or use the parameter –accepteula to suppress the display of the license dialog:

image

And now we have a command prompt in SYSTEM context where we can test for example our script to see if if works in SYSTEM context.

This would be nice to try before running it in a SCCM Task Sequence or a Scheduled Task running in SYSTEM context.

To prove that we actual are running as SYSTEM we can try the command whoami.

And as you can see here it should reply nt authority\system

image

Use the command EXIT to return to the original command prompt.

image

PSEXEC will also work remote so let try the same on a remote computer:

psexec \\RemoteComputer -s cmd.exe –accepteula

image

And lets see on which computer we are running on by using the command HOSTNAME:

image

Again use exit to return to your local system.

Tuesday, January 6, 2015

How long has this system been running

I often need a quick way to see how long a Windows box has been running, or actually when it was last restarted Smile

One way is to use the command net statistics workstation and find Statistics since:

image

And of course PowerShell is nowadays also an option:

Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime

Note that this requires PowerShell 3.0 and that the time is 2 seconds before the time from net statistics.

image