我正在尝试自动化我的流程。我需要询问用户计算机名称ex:SH010123将其作为变量存储。启动cmd提示符。输入psexec\\"computername" cmd
然后我需要输入net use t: \\network\path password /user:domain\username
,然后输入\\network\path\"my file.bat"
我无法弄清楚如何使用vbscript将这些输入发送到cmd窗口。
答案 0 :(得分:0)
虽然可以绕过向cmd窗口发送输入来实现解决方案,但这里是一个如何将命令发送到cmd并返回某些输出的示例:
Dim oShell, oExec
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.exec("%comspec%")
oExec.StdIn.Write "dir" & vbCrLf
oExec.StdIn.Write "cd c:\" & vbCrLf
oExec.StdIn.Write "dir" & vbCrLf
oExec.StdIn.Write "exit" & vbCrLf
ShowInNotepad oExec.StdOut.readall
Sub ShowInNotepad(strTest)
Dim TempPath
With CreateObject("Scripting.FileSystemObject")
TempPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\" & .GetTempName
With .CreateTextFile(TempPath, True, True)
.WriteLine(strTest)
.Close
End With
CreateObject("WScript.Shell").Run "notepad.exe " & TempPath, 1, True
.DeleteFile(TempPath)
End With
End Sub