[AU3]通过edid查看显示器物理大小等信息

通过edid查看显示器大小等信息(有些可能不准确)

[AU3]通过edid查看显示器物理大小等信息_第1张图片

#NoTrayIcon
#include <string.au3>
$g_szVersion = "qq153785587"
If WinExists($g_szVersion) Then
Exit
EndIf
AutoItWinSetTitle($g_szVersion)
Global $edidvalue , $dissnid , $width ,$height ,$dissize,$createweek ,$createyear ,$proid ,$proname ,$disothersn;, $midtemp ,$midtemp1
Global $ti,$ti1 ,$p1,$p2,$p3,$alltxt
$edidvalue = _currdisplayEDID()
If $edidvalue="" Then
MsgBox(0,"错误","读取注册表出错!")
Exit
EndIf


;显示器ID = 制造商 + 产品代码
$proname=StringMid ( $edidvalue, 19 ,4 ) ;制造商名称
;MsgBox(0,"",StringLen(_N2B(_hextodec($proname))))
$proname=_N2B(_hextodec($proname))
;$proname = "111010111010110"
$ti = StringLen($proname)
If $ti<15 Then
$ti1 = 5 - (15 - $ti)
Else
$ti1 = 5
EndIf
$p1 = StringMid($proname,1,$ti1) ;第一个字符
$p2 = StringMid($proname,$ti1+1,5) ;第二个字符
$p3 = StringMid($proname,$ti1+1+5,5) ;第三个字符
;$proname = _bintochr(StringMid($pronametemp,1,$ti1)) & _bintochr(StringMid($pronametemp,$ti1+1,5)) & _bintochr(StringMid($pronametemp,$ti1+1+5,5) )
;MsgBox(0,"",$proname)
Switch $ti1
Case 4
$p1 = "0" & $p1
Case 3
$p1 = "00" & $p1
Case 2
$p1 = "000" & $p1
Case 1
$p1 = "0000" & $p1
EndSwitch
$proname = _bintochr($p1) & _bintochr($p2) & _bintochr($p3) ;显示完整的标识 比如 AOC
;MsgBox(0,"",$proname)
$proid= StringMid ( $edidvalue, 25 ,2 ) &StringMid ( $edidvalue, 23 ,2 ) ;产品代码 高低互换
;MsgBox(0,"",$proid)

$createweek=_hextodecfortwo( StringMid ( $edidvalue, 35 ,2 ) );制造周
$createyear=_hextodecfortwo(StringMid ( $edidvalue, 37 ,2 )) + 1990 ;制造年
;MsgBox(0,"",$createyear)

$width = _hextodecfortwo(StringMid ( $edidvalue, 45 ,2 ) ); 宽 单位cm
$height = _hextodecfortwo(StringMid ( $edidvalue, 47 ,2 )); 高
;显示器中间的斜线 = 两直角边平方和再开方(即平方根) 再除以2.54表示寸 1英寸=2.54cm
$dissize = StringMid(Sqrt($width*$width + $height*$height) / 2.54,1,4) & "" ;尺寸
;MsgBox(0,"",$dissize)
$dissnid = _convertChrToString(227,$edidvalue) ;直接可以在227处读取序列号
$disothersn = _convertChrToString(191,$edidvalue) ;直接可以在191处读取序列号 机种名称信息 型号
;MsgBox(0,"",$disothersn)
;$midtemp=StringMid ( $edidvalue, 219 ,8 ) ;2
;$midtemp1=StringMid ( $midtemp, 7 ,2 )
;If $midtemp1="ff" Then
;$midtemp2=StringMid ( $edidvalue, 227 ,28 )
;MsgBox(0,"",_convertChrToString(227,$edidvalue))
;EndIf
$alltxt = "显示器ID:" & $proname & $proid & @CRLF & "型号:"& $disothersn & @CRLF & "" & $createweek & "周 / " & $createyear & @CRLF & "序列号:" & $dissnid & @CRLF & $width &" cm × " & $height & " cm (" & $dissize & ")"
MsgBox(0,"查看显示器参数",$alltxt) ;& @CRLF &


Func _currdisplayEDID() ;取得edid值
Local $objWMIService,$Items ,$Info , $reg ,$redid
$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
$Items = $objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor")
For $Info In $Items
$reg = $Info.PNPDeviceID
Next
$redid = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\" & $reg &"\Device Parameters", "edid")
Return $redid
EndFunc



;把多个字符 连在一起组成字符串
Func _convertChrToString($inputint,$tedid)
Local $txt ,$i,$j,$tmp
$txt=""
$j=$inputint
For $i=1 To 14
$tmp=StringMid ( $tedid, $j ,2)
$txt = $txt & String(Chr(_hextodecfortwo($tmp)))
$j = $j +2
Next
Return $txt
EndFunc

;把字符串形的16进制[四位的十六进制]转为10进制
Func _hextodec($instring)
Local $strtemp
$strtemp = StringUpper($instring)
Return _hextemp(StringMid($strtemp,1,1))*16*16*16 + _hextemp(StringMid($strtemp,2,1))*16*16 + _hextemp(StringMid($strtemp,3,1))*16 + _hextemp(StringMid($strtemp,4,1))
EndFunc
Func _hextemp($ichr)
Local $uperstr
$uperstr = asc(StringUpper($ichr))
If $uperstr< 58 Then
$uperstr = $uperstr -48
Else
$uperstr =$uperstr - 55
EndIf
Return $uperstr
EndFunc
;原理BitAND 用来按位""运算,之后将这些得到的 0 1 等相连
;BitShift 用来按位""运算,这里它的作用是用作右移一位则相当于除以2结果没带小数点
;十进制转二进制 ,直接网上代码 转sky123
Func _N2B($iN)
Local $sB = ""
Local $iN2 = $iN
While $iN
$sB = BitAND($iN , 1) & $sB
$iN = BitShift($iN, 1)
WEnd
Return $sB
EndFunc ;==>_N2B
;直接查表返回
Func _bintochr($inbin)
Local $i
Local $table[26] = ["00001","00010","00011","00100","00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001","10010","10011","10100","10101","10110","10111","11000","11001","11010"]
Local $tablechr[26] = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
For $i = 0 To 25
If $table[$i] = $inbin Then
ExitLoop
;MsgBox(0,"",$i)
EndIf
Next
Return $tablechr[$i]
EndFunc










;把 字符串的十六进制转为对应的ascii码 比如 "41"表示A 转为 65
Func _hextodecfortwo($strhex)
Local $rvar,$temp,$one,$two
;Local $hextodec[6] = ["A","B","C","D","E","F"]
$temp = StringUpper($strhex)
If StringLen($temp)<>2 Then
$rvar = 0
Return $rvar
EndIf
$one = Asc(StringMid($temp,1,1))
$two = Asc(StringMid($temp,2,1))

If $one< 58 Then
$one = $one -48
Else
$one =$one - 55
EndIf
If $two< 58 Then
$two = $two -48
Else
$two =$two - 55
EndIf
;MsgBox(0,"",$two)
$rvar = $one*16 + $two
Return $rvar
EndFunc

 

转载于:https://www.cnblogs.com/onepc/archive/2011/11/10/2244362.html

你可能感兴趣的:([AU3]通过edid查看显示器物理大小等信息)