VBA查找远程计算机的安装日期和Bios日期

标签 vba shell excel wsh

我正在尝试让一些 VBA 代码返回计算机 Ping 结果、安装日期和 BIOS 版本(以获取日期)。

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

Ping 工作正常,但系统信息短暂闪烁并消失。我可以只使用 "systeminfo/s "& addr1 运行,但显然这会带来很多不必要的信息。我有一种感觉,这与传递 " 字符有关。也尝试过 /C:"& Chr(34) & " 但无济于事。

最佳答案

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

cmdBios = "%comspec% /c systeminfo /s " & addr1 & " " & Chr(124) & " findstr /C:""BIOS Version"""

关于VBA查找远程计算机的安装日期和Bios日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22633787/

相关文章:

excel - 如何在 VBA 中找到第一个空单元格?

forms - 转到父表单中的新记录

linux - 如何在 linux shell 上显示完整输出?

java - 如何将Excel单元格值转换为字符串类型?在Excel中将单元格设置为文本类型不起作用

vba - 仅将格式从一个单元格复制到其他单元格

windows - 如何将控制台输出重定向到文件并仍然在控制台中获取它?

c - 如何将 ./a.out 的结果存储到文本文件

vba - 从文本文件中读取数据并分隔

Excel VBA - 条件格式,索引不包含在间隔中

excel - 将单元格格式化为其他单元格时出现错误 `xlValues` is not defined