When try to get CPU temperature in Windows 10 Get-WmiObject: Not supported ERROR - cpu

I am trying to get CPU temperature with this command;
#echo off
for /f "skip=1 tokens=2 delims==" %%A in ('wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value') do set /a "HunDegCel=(%%~A*10)-27315"
echo %HunDegCel:~0,-2%.%HunDegCel:~-2% Degrees Celsius
And I am getting this error;
ERROR:
Description = Not supported
I also tried different methods with WMI but I got this error;
Get-WmiObject : Not supported
How can I get the CPU temperature?

Related

BATCH: Variable set by for loop ends up being blank

I am trying to run the following script
#ECHO OFF
FOR /F "Skip=1 Tokens=*" %%G IN ('WMIC COMPUTERSYSTEM GET Manufacturer') DO (SET "DeviceOEM=%%G")
ECHO OEM: %DeviceOEM%
PAUSE
However all I get is "ECHO OEM:", which indicates that %DeviceOEM% is blank.
Now if I run
FOR /F "Skip=1 Tokens=*" %%G IN ('WMIC COMPUTERSYSTEM GET Manufacturer') DO (ECHO %%G)
PAUSE
Then I get a real answer of my OEM.
I don't understand where this SET command is failing.
When delim is issued on = it will only assign the value after the = to the value. We therefore change the wmic command to issue the result with /value which will return Manufacturer=<name of OEM> where we only use everything post =
#echo off
For /F "tokens=2*delims==" %%G in ('WMIC COMPUTERSYSTEM GET Manufacturer /value') do SET "DeviceOEM=%%G"
echo OEM: %DeviceOEM%

For loop not working properly in batch file

I am trying to get the current operating system using this batch file. It is:
#echo off
for /f "skip=1 tokens=1* delims= " %%a in ('wmic path win32_operatingsystem get caption') do set _os=%%a %%b %%c %%d
echo You are running %_os%.
goto :eof
My operating system is windows 7 so I expected it will return:
You are running Microsoft Windows 7 Ultimate.
But it returns you are running %c %d.
Why I am getting this result?
There are a few ways, one already posted by Mofi in the above comment which already demonstrates the main change using /value. You can also use the caption itself as variable name with its value:
#echo off
for /f "delims=" %%a in ('wmic path win32_operatingsystem get caption /value') do set %%a>nul 2>&1
echo %caption%

Extracting timezone in windows

