windows-7 - 在 Windows 7 下远程锁定屏幕的脚本

标签 windows-7 vbscript

我已经使用了几年的脚本作者向我指出了这个方向。

它允许远程锁定桌面,在 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/

相关文章:

http - MSXML6.dll Access Denied 将 HTTP 重定向到 HTTPS

sql - 使用 Vbscript 处理大型 csv(500k 记录)并将其导入 SQL Server 的最佳方法是什么?

cmd - 如何使用 CMD 或 VBS 轻轻关闭 Chrome?

sql - ADODB 查询将 Excel 单元格更新为转义文本

vbscript - 使用 VBScript/WSH 查询 Active Directory 并导出

windows-7 - 在 Windows 7 上构建 capybara-webkit

.net - 我应该在哪里保存一个 xml 文件,以便它可以在 Windows 注销时由服务写入?

批处理数学(获胜)

Windows 7 中的 Java swing 最大化

c++ - 从 2020 年开始学习 c++ 需要 c++17 吗?