Question

I am trying to get some VBA code working to return a computers Ping result, Installation Date and BIOS Version (to get the date).

For i = 1 To lRow
Debug.Print i
addr1 = ActiveSheet.Cells(i, 1).Value 'this contains my IP/Computer Name

cmdPing = "C:\Windows\System32\PING.EXE " & addr1
Set shPing = CreateObject("Wscript.shell")
Set runPing = shPing.exec(cmdPing)
strPing = runPing.stdout.readall
ActiveSheet.Cells(i, 2).Value = strPing
Set runPing = Nothing
Set shPing = Nothing

cmdInstall = "systeminfo /s " & addr1 & " | findstr /C:""Install Date"""
Set shInstall = CreateObject("Wscript.shell")
Set runInstall = shInstall.exec(cmdInstall)
strInstall = runInstall.stdout.readall
ActiveSheet.Cells(i, 3).Value = strInstall
Set runInstall = Nothing
Set shInstall = Nothing

cmdBios = "systeminfo /s " & addr1 & " | findstr /C:""BIOS Version"""
Set shBios = CreateObject("Wscript.shell")
Set runBios = shBios.exec(cmdBios)
strBios = runBios.stdout.readall
ActiveSheet.Cells(i, 4).Value = strBios
Set runBios = Nothing
Set shBios = Nothing

Next i

The Ping works fine, but the systeminfo flickers on briefly and disappears. I can run with just "systeminfo /s " & addr1, but obviously that brings through a lot of unnecessary info. I have a feeling it is to do with passing the " character. Have tried /C:" & Chr(34) & " to no avail as well.

Was it helpful?

Solution

cmdInstall = "%comspec% /c systeminfo /s " & addr1 & " | findstr /C:""Install Date"""

and

cmdBios = "%comspec% /c systeminfo /s " & addr1 & " " & Chr(124) & " findstr /C:""BIOS Version"""
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top