I try to read the current resolution, when the resoltuitoon is not 4k a flag is that to false, when it changes back to 4K a video process is killed and restarted.
but I get always the maximal resolution in the screen, on different windows machines.
#echo off
set resolution=false
:loop
Set "WMIC_Command=wmic path Win32_VideoController get VideoModeDescription^,CurrentHorizontalResolution^,CurrentVerticalResolution^ /format:Value"
Set "H=CurrentHorizontalResolution"
Set "V=CurrentVerticalResolution"
Call :GetResolution %H% HorizontalResolution
Call :GetResolution %V% VerticalResolution
echo(
echo Screen Resolution is : %HorizontalResolution% x %VerticalResolution% = %resolution%
timeout /t 2
if %HorizontalResolution% == 3840 (
if %resolution% == false (
echo "hoppla die Auflösung wurde geaendert"
TASKKILL /F /FI "WINDOWTITLE eq SHH_Wandprojektion*"
echo "Video task gekillt"
timeout /t 2
start "E:\_projekte\STADTHOEFE_HAMBURG\PROJEKTION_VIDEO\mpc-hc.exe" "E:\_projekte\STADTHOEFE_HAMBURG\PROJEKTION_VIDEO\SHH_Wandprojektion_200123b_1.mp4"
echo "und wieder geoeffnet"
set resolution=true
)
) else (
set resolution=false
)
timeout /t 3
goto loop
::****************************************************
:GetResolution
FOR /F "tokens=2 delims==" %%I IN (
'%WMIC_Command% ^| find /I "%~1" 2^>^nul'
) DO FOR /F "delims=" %%A IN ("%%I") DO SET "%2=%%A"
Exit /b
::****************************************************
a alternative way also prints only the max resolution of the screen:
for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b"
if version lss 62 (
::set "wmic_query=wmic desktopmonitor get screenheight, screenwidth /format:value"
for /f "tokens=* delims=" %%# in ('wmic desktopmonitor get screenwidth /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "x=%%#"
)
for /f "tokens=* delims=" %%# in ('wmic desktopmonitor get screenheight /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "y=%%#"
)
) else (
::wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
for /f "tokens=* delims=" %%# in ('wmic path Win32_VideoController get CurrentHorizontalResolution /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "x=%%#"
)
for /f "tokens=* delims=" %%# in ('wmic path Win32_VideoController get CurrentVerticalResolution /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "y=%%#"
)
)
echo Resolution %x%x%y%
Related
I'm making a program that needs a pendrive, and I want detect if a pendrive is in the pc and distinguish he from a internal disk or anything else, somebody can help me?
Here's an example.
#Echo Off
SetLocal EnableExtensions EnableDelayedExpansion
For /F "Skip=2 Tokens=*" %%A In ('WMIC DiskDrive Where InterfaceType^="USB"^
Assoc /AssocClass:Win32_DiskDriveToDiskPartition 2^>Nul') Do (
For /F UseBackQ^ Delims^=^"^ Tokens^=2 %%B In ('%%A') Do (
For /F Delims^=^":^ Tokens^=6 %%C In (
'WMIC Path Win32_LogicalDiskToPartition^|Find "%%B"') Do (
For /F "Skip=1 Delims=" %%D In ('WMIC LogicalDisk Where^
"DeviceID='%%C:'" Get DeviceID^, VolumeName') Do Echo( %%D
Set "_C=!_C!%%C")))
If Not Defined _C Echo( You do not have a USB drive connected && GoTo :EndIt
If "%_C:~,1%" Equ "%_C%" GoTo :Picked
Echo( Enter the USB drive letter from the above [%_C%]:
For /F "Delims=? Tokens=2" %%A In ('Choice /C %_C%') Do Set "Letter=%%A:"
:Picked
If Not Defined Letter (Call :Task %_C%:) Else (Call :Task %Letter%)
:EndIt
>Nul Timeout 5
Exit/B
:Task
Rem Place your commands here
Echo Your selected pen drive is %1
Pause
I tried to find the answer on some other threads, but i think that what i'm trying to do is a bit "specific". I'm not enough good with batch to adapt/concatenate parts of scripts i've found as well...
So, i'm trying to execute a command, depending of the running screen resolution.
The context is the following;
The command executed at the logon is placing the shortcuts on the desktop specifically, but it's not the same placement between the resolutions...
the idea is to define a variable, which is the answer of a wmic desktopmonitor get screenheight, screenwidth request. Then if the output contains 1080, so execute this cmd, else if it contains 720, execute another one, etc...
thats the cmd i use for win7 (working);
for /f "tokens=1-2 delims= " %%r in ('wmic desktopmonitor get screenheight^, screenwidth ^| findstr "1"') do set current_res=%%sx%%r
if "%current_res%" == "1920x1080" C:\Windows\kiosque\desktopok.exe /load /silent c:\windows\kiosque\dispo_icones_1080p.dok
i need to do the same with win10 with the wmic path Win32_VideoController get VideoModeDescription, but i didn't found how to define the output of this request properly as a variable...
You need different wmic queries depending on the windows version.Here's a resolution getter that depends on the version:
#echo off
::https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
setlocal
for /f "tokens=4,5 delims=. " %%a in ('ver') do set "version=%%a%%b"
if version lss 62 (
::wmic_query=wmic desktopmonitor get screenheight, screenwidth /format:value"
for /f "tokens=* delims=" %%# in ('wmic desktopmonitor get screenwidth /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "x=%%#"
)
for /f "tokens=* delims=" %%# in ('wmic desktopmonitor get screenheight /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "y=%%#"
)
) else (
::wmic path Win32_VideoController get VideoModeDescription,CurrentVerticalResolution,CurrentHorizontalResolution /format:value
for /f "tokens=* delims=" %%# in ('wmic path Win32_VideoController get CurrentHorizontalResolution /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "x=%%#"
)
for /f "tokens=* delims=" %%# in ('wmic path Win32_VideoController get CurrentVerticalResolution /format:value') do (
for /f "tokens=2 delims==" %%# in ("%%#") do set "y=%%#"
)
)
echo Resolution %x%x%y%
::if "%x%x%y%" == "1920x1080" C:\Windows\kiosque\desktopok.exe /load /silent c:\windows\kiosque\dispo_icones_1080p.dok
endlocal
For windows 7 or earlier you need desktopmonitor class for the newer windows versions you need Win32_VideoController .you can try with dxdiag too:
#echo off
del ~.txt /q /f >nul 2>nul
start "" /w dxdiag /t ~
setlocal enableDelayedExpansion
set currmon=1
for /f "tokens=2 delims=:" %%a in ('find "Current Mode:" ~.txt') do (
echo Monitor !currmon! : %%a
set /a currmon=currmon+1
)
endlocal
del ~.txt /q /f >nul 2>nul
Because Win32_VideoController has been tested as working on my Windows 7 and Windows 10 systems, here are some Win32_VideoController examples:
Retrieving the horizontal resolution, as intimated in your question as the determining factor:
For /F "Delims=" %%A In (
'WMIC Path Win32_VideoController Get CurrentHorizontalResolution'
) Do For %%B In (%%A) Do Set "ResW=%%B"
Likewise if you wanted to check only the vertical resolution:
For /F "Delims=" %%A In (
'WMIC Path Win32_VideoController Get CurrentVerticalResolution'
) Do For %%B In (%%A) Do Set "ResH=%%B"
And if you wanted the resolution in WxH format:
#Echo Off
Set "WP=Path Win32_VideoController"
Set "WV=CurrentHorizontalResolution,CurrentVerticalResolution"
For /F "Skip=1 Tokens=*" %%A In ('"WMIC %WP% Get %WV%"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set ScRes=%%Bx%%C
Echo=%ScRes%
Pause
If you wanted a version which accounts for both DesktopMonitor and Win32_VideoController, then perhaps this will do, (from Vista onwards):
#Echo Off
Set "OV="
For /F "EOL=V" %%A In ('WMIc OS Get Version 2^>Nul'
) Do For /F "Tokens=1-2 Delims=." %%B In ("%%A") Do Set /A "OV=%%B%%C"
If Not Defined OV Exit /B
Set "ScRes=%%Cx%%B" & Set "WP=DesktopMonitor"
Set "WV=ScreenHeight,ScreenWidth"
If %OV% GEq 61 (Set "WP=Path Win32_VideoController" & Set "ScRes=%%Bx%%C"
Set "WV=CurrentHorizontalResolution,CurrentVerticalResolution")
For /F "Skip=1 Tokens=*" %%A In ('"WMIC %WP% Get %WV%"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set ScRes=%ScRes%
Echo=%ScRes%
Pause
I have left line 8 as GEq 61 for versions of at least Windows 7, because as I've stated, it works on my Windows 7 version.You could however change that to read Gtr 61 for Windows 8/Server 2012 and above, or even Gtr 63 if you want to limit it to anything above Windows 8.1/Server 2012 R2
how can set the DeviceID in a variable? output here is empty :(
in cmd working :
D:\>wmic logicaldisk where drivetype=5 get deviceid, volumename | find "bunny"
F: bd50-bunny-comple
here is my bat:
#echo off
d:\bunny.iso
set isoname=bunny
for /f "delims=" %%a in ('wmic logicaldisk where DriveType^="5" Get DeviceID^,volumename ^|find "%isoname%"') do (
set %%a
)
echo %DeviceID%
echo %volumename%
Regards
Based on Magoo's comment :
#echo off
SETLOCAL ENABLEDELAYEDEXPANSION
For /F "skip=1" %%a in ('wmic logicaldisk where DriveType^="5" Get DeviceID^,volumename') DO (
SET "line=%%a"
CALL :striptrailing
if not "!line!"=="" (
set "myvar=!line!"
goto :loop_end
)
)
::****************************************
:loop_end
ECHO %myvar%
pause & GOTO :EOF
::****************************************
:striptrailing
IF NOT DEFINED line GOTO :EOF
if "%line:~-1%"==" " GOTO striptrailing
GOTO :eof
::****************************************
Something like this perhaps:
#Echo Off
For /F "Skip=1 Delims=" %%A In (
'"WMIC LogicalDisk Where (DriveType='5') Get DeviceID, VolumeName"'
) Do For /F "Tokens=1-2" %%B In ("%%A") Do Set "DID=%%B" & Set "VOL=%%C"
Echo Volume %VOL% is assigned to %DID%
Timeout -1
I have a program to ping computers, check there registry, and tell me the results.
I am now trying to script it so that I don't have to know the ip address just the host name of the computer.
I found a script to give me the ip off of a hostname
for /f "tokens=1,2 delims=[]" %%a in ('ping -4 %%a ^| find "Pinging"') do set ip=%%c >nul
I have tried to simply insert this into a biger loop that uses a file to give it the host names.
for /f %%A in (%1) do (
for /f "tokens=1,2 delims=[]" %%a in ('ping -4 %%a ^| find "Pinging"') do (
set host=%%a
set ip=%%c
echo "."
echo %ip% %host%
pause
) >>%2
)
I have also tried it like this,
for /f %%a in (%1) do (
set /p hostname=%%a
for /f "tokens=1,2 delims=[]" %%b in ('ping -4 %%a ^| find "Pinging"') do set ip=%%c >nul
echo %ipaddress% %hostname%
)
Please any help on this would be greatly appreciated.
Thank you.
AFTER MUTCH HEAD BANGING
#echo off
SETLOCAL EnableDelayedExpansion
for /f %%A in (%1) do (
for /f "tokens=1,2 delims=[]" %%a in ('ping /4 /n 1 %%A ^| findstr "Pinging"') do echo "%%A %%b"
)
Getting drives in variable
LogicalDisk = "c:\d:\"
now i want to get drives separated by semicolon;
like LogicalDisk = "c:\;d:\;e:\;f:\"
#echo on
setlocal enabledelayedexpansion
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do (
set "LogicalDisk=!LogicalDisk!%%d\"
)
echo %LogicalDisk%
endlocal
pause
either
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do (
set "LogicalDisk=!LogicalDisk!%%d\;"
)
set"LogicalDisk=%LogicalDisk:~0,-1%"
echo %LogicalDisk%
or
for /f "tokens=2 delims==" %%d in ('wmic logicaldisk where "drivetype=3" get name /format:value') do (
set "LogicalDisk=!LogicalDisk!%%d\"
)
set"LogicalDisk=%LogicalDisk:\=\;%"
set"LogicalDisk=%LogicalDisk:~0,-1%"
echo %LogicalDisk%