I really didn't know what to set the title as. Sorry for being too vague. I have a couple questions specific to my VB Script.
First off, I have a piece that determines how much RAM is installed in my PC. I would like it to output as one amount. Currently, it outputs each slot in my computer. For example...
Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333
Capacity:, 1024, Speed:, 1333
I want it to output as one line, combined (in my case, 4 GB). Here is my code:
'Finds the computer's RAM capacity and speed.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
For Each objItem in colItems
convertedResult = objItem.Capacity/1048576
MyFile.WriteLine ("Capacity:, " & convertedResult & ", Speed:, " & objItem.Speed)
Next
My next issue is I want to find out what network adapters are in my PC, and their MAC address. I simply want to find the physical LAN adapters and WLAN adapters. I do not want any virtual adapters.
'Finds the computer's network adapters' name and MAC address (this includes virtual adapters).
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")
For Each objItem in colItems
MyFile.WriteLine ("Name:, " & objItem.Name & ", MAC Address:, " & objItem.MACAddress)
Next
For the memory, try this:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory")
dim total
For Each objItem in colItems
convertedResult = objItem.Capacity/1048576
total = total + convertedResult
Next
MyFile.WriteLine ("Capacity:, " & total )
Related
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.
here is a vbscript which shows all drives' volume serial numbers. But I need to customize to return only the volume serial number of the drive which the script is running from.
How to do it?
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
str = ""
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk")
For Each objItem In colItems
str = str & objItem.Name & " SerialNumber: " & objItem.VolumeSerialNumber & vbCrlf & vbCrlf
Next
MsgBox str
This should do what you need:
' Get the drive designator...
With CreateObject("Scripting.FileSystemObject")
strDrive = .GetDriveName(WScript.ScriptFullName)
End With
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk WHERE DeviceId='" & strDrive & "'")
' There should only be one item in the collection...
For Each objItem In colItems
MsgBox objItem.Name & " SerialNumber: " & objItem.VolumeSerialNumber
Next
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
Hello I´m writing this script where i need Serial number, IP address, login user, produkt key from office, autoroute to a text file. I have begun to write a script but having some issues. Not a done script but im kinda stuck to here.
Here´s the script:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("localhost")
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService1.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService2.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set objWMIService = GetObject( "winmgmts:\\" & strCoputer & ".\root\CIMV2" )
Set colItems = objWMIService.ExecQuery( "SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)
next
For Each objItem In colItems2
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile ("c:\" & objItem.UserName & ".txt", True)
tf.Write "Username: " & objItem.UserName
tf.WriteBlankLines(1)
tf.Write "Hostname: " & objItem.Name
tf.WriteBlankLines(1)
tf.Write "Domain: " & objItem.Domain
tf.WriteBlankLines(2)
next
For Each objItem In colItems1
tf.Write "Serial: " & objItem.IdentifyingNumber
tf.WriteBlankLines(1)
tf.Write "Model: " & objItem.Name
tf.WriteBlankLines(2)
tf.Write "Vendor: " & objItem.Vendor
tf.WriteBlankLines(1)
tf.Write "Version: " & objItem.Version
tf.WriteBlankLines(2)
Next
For Each objItem In colItems3
tf.Write "IP Address: " & objItem.IPAddress
tf.WriteBlankLines(1)
tf.Close
next
Microsoft has created a free tool called Scriptomatic which automatically creates vbscript code for such kind of task. You can download scriptomatic from the below location.
http://www.microsoft.com/en-in/download/details.aspx?id=12028
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