Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get the highest possible resolution 2

Status
Not open for further replies.

jurexo

Programmer
Apr 18, 2007
11
0
0
DE
Hello,

i need a vb script which makes my display to the highest possible resolution after the installation of windows.

can somebody help me?thx
 
Although I cannot help in writing the script (without keystrokes anyway), I suggest you stick to a default 1024x768 with 32bit colours as there is really no way (that I know) of determining the monitor that is connected to the machine, then determining what the maximium resolution and refresh rate of that monitor is.

Be good if there is, I would also love to know if anyone else knows.

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Well, you can get some of the info that you need from WMI. As to how you could set it, I don't know. I recommend that you download Scriptomatic 2.0 from Microsoft and take a look around.

There are two classes that look useful here:

root\CIMv2\Win32_VideoSettings looks like it will get you all of the display modes that are available with the current monitor/adapter combination. At least it did on my system.

root\CIMv2\Win32_VideoController, and specifically the VideoModeDescription property will tell you what the display is currently set at.

So if you iterate through the output from Win32_VideoSettings to you should be able to parse the output to find out what the highest resolution/color depth/sync rate supported is.

You will have to set it in the registry, which is where it gets tricky-ish. The data that you want is stored (under Windows XP) in HKEY_CURRENT_CONFIG\SYSTEM\CurrentControlSet\Control\Video\DISPLAYGUID\0000\. Somehow you'll have to retrieve the DISPLAYGUID value. The keys in question are:

DefaultSettings.BitsPerPel
DefaultSettings.VRefresh
DefaultSettings.XResolution
DefaultSettings.YResolution

You might also be able to find a registry key by following the same path but under HKEY_LOCAL_MACHINE that lists available display modes, but those are likely to be adapter-specific and not take into account the monitor.
 
hi,
how do you iterate through win32_videosettings. i can use this in a similar app.
 
Sample code from Scriptomatic:

Code:
On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array(".")
For Each strComputer In arrComputers
   WScript.Echo
   WScript.Echo "=========================================="
   WScript.Echo "Computer: " & strComputer
   WScript.Echo "=========================================="

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoSettings", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo "Element: " & objItem.Element
      WScript.Echo "Setting: " & objItem.Setting
      WScript.Echo
   Next
Next
 
yes, so i can see what resolutions are possible with my video controller but what i need is a a scipt which makes automatically the client into the highest possible resolution.
 
i'm getting an error with this:
"end of statement expected"
("SELECT * FROM Win32_VideoSettings", "WQL", _ wbemFlagReturnImmediately + wbemFlagForwardOnly)
i'm not sure if the syntax of the select is ok or not.
 
Try this:
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_VideoSettings", "WQL", &H30)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If it's all on one line then you can take out the '_' after "WQL". If instruction spans multiple lines then you'll need an '_' at the end of the first line to indicate that the rest of the instruction is continued on the line below it.

The formatting looked good in my editor, but after I pasted it here I got some funny line breaks in the code box which may have caused you problems.
 
yes, so i can see what resolutions are possible with my video controller but what i need is a a scipt which makes automatically the client into the highest possible resolution.

What code do you have so far?

Not to be too pointed about it, but most people here will be more than happy to help out if you're having problems writing code, or need pointed in the right direction to get started. It's one of the ways that we learn and stay sharp (and some of us like helping people).

However, posting homework problems is prohibited (and I'm not saying that's what you're doing, I'm just stating a fact about Tek-Tips). Also, most of us get paid for things like this as our day job. Because of that, the odds of getting someone to custom write and post a script for you are fairly slim. Especially when the script in question isn't something that you can just bang out in 5 minutes. Being a programmer yourself, I'm sure you understand that.

 
this is my code which i have so far

it proofs: if it is a latitude notebook then make a resolution of 1280x800

it works, but i need a script which makes at all pcs the max. resolution automatically

Set objNetwork = WScript.CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20



Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)

For Each objItem In colItems

