24 November, 2016

Locking the screen of a Windows VM after suspending the VM in VMware Workstation

Edit the suspend-vm-default.bat script inside VM located in C:\Program Files\VMware\VMware Tools\ and add the following line before the ipconfig line:

tsdiscon console

So the entire script looks like:
@REM ########################################################################
@REM # DO NOT modify this file directly as it will be overwritten the next
@REM # time the VMware Tools are installed.
@REM ########################################################################
tsdiscon console
@%SYSTEMROOT%\system32\ipconfig /release
@REM # DO NOT REMOVE THIS LINE.  To avoid propagating any ipconfig errors, at
@REM # least one (successful) statement must follow it.

At first I tried solving the screenlocking with command:

rundll32.exe user32.dll,LockWorkStation

but that did not seem to work if executed by VMtools- probably because it was executed outside the current user session and was not able to interact with user desktop and probably got an error:

"ERROR: Input redirection is not supported, exiting the process immediately".

Atleast that is the error I saw when executing the command through psexec (-s is for SYSTEM privileges):
psexec -s "c:\test.bat"
If executing it with -s and -i (-i for interacting with user desktop) the lock screen worked fine.

For reference:
http://windowsitpro.com/systems-management/jsi-tip-5428-how-do-i-use-tsdiscon-command-disconnect-windows-2000-terminal-servi 
https://technet.microsoft.com/en-us/library/cc785434(v=ws.11).aspx

No comments:

Post a Comment