Jump to content

Get monitor info while computer is open


continyu
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

  • 1 month later...

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...