If (InStr(objItem.Model, "Latitude")) = 1 Then


Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run("C:\setdisplay_latitude.cmd")

End If

Next


And setdisplay_latitude.cmd looks so:

"C:\reschange.exe" -width=1280 -height=800

The file reschange.exe i have copy to C:\

 
i have a script which say me the highest possible resolution that my display can make but how i can modify the script and can say: make automatically the highest possible resoultion?

thx


Option Explicit
'On Error Resume Next

Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim colItems : Set colItems = objWMIService.ExecQuery("Select * From CIM_VideoControllerResolution")
Dim maxHR : maxHR = 0
Dim maxVR : maxVR = 0
Dim objItem

For Each objItem in colItems
If objItem.HorizontalResolution > maxHR Then maxHR = objItem.HorizontalResolution
If objItem.VerticalResolution > maxVR Then maxVR = objItem.VerticalResolution
Next

WScript.Echo maxHR
WScript.Echo maxVR
 
Looks familiar....

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Well taking what you have and what I posted in the other forum...maybe like this...untested..you need to take the time and understand what's going on.

Code:
option explicit
on error resume next
Dim strComputer, colItems1, colItems2, objItem1, objItem2, objWMIService, objWMIService1
Dim objShare, objInParam, objOutParams, height, width
Dim strKeyPath, arrSubKeys, subkey, strKeyPath1, arrSubKeys1, subkey1
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objWMIService1 = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\DEFAULT")
Dim colItems		:	Set colItems = objWMIService.ExecQuery("Select * From CIM_VideoControllerResolution")
Dim maxHR			: 	maxHR = 0
Dim maxVR			:	maxVR = 0
Dim objItem

For Each objItem in colItems
	If objItem.HorizontalResolution > maxHR Then maxHR = objItem.HorizontalResolution
	If objItem.VerticalResolution > maxVR Then maxVR = objItem.VerticalResolution
Next
height = maxVR
width = maxHR
Set objShare = objWMIService.Get("StdRegProv")
Set colItems1 = objWMIService1.ExecQuery( _
   "SELECT * FROM Win32_DesktopMonitor",,48)

For Each objItem1 in colItems1
   If Instr(objItem1.Name,"2407") Then
     strKeyPath = "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO"
     objShare.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
     For Each subkey In arrSubKeys
       strKeyPath1 = "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
       objShare.EnumKey HKEY_LOCAL_MACHINE, strKeyPath1, arrSubKeys1
 
       Set objInParam = objShare.Methods_("SetDWORDValue"). _
       inParameters.SpawnInstance_()
       objInParam.Properties_.Item("hDefKey") =  &H80000002
       objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
       objInParam.Properties_.Item("sValueName") =  "DefaultSettings.YResolution"
       objInParam.Properties_.Item("uValue") =  height
       Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
       objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
       objInParam.Properties_.Item("sValueName") =  "DefaultSettings.XResolution"
       objInParam.Properties_.Item("uValue") =  width
       Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
  
       For Each subkey1 In arrSubKeys1
         ' *** Setzen der DWORD Registrywerte für die DefaultAuflösung
         Set objInParam = objShare.Methods_("SetDWORDValue"). _
         inParameters.SpawnInstance_()
         objInParam.Properties_.Item("hDefKey") =  &H80000002
         objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000\" & subkey1
         objInParam.Properties_.Item("sValueName") =  "DefaultSettings.YResolution"
         objInParam.Properties_.Item("uValue") =  height
         Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
         objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000\" & subkey1
         objInParam.Properties_.Item("sValueName") =  "DefaultSettings.XResolution"
         objInParam.Properties_.Item("uValue") =  width
         Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
       Next
     Next
   End If
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
oops. change this line
Set colItems = objWMIService.ExecQuery("Select * From CIM_VideoControllerResolution")

to

Set colItems = objWMIService1.ExecQuery("Select * From CIM_VideoControllerResolution")

