2011-08-10 9 views
0


我正在寫一個小的VBScript,禁用Windows XP開始菜單中的關閉選項,並在第二天重新啓用它。
該腳本是爲了在有限的特權用戶登錄上運行。由於此用戶沒有權限更改Windows註冊表,因此它必須由管理員帳戶運行。
我設置了一個計劃任務,該計劃任務通過限制用戶登錄as explained here, point 5的管理員帳戶運行腳本。
下面是問題:在對Windows註冊表應用更改後,我必須重新啓動該用戶的explorer.exe才能使更改生效。我的腳本無法做到這一點。它可以殺死explorer.exe,但由於某種原因無法重新啓動它。
請注意,如果我直接從管理員帳戶更改管理員帳戶的註冊表設置並重新啓動管理員帳戶explorer.exe運行腳本,該腳本將完美地工作。
下面的代碼的部分:VBScript - 重新啓動另一個用戶的explorer.exe

Option Explicit 
Const RegKey = "HKEY_USERS\LIMITED USER SID HERE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoClose" 
Const BackupDay = 5 'sunday = 1 
Dim WshShell 

Set WshShell = WScript.CreateObject("WScript.Shell") 

If Weekday(Date) = BackupDay Then 

    If WshShell.RegRead(RegKey) = 0 Then 

     WshShell.Run "msg * __Message Here__" 
     Wscript.Sleep 500 

     WshShell.RegWrite RegKey, 1, "REG_DWORD" 

     RestartExplorer1 
     ' RestartExplorer2 

     WScript.quit 

    Else 

[...]

Sub RestartExplorer1() 

Dim strComputer, strProcessToKill, objWMIService, colProcess, objProcess 

strComputer = "." 
strProcessToKill = "explorer.exe" 

Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" _ 
    & strComputer _ 
    & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _ 
    ("Select * from Win32_Process Where Name = '" & strProcessToKill & "'") 

For Each objProcess in colProcess 
    objProcess.Terminate() 

Next 
End Sub 

程序RestartExplorer1要殺死所有的explorer.exe進程(包括管理員的一個,它的確定,因爲他應如此註銷不應該有一個,除了我可以通過用戶名篩選並殺死用戶的一個,但這不是問題),但如果從管理員帳戶的計劃任務運行,則完全沒有任何問題。
RestartExplorer2有沒有更好的運氣:

Sub RestartExplorer2() 

WshShell.Run "cmd /c Taskkill /F /IM explorer.exe" 
WScript.Sleep 500 
WshShell.Run "cmd /c Start explorer.exe" 

End Sub 

在這種情況下的explorer.exe確實喪生,但由於某種原因,它沒有重新啓動。
我到處搜索沒有結果。
任何幫助,非常感謝,謝謝。

回答

0

通過使用Windows中的RunAs功能,您可以在另一個用戶帳戶下重新啓動Explorer.exe進程。試試這個:

Dim objShell, strUsername, strPassword 
strUsername = "username" 
strPassword = "password" 

Set objShell= WScript.CreateObject("WScript.Shell") 
objShell.Run "runas /user:" & strusername & " ""explorer.exe""" 

WScript.Sleep 100 

objShell.Sendkeys strPassword & "~" 
WScript.Quit 
+0

嗨Nilpo,謝謝你的幫助。不幸的是,runas不是我的問題的解決方案,我已經嘗試過,沒有結果。 – Giovanni