Sign in to follow this  
Followers 0
continyu

Get monitor info while computer is open

11 posts in this topic

Hi,

I'm creating a new script to determine if computers are staying with same monitors.

I've founded a script which gets information about monitors serial number and name from registry with edid.

BUT

it only works when i restart my pc after changing monitors. (because registry doesn't get refreshed when computer is open.)

So

I need to get active monitor's serial number. without restarting comp.

i was thinking to get all devices name from device manager. but i don't know how to do that. also i don't know how to get monitors serial number from device manager.

sorry if i couldn't explained it clearly. please ask any questions about my problems.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

continyu,

A brief search on Google ("wmi" & "monitor") gives all the info you need..

Good Luck,

kylomas

Edit: a forum search also turns up many examples...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Sadly i couldn't find any autoit examples with wmi.

also at forums i've only found examples with registry not wmi...

Share this post


Link to post
Share on other sites

continyu,

When I search on "wmi" and "monitor" I get 109 hits, the second of which looks like exactly what you want...

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

if you can give me some of the links i can tell you if they are the one i'm looking for or not.

but the results from "wmi" "montior" query didn't gave me what i'm looking for.

also if there is a way for getting all active device names / serial numbers to a txt file it would be good to.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You could try calling EnvUpdate ( ) a few times maybe with some Sleep() in between before checking the registry value.

Might be a quick and dirty fix.

Edited by MilesAhead

Share this post


Link to post
Share on other sites

You could try calling EnvUpdate ( ) a few times maybe with some Sleep() in between before checking the registry value.

Might be a quick and dirty fix.

Thank you for your answer. i will try it when i get a chance.

i'm still trying to get all device names and/or serial numbers without opening and reading it from device manager. which is a bad solution.

Share this post


Link to post
Share on other sites

VB isn't my strength either. But I can tell you &H denotes hex numbers like 0x does in AutoIt and c/c++

I would run it and see if it works before spending a lot of time. I think it's from 2006 so it may not work in Vista/W7. I don't know.

Share this post


Link to post
Share on other sites

I also struggled with using the registry to get the monitor information because as you point out this isn't updated when a new monitor is added/removed only on first PC boot.

Came across a way using WMI that works and I don't believe has been posted in the forum.

ConsoleWrite(_MonitorInfo())

Func _MonitorInfo()
Local $WMIWmiMonitorID
Local $sManufacturerName, $sSerialNumberID, $YearOfManufacture, $WeekOfManufacture, $sUserFriendlyName
Local $i
Local $sMonitorInfo
Local $strcomputer = "."
Local $objWMIServiceWMI = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $strcomputer & "\root\WMI")
If IsObj($objWMIServiceWMI) = 1 Then
  $WMIWmiMonitorID = $objWMIServiceWMI.ExecQuery("SELECT * FROM WmiMonitorID WHERE Active='True'")
  For $objComputer In $WMIWmiMonitorID
   $WeekOfManufacture = $objComputer.WeekOfManufacture
   $YearOfManufacture = $objComputer.YearOfManufacture
   For $i = 0 To UBound($objComputer.UserFriendlyName) - 1
    $sUserFriendlyName = $objComputer.UserFriendlyName($i)
    If StringLen($sUserFriendlyName) <> 0 Then
     $sMonitorInfo = $sMonitorInfo & String(Chr($sUserFriendlyName))
    EndIf
   Next
   $sMonitorInfo = $sMonitorInfo & " Manufacturer: "
   For $i = 0 To UBound($objComputer.ManufacturerName) - 1
    $sManufacturerName = $objComputer.ManufacturerName($i)
    If StringLen($sManufacturerName) <> 0 Then
     ;Returns a character corresponding to an ASCII code.
     $sMonitorInfo = $sMonitorInfo & String(Chr($sManufacturerName))
    EndIf
   Next
   $sMonitorInfo = $sMonitorInfo & " ProductCode: "
   For $i = 0 To UBound($objComputer.ProductCodeID) - 1
    $sProductCodeID = $objComputer.ProductCodeID($i)
    If StringLen($sProductCodeID) <> 0 Then
     $sMonitorInfo = $sMonitorInfo & String(Chr($sProductCodeID))
    EndIf
   Next
   $sMonitorInfo = $sMonitorInfo & " Serial: "
   For $i = 0 To UBound($objComputer.SerialNumberID) - 1
    $sSerialNumberID = $objComputer.SerialNumberID($i)
    If StringLen($sSerialNumberID) <> 0 Then
     $sMonitorInfo = $sMonitorInfo & String(Chr($sSerialNumberID))
    EndIf
   Next
   $sMonitorInfo = $sMonitorInfo & " Built: " & $WeekOfManufacture & "/" & $YearOfManufacture
   $sMonitorInfo = $sMonitorInfo & @CRLF
  Next
Else
  $sMonitorInfo = "Error: Not an Object" & @CRLF
EndIf
Return $sMonitorInfo
EndFunc   ;==>_MonitorInfo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0