to match what you are currently using.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
dm4ever said:
My philosophy: K.I.S.S - Keep It Simple Stupid

That script was SIMPLE????????

<hats off>



Just my 2¢
-There once was a man from Peru
Who wanted to write a Haiku
but...

--Greg
 
thx but it doesnt work:(

it comes nothing
 
You may want to remove this line too:
If Instr(objItem1.Name,"2407") Then

gbaughma, I didn't come up with the whole script...my contribution was the following which is pretty simple.

Option Explicit
'On Error Resume Next

Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Dim colItems : Set colItems = objWMIService.ExecQuery("Select * From CIM_VideoControllerResolution")
Dim maxHR : maxHR = 0
Dim maxVR : maxVR = 0
Dim objItem

For Each objItem in colItems
If objItem.HorizontalResolution > maxHR Then maxHR = objItem.HorizontalResolution
If objItem.VerticalResolution > maxVR Then maxVR = objItem.VerticalResolution
Next

WScript.Echo maxHR
WScript.Echo maxVR

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I posted this in the other forum... jurexo said it worked after a reboot...just posting here.

Code:
Option Explicit
On Error Resume Next
Dim strComputer, colItems1, colItems2, objItem1, objItem2, objWMIService, objWMIService1
Dim objShare, objInParam, objOutParams, height, width
Dim strKeyPath, arrSubKeys, subkey, strKeyPath1, arrSubKeys1, subkey1
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objWMIService1 = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\DEFAULT")
Dim colItems : Set colItems = objWMIService1.ExecQuery("Select * From CIM_VideoControllerResolution")
Dim maxHR : maxHR = 0
Dim maxVR : maxVR = 0
Dim objItem
For Each objItem in colItems
 If objItem.HorizontalResolution > maxHR Then maxHR = objItem.HorizontalResolution
 If objItem.VerticalResolution > maxVR Then maxVR = objItem.VerticalResolution
Next
height = maxVR
width = maxHR
Set objShare = objWMIService.Get("StdRegProv")
Set colItems1 = objWMIService1.ExecQuery( _
"SELECT * FROM Win32_DesktopMonitor",,48)

For Each objItem1 in colItems1
  strKeyPath = "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO"
  objShare.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
  For Each subkey In arrSubKeys
    strKeyPath1 = "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
    objShare.EnumKey HKEY_LOCAL_MACHINE, strKeyPath1, arrSubKeys1

    Set objInParam = objShare.Methods_("SetDWORDValue"). _
    inParameters.SpawnInstance_()
    objInParam.Properties_.Item("hDefKey") =  &H80000002
    objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
    objInParam.Properties_.Item("sValueName") =  "DefaultSettings.YResolution"
    objInParam.Properties_.Item("uValue") =  height
    Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
    objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000"
    objInParam.Properties_.Item("sValueName") =  "DefaultSettings.XResolution"
    objInParam.Properties_.Item("uValue") =  width
    Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)

    For Each subkey1 In arrSubKeys1
      ' *** Setzen der DWORD Registrywerte für die DefaultAuflösung
      Set objInParam = objShare.Methods_("SetDWORDValue"). _
      inParameters.SpawnInstance_()
      objInParam.Properties_.Item("hDefKey") =  &H80000002
      objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000\" & subkey1
      objInParam.Properties_.Item("sValueName") =  "DefaultSettings.YResolution"
      objInParam.Properties_.Item("uValue") =  height
      Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
      objInParam.Properties_.Item("sSubKeyName") =  "SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Control\VIDEO\" & subkey & "\0000\" & subkey1
      objInParam.Properties_.Item("sValueName") =  "DefaultSettings.XResolution"
      objInParam.Properties_.Item("uValue") =  width
      Set objOutParams = objWMIService.ExecMethod("StdRegProv", "SetDWORDValue", objInParam)
    Next
  Next
Next

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
yes at my desktop it works but at my notebook it doesnt work:(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top