How get real time voltage? - windows

Is there a way to retrieve the voltage being supplied to a computer in real time?

You can use WMI to get some of that information. I used the WMI Code Creator to come up with this VB script which returns the Win32_Processor CurrentVoltage value. If you have a laptop, there is also some battery information available in WMI.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Processor",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_Processor instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "CurrentVoltage: " & objItem.CurrentVoltage
Next

Related

How can I retrieve the LAN adapter MAC address?

I want to retrieve the MAC address from a Windows system, only for LAN Adapter. Can you suggest to me how I'd handle this in VBScript?
I'm currently using this VBScript for getting the MAC address, but this is giving me results for all adapters, while I only want the MAC address when I am connected with LAN Adapter.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.ServiceName <> "VMnetAdapter" AND isNull(objItem.MACAddress)=0 Then
Wscript.Echo objItem.MACAddress
Wscript.Echo objItem.ServiceName
End if
Next
Use the Win32_NetworkAdapter class instead of the Win32_NetworkAdapterConfiguration class. The latter doesn't have a property providing the adapter name.
adaptername = "LAN Adapter"
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = '" & adaptername & "'"
For Each adapter In wmi.ExecQuery(qry)
If Not IsNull(adapter.MACAddress) Then Wscript.Echo adapter.MACAddress
Next
how about this
way 1:
if possible try to exclude all not required adapters (excluded VmWare and VirtualBox). of couse, on some computers could be more specific adapters which you need to find out and exclude
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
if objItem.ServiceName <> "VMnetAdapter" and objItem.ServiceName <> "VBoxNetAdp" and objItem.ServiceName <> "" and isNull(objItem.MACAddress) = 0 Then
Wscript.Echo objItem.ServiceName & vbCrLf & objItem.MACAddress
End if
Next
way 2:
find all adapters which has specific gateway
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
if objItem.ServiceName <> "VMnetAdapter" and objItem.ServiceName <> "VBoxNetAdp" and objItem.ServiceName <> "" and isNull(objItem.MACAddress) = 0 Then
For Each strIP in objItem.DefaultIPGateway
If strIP = "192.168.1.1" Then
Wscript.Echo objItem.ServiceName & vbCrLf & objItem.MACAddress
End If
Next
End if
Next
https://msdn.microsoft.com/en-us/library/aa394217(v=vs.85).aspx
Try this,you will get MAC Address of LAN Adapter Only,
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_NetworkAdapter WHERE (NetConnectionID like '%Local Area Connection%')"
For Each adapter In wmi.ExecQuery(qry)
If Not IsNull(adapter.MACAddress) Then Wscript.Echo adapter.MACAddress
Next
I am using this code only and its working fine.

Microsoft Server 2012 R2 WMI (virtualization/v2) not detecting virtual machines - VBScript

As the title indicates, I'm currently unable to retrieve a list of virtual machines with a WMI query in VBScript. Hyper-V manager is correctly identifying 3 Virtual Machines on the Host in question, but when I query WMI I only see the Host itself.
Here's a sample VBScript (courtesy of WMI Code Creator):
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\virtualization\v2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Msvm_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Msvm_ComputerSystem instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "ElementName: " & objItem.ElementName
Next
Output:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
-----------------------------------
Msvm_ComputerSystem instance
-----------------------------------
Description: Microsoft Hosting Computer System
ElementName: TEST-VH
Ideas, suggestions, or rocks to look under would be greatly appreciated, thanks!
You can take it one level higher and grab the computer names directly then compare the model and extract accordingly. I do not have any VM's installed to try this. But give it a shot and let me know if it works.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
strModel = objItem.Model
If instr(strModel, "Virtual Machine") Then
Wscript.Echo "-----------------------------------"
Wscript.Echo "Msvm_ComputerSystem instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "HostName: " & objItem.Name
End if
Next

What is the meaning of following line in VBScript

What is use of line:
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
in vbscript code.
This will create a WMI object that provides you with the objects, methods and properties needed to be able to communicate with the different parts of the OS.
So, using your snippet, you could for example query the status of every service:
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
For Each objService in colRunningServices
MsgBox objService.Name & " - " & objService.State
Next
You aren't limited to services, you can access registry settings, active process, etc. I use it often at work to help manage our Windows environment.
A few resources:
http://msdn.microsoft.com/en-us/library/aa394585(v=vs.85).aspx
http://technet.microsoft.com/en-us/library/ee176998.aspx

Using WMI objects in VB script to decide which programs to run

I have a vbscript that will find the OS, Service pack and OS Architecture but when i try to use the object in a If then statement its not defined, I tried to declare it but that didn't work. What i am trying to complete is create a script that will define the OS, Service pack and whether the system is x86 or x64 and the execute a program that will install the updates specific for that system but I'm stuck.
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo "Version: " & objOperatingSystem.Version
Wscript.Echo "Service Pack: " & objOperatingSystem.CSDVersion
Wscript.Echo "CPU Bit: " & objOperatingSystem.OSArchitecture
Next
I am assuming you are not storing those variables you are echoing with "wscript.echo"..
You could use this example (or make a case statement):
Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
osVersion = objOperatingSystem.Version
osCSDVersion = objOperatingSystem.CSDVersion
osArchitecture = objOperatingSystem.OSArchitecture
Next
Wscript.Echo "Version: " & osVersion
Wscript.Echo "Service Pack: " & osCSDVersion
Wscript.Echo "CPU Bit: " & osArchitecture
If InStr(LCase(osArchitecture), "64-bit") Then
wscript.echo "64-bit"
' .... Do stuff here ....
Else
wscript.echo "not 64-bit"
' .... Do stuff here ....
End If

vbscript WMI Using Public Member Functions (nVidia NV2)

I am trying to use some nVidia functions in there WMI API (attached, it is a txt file but should be renamed to chm for help file)
I am new to vbscript so can be doing something wrong.
My code is as follows:
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV")
Set colItems = objWMIService.ExecQuery("SELECT * FROM SyncTopology", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
NodeID = objItem.id
WScript.Echo "id: " & NodeID
WScript.Echo
Next
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2\NV")
Set SyncClass = objWMIService.Get("Sync")
if (SyncClass.toggleSource()) Then
wscript.echo "done!"
End if
Next
I am actually trying to use a different function but this one is the easiest and takes no arguments.
The class is 'Sync' the function is toggleSource, should be too easy!
I get an error on line:
if (SyncClass.toggleSource()) Then
stating:
C:\Users\User\Desktop\test3.vbs(28, 2) SWbemObjectEx: Invalid method Parameter(s)
I can query attributes in the class just can run methods :(
I can use these methods in Powershell so they should work, just can't get it working in vbscript!! AHHH...

Resources