我试图在shell中使用PSEXEC获取少数服务器的磁盘状态并将其附加到表中。但我只从shell结果中获取标题。
这是我的代码:
Option Compare Database
Option Explicit
Const svrUname = "username"
Const svrPass = "password"
Const ForReading = 1
Sub First()
Dim svr(2, 1) As String
svr(0, 0) = ""
svr(0, 1) = "server name"
svr(1, 0) = "PSEXEC \\(IPADD) -u " & svrUname & " -p " & svrPass "
svr(1, 1) = ""
Dim i As Integer
For i = 0 To 1
Call ShellRun(svr(i, 0) & "WMIC logicaldisk get size, caption, " _
& "freespace", svr(i, 1))
Next
End Sub
Public Sub ShellRun(sCmd As String, svrName As String)
' Run a shell command, returning the output as a string
Dim oShell As Object
Dim oExec As Object
Dim oOutput As Object
Dim a As String
' Run command
Set oShell = CreateObject("Wscript.Shell")
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
' handle the results as they are written to and read from the StdOut object
Dim sInfo As String
Dim sLine As String
While Not oOutput.AtEndofStream
sLine = oOutput.Readline
Call EXTRACTINFO(sLine, svrName)
a = a & sLine
SKIP:
Wend
MsgBox a
oExec.Terminate
End Sub
什么似乎是问题?
答案 0 :(得分:1)
如果我运行此代码:
Sub First()
Const svrUname = "username"
Const svrPass = "password"
Const ForReading = 1
Dim svr(2, 1) As String
svr(0, 0) = ""
svr(0, 1) = "server name"
svr(1, 0) = "PSEXEC \\(IPADD) -u " & svrUname & " -p " & svrPass
svr(1, 1) = ""
Dim i As Integer
For i = 0 To 0
Call ShellRun(svr(i, 0) & "WMIC logicaldisk get size, caption, " _
& "freespace", svr(i, 1))
Next
End Sub
Public Sub ShellRun(sCmd As String, svrName As String)
' Run a shell command, returning the output as a string
Dim oShell As Object
Dim oExec As Object
Dim oOutput As Object
Dim a As String
' Run command
Set oShell = CreateObject("Wscript.Shell")
Set oExec = oShell.Exec(sCmd)
Set oOutput = oExec.StdOut
' handle the results as they are written to and read from the StdOut object
Dim sInfo As String
Dim sLine As String
While Not oOutput.AtEndofStream
sLine = oOutput.Readline
'Call EXTRACTINFO(sLine, svrName)
a = a & sLine
SKIP:
Wend
MsgBox a
oExec.Terminate
End Sub
它返回:
请仔细检查您的EXTRACTINFO功能。
命令文件:
C:\Folder\PsExec \\server -u user -p password WMIC logicaldisk get size, caption, freespace > C:\SomeFolder\DiskSize.txt
然后阅读此文件。