为什么我在CMD和VBS之间获得不同的结果?

发布于 2025-02-10 01:24:05 字数 657 浏览 2 评论 0原文

当我在CMD提示符中发布以下命令时,将返回Adapterram对象的正确值:

WMIC Path Win32_VideoController Get AdapterRAM

返回8589934592的正确值。但是,当我使用相同查询的VBScript使用VBScript时,将返回相同的apperram对象的不正确值:

sPC = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sPC & "\root\cimv2")
Set cSettings = objWMIService.ExecQuery("Select AdapterRAM From Win32_VideoController Where DeviceID='VideoController1'")
For Each oPC in cSettings
    GPURAMSize = oPC.AdapterRAM
    WScript.Echo GPURAMSize
Next

与同一Adapterram对象返回-1048576的不正确值。

我在这里错过了什么吗?为什么从CMD提示与VBScript使用相同的查询之间返回的值差异?

提前致谢。

When I issue the following command in a CMD prompt, the correct value is returned for the AdapterRAM object:

WMIC Path Win32_VideoController Get AdapterRAM

The correct value of 8589934592 is returned. However when I utilize VBScript with the same query, an incorrect value is returned for the same AdapterRam object:

sPC = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & sPC & "\root\cimv2")
Set cSettings = objWMIService.ExecQuery("Select AdapterRAM From Win32_VideoController Where DeviceID='VideoController1'")
For Each oPC in cSettings
    GPURAMSize = oPC.AdapterRAM
    WScript.Echo GPURAMSize
Next

The incorrect value of -1048576 is returned for the same AdapterRAM object.

Am I missing something here? Why the difference in values returned between utilizing the same query from a CMD prompt versus a VBScript?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

貪欢 2025-02-17 01:24:05

thanx在所有提出评论的人的所有帮助下,但大多数用户692942提供了帮助我解决问题的链接。这是我想到的...

strComputer = "."
Dim VideoController, PosValueBegin, PosValueEnd, Length, StringToFind
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cSetting = objWMIService.ExecQuery("Select Name, Manufacturer, Model, SystemSKUNumber, TotalPhysicalMemory From Win32_ComputerSystem")
mathConversion = 1024 * 1024 * 1024
Set cSetting = objWMIService.ExecQuery("Select DeviceID, Caption, AdapterRAM From Win32_VideoController Where DeviceID='VideoController1'")
For Each objComputer in cSetting
    GPUID = objComputer.Caption
Next
For Each objComputer in cSetting
    StringToFind = "AdapterRAM = "
    VideoController = objComputer.GetObjectText_(0)
    PosValueBegin = InStr(VideoController, StringToFind) + Len(StringToFind)
    PosValueEnd = InStr(PosValueBegin, VideoController, ";")
    Length = PosValueEnd - PosValueBegin
    ActualNumber = Mid(VideoController, PosValueBegin, Length)
    GPURAMSize = RoundUp(ActualNumber / mathConversion)
Next
wScript.Echo "GPU:  " & GPUID & " (" & GPURAMSize & "GB)"
wScript.Quit

Thanx to all the help from everyone that has contributed comments, but most especially user 692942 for providing the link that helped me solve the problem. Here's what I came up with...

strComputer = "."
Dim VideoController, PosValueBegin, PosValueEnd, Length, StringToFind
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cSetting = objWMIService.ExecQuery("Select Name, Manufacturer, Model, SystemSKUNumber, TotalPhysicalMemory From Win32_ComputerSystem")
mathConversion = 1024 * 1024 * 1024
Set cSetting = objWMIService.ExecQuery("Select DeviceID, Caption, AdapterRAM From Win32_VideoController Where DeviceID='VideoController1'")
For Each objComputer in cSetting
    GPUID = objComputer.Caption
Next
For Each objComputer in cSetting
    StringToFind = "AdapterRAM = "
    VideoController = objComputer.GetObjectText_(0)
    PosValueBegin = InStr(VideoController, StringToFind) + Len(StringToFind)
    PosValueEnd = InStr(PosValueBegin, VideoController, ";")
    Length = PosValueEnd - PosValueBegin
    ActualNumber = Mid(VideoController, PosValueBegin, Length)
    GPURAMSize = RoundUp(ActualNumber / mathConversion)
Next
wScript.Echo "GPU:  " & GPUID & " (" & GPURAMSize & "GB)"
wScript.Quit
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文