Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

WMI and Registry Query of Machine

Posted on 2011-05-12
10
Medium Priority
?
695 Views
Last Modified: 2012-05-11
We currently run a shutdown script that writes the computers service tag to the AD computer account description field. I am trying to expand this to also include the monitor service tag.

The monitor service tag can be found at HKLM\System\ControlSet001\Control\GraphicsDrivers\Connectivity\

The sub-key under connectivity is named after the serial number.

How can I have that serial number automatically record to an AD field for the respective computer? If possible, could the script below be modified so that on shutdown, the description is populated with the computer and monitor service tag.

Something like:

Computer: 1234567 Monitor:asldjaksdlk3jkasd
sn = GetSerialNumber 
UpdateDescription(sn) 
 
 
Function GetSerialNumber 
        strComputer = "." 
        Set objWMIService = GetObject("winmgmts:" _ 
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
        Set colBIOS = objWMIService.ExecQuery _ 
            ("Select * from Win32_BIOS") 
        For each objBIOS in colBIOS 
                GetSerialNumber = objBIOS.SerialNumber 
        Next 
End Function 
 
Sub UpdateDescription(strDescription) 
        Set objSysInfo = CreateObject("ADSystemInfo") 
         
        Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
        objComputer.Description = strDescription 
        objComputer.SetInfo 
End Sub

Open in new window

0
Comment
Question by:Joseph Moody
  • 4
  • 4
  • 2
10 Comments
 
LVL 14

Expert Comment

by:Dhiraj Mutha
ID: 35751819
Hope the below code helps you.

Just the change the "value name" there (Line 21).
sn = GetSerialNumber 
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")
UpdateDescription(sn) 
 
 
Function GetSerialNumber 
        strComputer = "." 
        Set objWMIService = GetObject("winmgmts:" _ 
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
        Set colBIOS = objWMIService.ExecQuery _ 
            ("Select * from Win32_BIOS") 
        For each objBIOS in colBIOS 
                GetSerialNumber = objBIOS.SerialNumber 
        Next 
End Function 
 
Sub UpdateDescription(strDescription) 
	strKeyPath = "HKLM\System\ControlSet001\Control\GraphicsDrivers\Connectivity\"
	strValueName = "Value Name"
	oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
	Set objSysInfo = CreateObject("ADSystemInfo") 
         Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
         objComputer.Description = "Computer: " & strDescription & " Monitor: " & strValue
         objComputer.SetInfo 
End Sub

Open in new window

0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35751904
Hi, run this and see if it gives you the monitor number on its own.  If it does, we'll plug it into the script.

Regards,

Rob.
Const HKEY_LOCAL_MACHINE = &H80000002
strKey = "SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Connectivity"
strComputer = "."
Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\default:StdRegProv")
If objRegistry.EnumKey(HKEY_LOCAL_MACHINE, strKey, arrKeyNames) = 0 Then
	If IsNull(arrKeyNames) = False Then
		For Each strKeyName In arrKeyNames
			MsgBox strKeyName
		Next
	End If
End If

Open in new window

0
 
LVL 22

Author Comment

by:Joseph Moody
ID: 35753513
Hey Rob,

That worked! It popped up a message for each monitor connected.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 22

Author Comment

by:Joseph Moody
ID: 35753517
pspglb: What should be at line 21? The key below Connectivity is different for every machine. I know this is probably a silly question.
0
 
LVL 14

Expert Comment

by:Dhiraj Mutha
ID: 35755437
Then I think Rob is the King.... Seriosuly he is a genius... I have just started my carrer in VBS on EE, thanks to Rob for that.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35758612
@pspglb, thanks ;-)

JMoody, you say it showed a message for *each* monitor.....what do you want in the description of the computer object?  The first, second, or both?

Regards,

Rob.
0
 
LVL 22

Author Comment

by:Joseph Moody
ID: 35768850
both if that is possible. Only a few computers have two monitors though
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 35774919
Sure, it's possible.  Give this a shot.

Regards,

Rob.
sn = GetSerialNumber
arrMonitors = GetMonitorSerials
strDescription = "Computer: " & sn
For intMon = LBound(arrMonitors) To UBound(arrMonitors)
	strDescription = strDescription & " Monitor " & intMon + 1 & ": " & arrMonitors(intMon)
Next
'MsgBox strDescription
UpdateDescription(strDescription)

 
Function GetSerialNumber 
        strComputer = "." 
        Set objWMIService = GetObject("winmgmts:" _ 
            & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
        Set colBIOS = objWMIService.ExecQuery _ 
            ("Select * from Win32_BIOS") 
        For each objBIOS In colBIOS 
                GetSerialNumber = objBIOS.SerialNumber 
        Next 
End Function 
 
Sub UpdateDescription(strDescription) 
        Set objSysInfo = CreateObject("ADSystemInfo")          
        Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) 
        objComputer.Description = strDescription 
        objComputer.SetInfo 
End Sub

Function GetMonitorSerials
	Const HKEY_LOCAL_MACHINE = &H80000002
	strKey = "SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Connectivity"
	strComputer = "."
	strMS = ""
	Set objRegistry = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\default:StdRegProv")
	If objRegistry.EnumKey(HKEY_LOCAL_MACHINE, strKey, arrKeyNames) = 0 Then
		If IsNull(arrKeyNames) = False Then
			For Each strKeyName In arrKeyNames
				If strMS = "" Then
					strMS = strKeyName
				Else
					strMS = strMS & ";" & strKeyName
				End If
			Next
		End If
	End If
	GetMonitorSerials = Split(strMS, ";")
End Function

Open in new window

0
 
LVL 22

Author Closing Comment

by:Joseph Moody
ID: 35804228
Worked perfectly!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35806345
Great! Thanks for the grade.

Rob.
0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question