在Windows 8.1上从VBScript启动任务管理器

时间:2015-10-21 10:37:19

标签: vbscript

在Windows 8之前的Windows版本上,我的安装程序使用类似于此脚本的VB脚本来启动任务管理器:

' StartProcessLocal.vbs
' Free example VBScript to start a process (not interactive)
' Author Guy Thomas
' Version 1.8 - December 2010
' -------------------------------------------------------' 
Option Explicit
Dim objWMIService, objProcess, objCalc
Dim strShell, objProgram, strComputer, strExe 

strComputer = "."
strExe = "Taskmgr.exe"
' 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 

这不会在Windows 8.1上启动任务管理器。

Taskmgr.exe在System32目录中,当我双击它时,它就可以正常启动了。它从命令提示符开始正常:> Taskmgr.exe

在上面的示例中,如果使用Calc.exe更改Taskmgr.exe,则会启动计算器。 Calc.exe也在System32文件夹中。

为什么上面的脚本不能启动任务管理器?

1 个答案:

答案 0 :(得分:2)

你是否试图通过这种方式启动它?

Option Explicit
Dim Application
Application = "%windir%\system32\Taskmgr.exe"
Call RunThis(Application)
'*********************************************************************************
Sub RunThis(Application)
    Dim Ws,Result
    Set Ws = CreateObject("WScript.Shell")
    Result = Ws.Run(DblQuote(Application),1,False)
End Sub
'*********************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'*********************************************************************************