Reputation: 8818
Is there any way that one can lock a desktop computer remotely? For example, if one accidently leaves a computer logged on, would there be a way to lock that computer using Remote Connection (VPN)?
Upvotes: 6
Views: 56836
Reputation: 1
Option Explicit
Dim objWMIService, objProcess
Dim strShell, objProgram, strComputer, strExe, strInput
strExe = "rundll32.exe user32.dll,LockWorkStation"
' Input Box to get name of machine to run the process
Do
strComputer = (InputBox(" ComputerName to Run Script",_
"Computer Name"))
If strComputer <> "" Then
strInput = True
End if
Loop until strInput = True
' Connect to WMI
set objWMIService = getobject("winmgmts://"_
& strComputer & "/root/cimv2")
' Obtain the Win32_Process class of object.
Set objProcess = objWMIService.Get("Win32_Process")
Set objProgram = objProcess.Methods_( _
"Create").InParameters.SpawnInstance_
objProgram.CommandLine = strExe
'Execute the program now at the command line.
Set strShell = objWMIService.ExecMethod( _
"Win32_Process", "Create", objProgram)
'WScript.echo "Created: " & strExe & " on " & strComputer
WSCript.Quit
' End of Example of a Process VBScript
Upvotes: -1
Reputation: 2227
You can use SysInternal tools, mainly the PsShutdown tool. You would get an instance of cmd on the PC and execute the lock command.
Example:
psshutdown \\computername -l
Upvotes: 0
Reputation: 7257
Use PsExec to invoke:
rundll32.exe user32.dll, LockWorkStation
on your remote PC.
If you are currently on PC_A and want to lock PC_B, type this on your command line (on PC_A):
psexec \\\PC_B -u user -p pass "rundll32.exe user32.dll, LockWorkStation"
This way rundll32.exe user32.dll, LockWorkStation
will be invoked on PC_B.
Upvotes: 12
Reputation: 866
You can create a file with an arbitrary name and the suffix bat use this code in bat file
rundll32.exe user32.dll, LockWorkStation
save and run
Upvotes: 4