我已经使用了几年的脚本作者向我指出了这个方向。
它允许远程锁定桌面,在 Windows XP 下本地和远程工作正常,在 Windows 7 下本地工作正常,但是当尝试在 Windows 7 机器上远程使用它时它无法工作。 它已经好几年了,非常有用,但我们最近开始在现场部署 Windows 7 机器,一旦升级完全完成,我将无法再使用它。
same question几年前有人向我提出过这个问题,但没有得到答复。
这是 VBS 代码:
' StartProcess.vbs
' Sample VBScript to start a process. Inputbox for name
' Author Guy Thomas http://computerperformance.co.uk/
' Version 2.2 - December 2005
' -------------------------------------------------------'
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
最佳答案
在我的 Win7 64 位上运行 rundll32.exe user32.dll,LockWorkStation
会锁定屏幕,所以这看起来很正常。但是在查看 http://msdn.microsoft.com/en-us/library/windows/desktop/aa376875(v=vs.85).aspx 时我读了
The LockWorkStation function is callable only by processes running on the interactive desktop. In addition, the user must be logged on, and the workstation cannot already be locked.
我没有使用 WMI 的经验,但我认为 WMI 不会在交互式桌面上运行 rundll32.exe!?
关于windows-7 - 在 Windows 7 下远程锁定屏幕的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8800685/