- Get screen resolution from command prompt
- Get Screen resolution using WMI/powershell in Windows 7
- 6 Answers 6
- Result
- PowerShell Code to format the results of: [System.Windows.Forms.Screen]::AllScreens
- Output for the secondary monitor in landscape mode. 1920 x 1200
- Output for the secondary monitor in portrait mode. 1200 x 1920
- Windows get screen resolution
- Answered by:
- Question
- Answers
- All replies
Get screen resolution from command prompt
We can find out desktop resolution of a computer from command prompt using wmic command. The below command prints desktop resolution for all the available monitors on the system.
wmic desktopmonitor get screenheight, screenwidth
The above output shows that there are two monitors connected to the computer, each having the resolution 900×1440.
The below is the output on another system connected to two displays having different resolutions.
Thanks for this! 🙂
i can’t use this command in Condition
I mean than :
If resolution do …
elso do …
it’s possible ?
You should be able to do this in a batch script by capturing the output of the wmic command in a variable and then check for it’s value.
How to change screen resolution with cmd without using third party tools
Nothing as such I am aware of.
Is there any command to duplicate the same display to the second monitor? or do vice-versa i.e Remove duplication and extend second display on the other monitor
Can you please let me know how to change resolution using cmd?
If the commands posted above does not work on Windows 10 machines, try the following
wmic path Win32_VideoController get CurrentHorizontalResolution,CurrentVerticalResolution
thanks, this one worked for me
I need to set my display resolution to 1024 x 768 . How do I do this in a straightforward manner?
Hey. I recently got a computer (Dell Inspiron with 15.6″ HD display) and I have it hooked up to a small tv, (Emerson 32″ -I think.) But I’m not able to find a command prompt to fit the resolution. I’m trying to learn this, but it’s not very easy to find books on coding and such.
Get Screen resolution using WMI/powershell in Windows 7
I am using the following script to get screen resolution in Windows using WMI. The script works fine when the computer is in landscape mode but returns incorrect values when in portrait mode. Works properly in XP and did not try in Vista. Can anyone confirm this is bug in Windows 7 WMI.
6 Answers 6
For the record, the PowerShell code is:
I get the same values in Landscape or in Portrait mode.
UPDATE:
In a multi monitor environment you can get the info for all monitors with:
You can grab this from the Win32_VideoController WMI class. The VideoModeDescription property includes the screen resolution and the color depth.
Result
Same as the other answers, however for the plain cmd:
wmic path Win32_VideoController get VideoModeDescription
@Shay Levy’s answer above accurately reports the Width/Height that was active when the powershell session was launched. If you rotate monitor after PS launch, it continues to report the original, now incorrect values.
The SystemInformation class provides another way to get orientation, and it changes in the current PS session even if the display is rotated after the session launch.
Rotate monitor, then.
Here’s an answer based on Shays only it formats the results for each screen as per the OPs’ example.
PowerShell Code to format the results of: [System.Windows.Forms.Screen]::AllScreens
Output for the secondary monitor in landscape mode. 1920 x 1200
Output for the secondary monitor in portrait mode. 1200 x 1920
You can get all available resolution with this command:
Windows get screen resolution
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
Hi powershell guy,
Question :
How to get the value like this :
$Display1 = Get-****
$Display2 = Get-****
In order to have only the resolution for example :
Write-Host $Display1
1280×800
Write-Host $Display2
1920×1200
The goal is to write the resolution in the registry and i am asking first how to get the values located in Bounds line.
Answers
This should accomplish what you want, or at least set you on the right track
If I were to write a scri0pt then I would make it useful like this:
All replies
This should accomplish what you want, or at least set you on the right track
PS C:\scripts> [System.Windows.Forms.Screen]::AllScreens.bounds.height
768
PS C:\scripts> [System.Windows.Forms.Screen]::AllScreens.bounds.width
136
PS C:\scripts> [System.Windows.Forms.Screen]::AllScreens.DeviceName.Split(‘\’)[-1]
DISPLAY16
the problem with that solution, is the OP has no way of pulling the information per monitor. Your solution gives the name of the monitor, and the dimensions, for all monitors, all at once.
with the solution i provided, it’s seperated. The OP can add in the registry writes in the foreach loop, and record the specs, per monitor.
If I were to write a scri0pt then I would make it useful like this:
This is also useful:
Get-WmiObject Win32_DisplayConfiguration | select DeviceName,BitsPerPel,PelsHeight,PelsWidth
Oops. ALomost for got:
Get-WMiObject Win32_DesktopMonitor -ComputerName testpc-Credential $cred | select Name,ScreenWidth,ScreenHeight
Well, we’re of two schools when it comes to instructing.
My way of teaching is to give a fully functioning example, in the simplest way possible and let the OP pick it apart, study it, and learn from it. This is my preferred way of learning.
Your way of instructing, for me, would only serve to frustrate me, as I’m sure it would others. I can’t tell you how many times i asked a question from my teachers/professors, only to be given a hint or two so that I may take that and find the answer. OH my god! Really!? I just stopped asking questions after a while.
I myself, learn best/quickest, by studying an existing, working script and googling the parts i don’t understand.
Both methods are valid, and can be debated successfully either way.
I feel my way is better, as it eliminates the possibility of confusing the OP, or at least, minimizes it as much as it can be.
You would never make it through a colelg3e level advanced course in math or physics. Why do you insist that being spoon fed is the best way. It is the slowest way for anyone to learn. Learning how to think is more important than a catalog of answers. It empowers the user. Our schools seem to no longer teach. They just drill students into passing test. Industry is saying that they cannot find good people because the college grads cannot think.
Not just an opinion. It is what most educators are trying to ,point out to our governments and legislators. It is also what most major corporations point at when asked why they cannot get trained and competent technical ,people. Jobs go to H1B visa holders because many are better educated then Americans.
Rote learning has never been considered useful as an educational tool. It is just a way to get people to pass tests.
Information is not knowledge. Facts are no understanding. Memorizing is not thinking.
Note to TixTix: The following post is not directed at you personally, please do not read this with any malice directed towards you individually.
Your opinion, and your entitled to it. I don’t agree.
There is wisdom to both sides of this argument.
However, the biggest thing to note here is that 90% of people who come to these forums aren’t really looking to learn. They really only want a handout, plain and simple.
Sometimes I’m bored and I give them one. Sometimes I decide that I want to use their question as a reason to learn something myself. Most times I either ignore them or just give them a link to the syntax.
Just something to think about before dedicating time to writing up a big example that you think will help someone learn. 9 out of 10 times they’ll just come back and ask you to make some change for them instead of actually processing what you’ve shown them.
I did the same thing when I started here, writing up big examples with lots of comments and links to blogs in an effort to help the OP learn something. Eventually I ended up jaded because I felt taken advantage of one too many times by unappreciative OPs. We’ll see what time tells.
At the end of the day though, this is all off topic and IMHO we should at least wait to continue this discussion until TixTix gets the answer he/she needs and closes this thread out with an answer. After that, fair game.
I would also note that «Write-Host» produces no usable output, If we just want the information at the moment then Write-Host is good enough. If we need this at another point later in the script then the methods I posted are more useful.
We cannot know in this instance what is needed. All of the information may prove useful to others however, I still prefer to challenge a user to consider how the objects and commands actually work. It will improve all who accept the challenge and it will improve all of our technical abilities.
I used write-host so that the OP can copy paste the script into his powershell window, and immediately see the output he desires. This will/should, also show him the variables that holds the data he’s looking for.
Removing the write-host command and inserting the code he needs to write the data to the registry should be a simple matter.
I used write-host so that the OP can copy paste the script into his powershell window, and immediately see the output he desires. This will/should, also show him the variables that holds the data he’s looking for.
Removing the write-host command and inserting the code he needs to write the data to the registry should be a simple matter.
@jrv and Xecros,
Thanks you both ! It helps a lot !
Yes the write host is cool to see direcly the result, my goal is to create some key in the registry, be quiet i know how to do that .. whew 🙂
Before created this post, i googled about 2 hours without any success, then try to find the solution with get-help but no way. Sometimes, it could be long to find the good way when you dont know the syntax by heart 🙁
My opinion its better to learn with example, however, if some guys post a lot of questions once they have a problem it is just like some slackness.
To learn without example the beginner like me should have a plan with «how to use the Get-Help» no ?
I’m happy we could help!
I’m like you. I don’t like to ask questions. I like to figure out problems on my own. But none of us, knows everything. None of us, can figure out every problem on our own.
Rest assured, If I ever ask a question, it’s only after I spent considerable time trying to figure it out on my own. I guess that’s why i got pissed at my instructors/teachers/professors. For them to just give me a vague hint on how to solve my problem, when I already spent considerable time trying to solve it. It’s insulting! It really is.
@jrv and Xecros,
Thanks you both ! It helps a lot !
Yes the write host is cool to see direcly the result, my goal is to create some key in the registry, be quiet i know how to do that .. whew 🙂
Before created this post, i googled about 2 hours without any success, then try to find the solution with get-help but no way. Sometimes, it could be long to find the good way when you dont know the syntax by heart 🙁
My opinion its better to learn with example, however, if some guys post a lot of questions once they have a problem it is just like some slackness.
To learn without example the beginner like me should have a plan with «how to use the Get-Help» no ?
0Yes but you both still have missed the answer that would have helped you to understand how PowerShell works. The issue is «Why doesn’t help help?»
You need to find the set of questions that are missing and search for those answers. That takes a bit of learning and thinking. Learning and thinking would get you to a place where you can answer your own questions and where you will understand how to ask better questions.
All is not lost. You can now see that your searching didn’t work so the bigger question is why?
First you didn’t inspect the object full.
[System.Windows.Forms.Screen]::AllScreens|gm
[System.Windows.Forms.Screen]::AllScreens.Bounds
This technique will allow you to understand how objects are built.
The how is not about what text can you display it is about how the underlying object system works and how to use if. «GM» is an alias for Get-Member which inspects objects.
Objects can be discovered:
Which is fundamental knowledge for ,using PowerShell.
Of course as Mike has noted most people coming here do not want to learn they just want someone to do it for them.