I am fairly new to windows batch file and I need to extract the timezone value.Is there anyway I can just extract +5:30 from below command ?
Or any other way that just gives me the timezone in +05:30 format.
systeminfo | findstr /C:"Time Zone"
Time Zone: (UTC+05:30) Chennai, Kolkata, Mumbai, New
Delhi
I can't user powershell for it
Use a for /f loop to capture the output of a command:
#echo off
for /f "tokens=2 delims=()" %%a in ('systeminfo ^| find "(UTC"') do set tzone=%%a
echo sysinfo: %tzone:~3%
(I took the freedom to change the search string to (UTC because Time Zone isn't international (I get "Zeitzone" instead)
but I guess you will like this one more:
for /f "tokens=2 delims=()" %%a in ('wmic timezone get caption /value') do set tzone=%%a
echo wmic: %tzone:~3%
or (with a little cheating):
for /f "tokens=2 delims=C)" %%a in ('wmic timezone get caption /value') do set tzone=%%a
echo wmic: %tzone%
You can also get the Bias in minutes with wmic timezone get Bias /value
Using a WMI-query works way faster than using SYSTEMINFO, as SYSTEMINFO scans for way more information and only "timezone" (or "Zeitzone" or whatever it's named) is used later on. That's why you have to use FINDSTR to just filter for "timezone".
Using a WMI-query has the additional advantage that it's language-independant, so you don't have to make changes to cover "timezone", "Zeitzone", "zona horaria" or whatever language your OS happens to run at the moment.
#echo off
for /F "eol=; tokens=2 delims=^(^)" %%I in ('wmic timezone get caption /format:list') do (
set "daUtcTimeZone=%%I"
)
rem remove "UTC" from string
set "daUtcBiasHHMM=%daUtcTimeZone:UTC=%"
echo daUtcTimeZone: %daUtcTimeZone%
echo daUtcBiasHHMM: %daUtcBiasHHMM%
PAUSE
Result:
daUtcTimeZone: UTC+01:00
daUtcBiasHHMM: +01:00
Querying all WMI-values from "timezone" you get even more options to chose from... have a look by replacing "caption" with an asterisk to see them all:
wmic timezone get * /format:list
Result:
Bias=60
Caption=(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien
DaylightBias=-60
DaylightDay=5
DaylightDayOfWeek=0
DaylightHour=2
DaylightMillisecond=0
DaylightMinute=0
DaylightMonth=3
DaylightName=Mitteleuropäische Sommerzeit
DaylightSecond=0
DaylightYear=0
Description=(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien
SettingID=
StandardBias=0
StandardDay=5
StandardDayOfWeek=0
StandardHour=3
StandardMillisecond=0
StandardMinute=0
StandardMonth=10
StandardName=Mitteleuropäische Zeit
StandardSecond=0
StandardYear=0
So you can as well get the bias in minutes for example using...
for /F "eol=; tokens=2 delims==" %%I in ('wmic timezone get bias /format:list') do (
set "daBias=%%I"
)
echo daBias: %daBias%
Result:
daBias: 60
WMI / WMIC is available in Windows since "Windows 2000".
Using a FOR /F loop :
#echo off
for /f "tokens=2 delims=()" %%a in ('systeminfo ^| findstr /C:"UTC"') do set "$utc=%%a"
echo %$utc:~3%

Batch-file get CPU temperature in °C and set as variable

How do i get a batch-file to work out the temperature of the Cpu and return it as a variable. I know it can be done as i have seen it been done. The solution can use any external tool. I have looked on Google for at least 2 hours but found nothing. Can any one help. Thanks.
You can use wmic.exe:
wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature
The output from wmic looks like this:
CurrentTemperature
2815
The units for MSAcpi_ThermalZoneTemperature are tenths of degrees Kelvin, so if you want celsius, you'd do something like this:
#echo off
for /f "delims== tokens=2" %%a in (
'wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value'
) do (
set /a degrees_celsius=%%a / 10 - 273
)
echo %degrees_celsius%
A few things:
1) The property may or may not be supported by your hardware.
2) The value may or may not update more than once per boot cycle.
3) You may need Administrative privileges to query the value.
Here is an example which keeps the decimal values and uses the full conversion value.
Code
#echo off
for /f "skip=1 tokens=2 delims==" %%A in ('wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature /value') do set /a "HunDegCel=(%%~A*10)-27315"
echo %HunDegCel:~0,-2%.%HunDegCel:~-2% Degrees Celsius
Output
38.05 Degrees Celsius
If you computer support it you can try like this :
wmic /namespace:\\root\wmi PATH MSAcpi_ThermalZoneTemperature get CurrentTemperature
This will output the temperature in degree Kelvin.

Batch Script related issue

I have written following script which works absolutely fine on my system.
#echo off
setlocal enabledelayedexpansion
FOR /F %%i IN ('wmic /node:%1 computersystem get Name') DO SET A=%%i
FOR /F %%i IN ('wmic /node:%1 computersystem get Domain') DO SET B=%%i
FOR /F %%i IN ('wmic /node:%1 computersystem get UserName') DO SET C=%%i
FOR /F %%i IN ('wmic /node:%1 computersystem get Manufacturer') DO SET D=%%i
FOR /F "delims=" %%i IN ('wmic /node:%1 computersystem get Model') DO SET E=%%i
FOR /F %%i IN ('wmic /node:%1 computersystem get SystemType') DO SET F=%%i
FOR /F %%i IN ('wmic /node:%1 bios get SerialNumber') DO SET G=%%i
FOR /F "delims=|" %%i IN ('wmic /node:%1 os get Name') DO SET H=%%i
FOR /F %%i IN ('wmic /node:%1 os get TotalVisibleMemorySize') DO (SET J=%%i)
SET /a J=%J%/1024
FOR /F "delims=" %%i IN ('wmic /node:%1 cpu get Name') DO SET K=%%i
echo %A%,%B%,%C%,%D%,%E%,%F%,%G%,%H%,%J% MB,%K% >> output.csv
But, with some modifications in it which are shown below, it doesn't display any information.
#echo off
setlocal enabledelayedexpansion
ping -n 1 %1 | find "TTL=" > NUL
IF NOT ERRORLEVEL 1 (
FOR /F %%i IN ('wmic /node:%1 computersystem get Name') DO (SET A=%%i)
FOR /F %%i IN ('wmic /node:%1 computersystem get Domain') DO (SET B=%%i)
FOR /F %%i IN ('wmic /node:%1 computersystem get UserName') DO (SET C=%%i)
FOR /F %%i IN ('wmic /node:%1 computersystem get Manufacturer') DO (SET D=%%i)
FOR /F "delims=" %%i IN ('wmic /node:%1 computersystem get Model') DO (SET E=%%i)
FOR /F %%i IN ('wmic /node:%1 computersystem get SystemType') DO (SET F=%%i)
FOR /F %%i IN ('wmic /node:%1 bios get SerialNumber') DO (SET G=%%i)
FOR /F "delims=|" %%i IN ('wmic /node:%1 os get Name') DO (SET H=%%i)
FOR /F %%i IN ('wmic /node:%1 os get TotalVisibleMemorySize') DO (SET J=%%i)
SET J=%J%/1024
FOR /F "delims=" %%i IN ('wmic /node:%1 cpu get Name') DO (SET K=%%i)
echo %A%,%B%,%C%,%D%,%E%,%F%,%G%,%H%,%J%,%K% >> output.csv
)
It is not giving any error either. But, the generated output.csv file contains no data.
Change
IF NOT ERRORLEVEL 1 (
to
IF NOT %ERRORLEVEL%==1 (
Although, I'm not sure the ping reply looks the same when IPv6 is used instead of IPv4. You may want to investigate this further (e.g., is TTL part of an IPv6 reply?). For instance:
c:\>ping localhost
Pinging Laptop_Name [::1] with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
Delayed expansion
When the cmd parser reaches a line of a block of lines (lines surounded in parenthesis), all variable reads are replaced with the value they have at parse time, before executing the lines in the block. If the value of the variable changes inside the block, this change is not seen in the lines where the value is readed, as this read was replaced with the value of the variable before the change.
So, in your second code, the variables are changing its value, but in the final echo to the output file, as the variable reads where replaced with the value before the value change, no data is output. The variables did not have any value before the start of block execution.
If you want to maintain this style of code, you need to enable delayed expansion, and change the sintax in the variable reads that need its reads / value expansion delayed until execution time.
setlocal enabledelayedexpansion
....
if not errorlevel 1 (
....
echo !a!, !b!, !c!
)
Arithmetic
SET J=%J%/1024 should be SET /A J=!J!/1024, arithmetic requires SET /A
PING
As JamesL indicates in his answer, in the case of IPv6, there is no "TTL=" data in the output of the ping command.
In ipv4 ping command set errorlevel if any packed is lost. And you will not get packets lost when pinging a non active same subnet machine. So the best way of testing for active machine in ipv4 is to test for TTL= value in output.
In ipv6, there is not TTL output, but now, pinging a same subnet non active machine you obtain all packet lost. And the errorlevel is only set if ALL the packets are lost. If any packet reaches its target, errorlevel is not set
So, for ipv4, test TTL=, for ipv6 test errorlevel
WMIC
While this way of retrieving data is correct and will work, is more efficient to retrieve all possible data in a single query (as you did in your previous questions). The six calls for computersystem data should be written as a single wmic call.

Resources