我从另一个调用VBScript以管理员身份运行。 以下是Invoker 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)
答案 0 :(得分:3)
您在cmd.exe之后指定了/ K,这意味着“执行命令并保持命令窗口打开”。 使用/ C代替,这意味着“执行命令并关闭命令窗口”。
如果执行“cmd.exe /?”您将获得所有参数及其描述的列表。