如何在成功执行 VBScript 后关闭 CMD 提示 window
How to Close the CMD prompt window after successfull execution of VBScript
我正在以管理员身份从另一个 运行 调用 VBScript。
以下是调用程序 VBScript 代码
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cscript", "C:\Temp\XYZ.vbs", "", "runas", 0
Wscript.Quit 1
以下是XYZ.vbs代码
On Error Resume Next
Dim strComputerRole, strDomain, strComputer, strText, strText2
Dim arrServiceList, strNextLine
Dim objFile, objFile2, strFile, strSysDrive, strTempDir, strSQLcommand
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = wscript.createObject("Wscript.Shell")
Set colProcEnvVars = objShell.Environment("Process")
Set colSystemEnvVars = objShell.Environment("System")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
strSysDrive = colProcEnvVars("systemdrive")
strTempDir = colProcEnvVars("SY0")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
If strSysDrive = "" Then
strSysDrive = "C:"
End If
If strTempDir = "" Then
strTempDir = strSysDrive & "\Temp"
End If
If Not objFSO.FolderExists(strTempDir) Then
objFSO.CreateFolder(strTempDir)
End If
strFile = strSysDrive & "\temp\XYZ.txt"
strSQLcommand="osql -o "& strFile & " -d HOST -E -Q ""************Select Query******** """
Set objExecObject = objShell.Exec(strSQLcommand)
以下 OSQL cmd 已成功执行。但是执行后,我打开了这个 CMD 提示 window。
有没有办法在成功执行后关闭命令提示符?
您在 cmd.exe 之后指定了 /K,这意味着 "Execute command and keep command window open"。
请改用 /C,这意味着 "Execute command and close command window then".
如果您执行 "cmd.exe /?",您将获得所有参数及其描述的列表。
我正在以管理员身份从另一个 运行 调用 VBScript。 以下是调用程序 VBScript 代码
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cscript", "C:\Temp\XYZ.vbs", "", "runas", 0
Wscript.Quit 1
以下是XYZ.vbs代码
On Error Resume Next
Dim strComputerRole, strDomain, strComputer, strText, strText2
Dim arrServiceList, strNextLine
Dim objFile, objFile2, strFile, strSysDrive, strTempDir, strSQLcommand
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = wscript.createObject("Wscript.Shell")
Set colProcEnvVars = objShell.Environment("Process")
Set colSystemEnvVars = objShell.Environment("System")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")
strSysDrive = colProcEnvVars("systemdrive")
strTempDir = colProcEnvVars("SY0")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
If strSysDrive = "" Then
strSysDrive = "C:"
End If
If strTempDir = "" Then
strTempDir = strSysDrive & "\Temp"
End If
If Not objFSO.FolderExists(strTempDir) Then
objFSO.CreateFolder(strTempDir)
End If
strFile = strSysDrive & "\temp\XYZ.txt"
strSQLcommand="osql -o "& strFile & " -d HOST -E -Q ""************Select Query******** """
Set objExecObject = objShell.Exec(strSQLcommand)
以下 OSQL cmd 已成功执行。但是执行后,我打开了这个 CMD 提示 window。
有没有办法在成功执行后关闭命令提示符?
您在 cmd.exe 之后指定了 /K,这意味着 "Execute command and keep command window open"。 请改用 /C,这意味着 "Execute command and close command window then".
如果您执行 "cmd.exe /?",您将获得所有参数及其描述的列表。