2012-01-10 89 views
3

我被一个我一直使用了几年的脚本的作者指向了这个方向。在Windows下远程锁定屏幕的脚本7

它允许桌面的远程锁定,并在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 
+1

(HTTP [那VBS代码从未真正摆在首位 “工作”]://blogs.msdn。 COM/b/oldnewthing /存档/ 2004/01/15/58973.aspx)。 Rundll32.exe从未打算调用'LockWorkStation'函数,因为它有错误的签名。现在和解决问题一样好。 – 2012-01-10 09:13:35

+0

感谢您的链接和编辑科迪,我看到有人说,打电话给rundll32这不是一个好主意,但不明白为什么直到现在。 – 2012-01-10 09:20:29

+0

@Cody Gray:LockWorkStation不需要任何参数,所以它不会介意rundll32.exe是否传递比所需参数多的参数。 – 2012-01-10 09:29:16

回答

1

在我的Win7 64位运行rundll32.exe user32.dll,LockWorkStation锁定屏幕,所以这似乎相当确定。但看http://msdn.microsoft.com/en-us/library/windows/desktop/aa376875(v=vs.85).aspx当我只有通过 交互桌面中运行的进程读取

的LockWorkStation功能调用。另外,用户必须登录,并且工作站不能被锁定。

我对WMI没有经验,但我认为WMI不会在交互式桌面上运行rundll32.exe!

+0

即使运行rundll32.exe user32。DLL,通过psexec LockWorkStation命令不能远程工作,但本地没关系。 – 2012-01-10 12:58:28

+0

rundll32.exe命令需要在本地执行。将脚本或批处理文件复制到远程机器并执行它将起作用。 – Nilpo 2012-01-10 17:36:59

+0

我将脚本复制到目标机器上,并使用psexec \\ targetmachine cmd执行它,就像从机器中运行一样,在Windows 7下它不起作用,但XP很好。 – 2012-01-11 10:17:28

1

这是为我工作与远程Windows 7 x64系统:

psexec.exe -accepteula \\REMOTECOMPUTERNAME -i -s %windir%\system32\rundll32.exe user32.dll,LockWorkStation 

问候