Jump to content

Detect display - LCD or CRT


Idontwantspam

Recommended Posts

I'm wondering if there is any way for a batch file or vbs script to detect whether the currently used display is an LCD or a CRT. The reason is that I'd like my unattended script to detect whether it is an LCD or not, and if it is, add the registry entries for cleartype, and if it isn't, then not do so, since I don't want to add cleartype on non-LCD monitors. If this isn't possible, then is there a way to determine the resolution? All of our LCD's are 1280x1024 or widescreen, and none of our CRT's are widescreen and very few are 1280x1024, so if there were a way to detect what the aspect ratio is I could do it that way, too. Any ideas, anyone?

Link to comment
Share on other sites


There's a Win32_DesktopMonitor WMI class that has a DisplayType property, which you'd hope would work, but there's no values for LCDs. And it returns a null value with this LCD... And I don't think testing for a null type is a reliable detection method either :(

You could peek at the monitor EDID (DDC) infos, but there's nothing about the monitor being LCD or CRT in there (besides perhaps the lack of more than 1 resolutions supported? Didn't investigate much, not like I'm gonna write a parser for that). I also peeked in the monitor's properties in device manager, and in the registry, and I didn't notice any information giving away if it's a LCD or CRT unfortunately.

So we're stuck checking resolutions I guess. That leaves us with the Win32_VideoController WMI class pretty much (Win32_DisplayConfiguration is deemed obsolete)

If all your LCD monitors are widescreen, then this script will work:

strComputer = "."
Set objShell = WScript.CreateObject ("WSCript.shell")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_VideoController")
For each objItem in colItems
intHorRes = objItem.CurrentHorizontalResolution
intVerRes = objItem.CurrentVerticalResolution
Next
If intHorRes / intVerRes > 1.34 Then
objShell.run "regedit /s cleartype.reg"
End If

if you wanna check for 1280x1024 specifically, change the if to:

If intHorRes=1280 And intVerRes=1024 Then

JScript version (with minimal error handling):

try {
strComputer = ".";
objWScript = new ActiveXObject("WScript.Shell" );
SWBemlocator = new ActiveXObject("WbemScripting.SWbemLocator");
objWMIService = SWBemlocator.ConnectServer(strComputer,"root/CIMV2");
colItems = objWMIService.ExecQuery("Select * from Win32_VideoController");
propEnum = new Enumerator(colItems);
for (;!propEnum.atEnd();propEnum.moveNext()) {
objItem = propEnum.item();
intHorRes = objItem.CurrentHorizontalResolution;
intVerRes = objItem.CurrentVerticalResolution;
}
if (intHorRes / intVerRes > 1.34) {
objWScript.Run('regedit /s cleartype.reg');
}
}
catch(e) {
WScript.Echo("exception " + e.number + ": " + e.description);
}

PowerShell version:

$strComputer = "."
$colItems = Get-WmiObject -Class "Win32_VideoController" -Namespace "root\CIMV2" -ComputerName $strComputer
foreach ($objItem in $colItems) {
$intHorRes = $objItem.CurrentHorizontalResolution
$intVerRes = $objItem.CurrentVerticalResolution
}
if (($intHorRes / $intVerRes) -gt 1.34){
$objStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$objStartInfo.FileName = "regedit.exe"
$objStartInfo.windowStyle ="Normal"
$objStartInfo.arguments = "/s cleartype.reg"
[System.Diagnostics.Process]::Start($objStartInfo)
}

anything else really, just ask.

Edited by crahak
Link to comment
Share on other sites

So then if I want to test for widescreen *or* 1280x1024, I can do this?

strComputer = "."
Set objShell = WScript.CreateObject ("WSCript.shell")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_VideoController")
For each objItem in colItems
intHorRes = objItem.CurrentHorizontalResolution
intVerRes = objItem.CurrentVerticalResolution
Next
If intHorRes / intVerRes > 1.34 Then
objShell.run "regedit /s cleartype.reg"
End If
If intHorRes=1280 And intVerRes=1024 Then
objShell.run "regedit /s cleartype.reg"
End If

I'll try that out - thanks for the help. :) For something such as this, it's not a big enough deal that if one or two don't get cleartyped or a CRT gets cleartype by accident that it would be the end of the world, so this ought to work just fine.

Edited by Idontwantspam
Link to comment
Share on other sites

Hmm, 1280x800 will already get cleartype enabled (16:10 AR i.e. 1.6, bigger than 1.34).

The line you added tests for 1280x1024. If you want to enable cleartype of those too, then sure, those changes you made will work.

Or you could do:

If (intHorRes / intVerRes > 1.34) Or (intHorRes=1280 And intVerRes=1024) Then
objShell.run "regedit /s cleartype.reg"
End If

And for those who are into them hardcore batch files still, I can manage to retrieve the resolution parsing WMIC's output:

FOR /F "skip=2 tokens=2-3 delims=," %%A IN ('"WMIC Path Win32_VideoController Get CurrentHorizontalResolution, CurrentVerticalResolution /Format:csv"') DO (
set
echo Resolution is: %%Ax%%B
)

But when it comes to doing math with them... I don't think that's possible (set can do math, but no floating point divisions). Unless you add some kind of command line calculator, then pass on those numbers to it, thru another FOR /F statement to parse its output, then perhaps pass on that result to a number comparison app, thru another FOR /F of course, to get the output from it, to see if it's widescreen or not :lol: (I personally don't really use batch files for anything anymore)

Edited by crahak
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
  • Recently Browsing   0 members

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