Sud*_*amy 2 vbscript cmd wsh shellexecute
我正在从另一个调用 VBScript 以管理员身份运行。以下是 Invoker VBScript 代码
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cscript", "C:\Temp\XYZ.vbs", "", "runas", 0
Wscript.Quit 1
Run Code Online (Sandbox Code Playgroud)
以下是 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)
Run Code Online (Sandbox Code Playgroud)
您在 cmd.exe 之后指定了 /K ,这意味着“执行命令并保持命令窗口打开”。使用 /C 代替,这意味着“然后执行命令并关闭命令窗口”。
如果执行“cmd.exe /?” 您将获得所有参数及其说明的列表。