®®® Posted April 16, 2005 Report Share Posted April 16, 2005 hazart i have a question. What is the output on Windows 2003 if you open up a command window (Run Box, then type "cmd") and type "ver"? Microsoft Windows [Version 5.2.3790] :) thanks, that helped! Now can you paste the following to a new created text file and save it as .BAT and run it and report what it says: ver | find /i "Windows [5.2.">NUL if not errorlevel 1 set v_os=2k3 else set v_os=not available echo Your OS is: %v_os% pause :( Aha, you are detecting operating systems in a batch job! :( You should have told me this earlier, so: if not "%OS%"=="Windows_NT" goto WRONGOSif not exist %systemroot%\system32\find.exe goto WRONGOS ver>%temp%\~diskopt.tmp find "5.1.2600" %temp%\~diskopt.tmp /c> NUL del %temp%\~diskopt.tmp if %errorlevel% equ 0 ( set ver=XPPRO if not exist %systemroot%\system32\fsutil.exe set ver=XPHOME goto CORRECTOS ) find "5.2.3790" %temp%\~diskopt.tmp /c> NUL if %errorlevel% equ 0 ( set ver=2003 goto CORRECTOS ) goto WRONGOS This is part of an OS detection I wrote in my DiskOpt batch job some time ago. It distinguishes Windows XP Home, Windows XP Pro, and Windows Server 2003. Fully tested, it never fails! :P BTW, the first line can eliminate Windows ME, Windows 98 and earlier. The second line is to test whether FIND.EXE exists. If not, goto WRONGOS. WRONGOS and CORRECTOS are just labels I used in my batch file. Do you still want me to run your .BAT and report to you what it says? :) This is great :P I will defenitealy look deeper into your suggestions a bit later, but for now can you also export for me the root of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion which would then look like this (remove all personal, sensitive data, but pls. include all reg keys): [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion] "SubVersionNumber"="" "CurrentBuild"="1.511.1 () (Obsolete data - do not use)" "InstallDate"= "ProductName"="Microsoft Windows XP" "RegDone"="" "RegisteredOrganization"= "RegisteredOwner"= "SoftwareType"="SYSTEM" "CurrentVersion"="5.1" "CurrentBuildNumber"="2600" "BuildLab"="2600.xpsp_sp2_gdr.050301-1519" "CurrentType"="Uniprocessor Free" "CSDVersion"="Service Pack 2" "SystemRoot"="C:\\WINDOWS" "SourcePath"="G:\\I386" "PathName"="C:\\WINDOWS" "ProductId" "DigitalProductId" I need to compare any differences between 2003 and XP or 2000 for my batch files...Thanks Link to comment Share on other sites More sharing options...
®®® Posted April 16, 2005 Author Report Share Posted April 16, 2005 fsutil is also not on XP Home :) . ###### i wonder how i should ever finish my batches. I use taskkill to distinguish between XP Home and Pro :) Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 Here you are: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion]"CurrentBuild"="1.511.1 () (Obsolete data - do not use)""InstallDate"=dword:422e0d6a "ProductName"="Microsoft Windows Server 2003" "RegDone"="" "RegisteredOrganization"="<removed as suggested>" "RegisteredOwner"="<removed as suggested>" "SoftwareType"="SYSTEM" "CurrentVersion"="5.2" "CurrentBuildNumber"="3790" "BuildLab"="3790.srv03_gdr.050225-1827" "CurrentType"="Uniprocessor Free" "SystemRoot"="C:\\WINDOWS" "SourcePath"="H:" "PathName"="C:\\WINDOWS" "ProductId"="<removed as suggested>" "DigitalProductId"=hex:<removed as suggested> "LicenseInfo"=hex:<removed as suggested> N.B. All patches have been installed except SP1. Good luck writing your batch! :) I think it's great fun! :) Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 (edited) //edit maybe i need that for later reference and as my PM box is always 94% full i need to delete some message quote ®®®:That what comes when i'm too hectic :) sending out PMs. Your're defenitely correct with what you wrote. Interesting though concerning the 5.x numbers in the ver output. I will switch to that in the future. Thanks also for the hint with chinese localised output. That's really a must to know :) . Do you know by chance the ver output of Windows XP 64bit ? I guess it should contain 5.2.3790 as well. FYI, the RTM build for all versions (WinSRV2003 SP1/x64 XP/x64 Server) is 5.2.3790.1830. Whether the VER of these OS's will output 5.2.3790 or 5.2.3790.1830 is unkown. It seems to be impossible to distinguish between them using the VER method. Anyway, I posted a screenshot in our post; check it out! :P Edited April 17, 2005 by ®®® Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 I think the ".1830" will not be shown by VER, because Windows Server 2003 RTM's version is actually 5.2.3790.0 but the trailing ".0" is not shown in the VER output. A screenshot of Windows XP Pro X64 (RTM version on MSDN): :) Link to comment Share on other sites More sharing options...
®®® Posted April 16, 2005 Author Report Share Posted April 16, 2005 Here's another one: I have all my batches readout the current CPU Speed. Though it works only on PC with WMCI installed (default on XP Pro), so on Windows 2000 and Windows XP Home it doesn't work Now finally i decided to implement a more compatible way of reading out this value. I fiddled around with the registry readout earlier, but gave up as i can't figure how to convert HEX values to DECIMAL values in batch files. Can anybody help here? The CPU Speed can be found here: [HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0] "ProcessorNameString"=" Mobile Intel® Pentium® 4 - M CPU 2.00GHz" "~MHz"=dword:000007c9 (<-1993 Mhz) Is there kind of an easy way to convert it, where 7 = HEXvalue1 c = HEXvalue2 9 = HEXvalue3 and the formula would then be something like this: (HEXvalue1*8)+(HEXvalue2*8)+(HEXvalue3*8)=DECIMALvalue I know this is totally wrong, but something like this would probably easy to be realizable in batch files. Here's a table http://www.maths.hscripts.com/hexConverter.php , but i can't determine a formula. Hex to binary to Decimal would be the step, right? Hex to Binary would be realizable in the batch i think, but then conversion from Binary to Decimal is unknown by me Does anyone know where one can find the installed RAM in the registry (probably also HEX or Binary). There is nothing i could find, but it must be somewhere! In Windows 2000 and XP Home (where both don't have WMCI installed) the amount of RAM is shown in the First page of the "System" control panel. In 2000 is the exact amount of Kilobytes shown, in XP the rounded RAM amount in MB (like 512MB). Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 Mmm, hex->dec conversion.. An example: If you want to convert $A0FE to dec, then you do 10*16^3+0*16^2+15*16^1+14*16^0=40960+0+240+14=41214 It is feasible to implement the conversion in a batch, but it requires some thought... :) Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 BTW, how can you read out only the value of a key in the registry? I used reg query HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0 /v ~MHz and I got HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0 ~MHz REG_DWORD 0x69e How can I put 69e into a variable? :) And how can I put "6", "9", and "e" in individual variables allowing future operations? This has been a problem around me for ages. Link to comment Share on other sites More sharing options...
®®® Posted April 16, 2005 Author Report Share Posted April 16, 2005 (edited) That's indeed a problem. Especially when you need 2K compatibilty where there's no reg.exe :( I will regedit /e (at least for CPU related stuff and compatibilty to all OS) and process the output. ...in combination with "for /f" and delim=dword: No 0x stuff in front here :P Pieter just posted the solution: My very first Computer (I wrote about elsewhere) had the 6502 CPU, this had the ability to do both Decimal and hex (binary) calculations.Of no use to you Rene, but I feel better for telling this useless information. One clue I can give you need to multiply each hex multiple of 10 (dec 16) x 16. ie hex value XYZ = dec value (Xx16x16)+(Zx16)+Z so hex 7c9 = (7x16x16)+(12©x16)+9 = 1993 (wow it even works) Hope this helps, 6502 Assembly Programmner Btw i used wmic, but speedwise it's a pain :) Also it's not available at 2K and XP Home :) for /f "skip=1 tokens=1" %%G in ('WMIC /locale:ms_409 cpu get CurrentClockSpeed') do (set v_wmi_cpu_CurrentClockSpeed=%%G) for /f "skip=1 tokens=1" %%G in ('WMIC /locale:ms_409 memlogical get TotalPhysicalMemory') do (set v_wmi_memlogical_TotalPhysicalMemory=%%G) Edited April 16, 2005 by ®®® Link to comment Share on other sites More sharing options...
®®® Posted April 16, 2005 Author Report Share Posted April 16, 2005 How can I put 69e into a variable? And how can I put "6", "9", and "e" in individual variables allowing future operations? This has been a problem around me for ages. It took some time, research and customization, but finally i figured that too in NVLiTE.bat: determine driver version from any NV driver INF and at the same time getting rid of all the dots except one will result in 7.1.8.4 -> v71.84 for /f "tokens=2* delims=," %%G in ('type "*.inf" ^| find /i "DriverVer "') do (set V_NVVER=%%G) ::credits: http://www.robvanderwoude.com/bht.html HowTo #4 ::credits: http://www.ss64.com/ntsyntax/varsubstring.html set V_NVVER=%V_NVVER: =% set V_NVVER1=%V_NVVER:~-1,1%&set V_NVVER2=%V_NVVER:~-3,1%&set V_NVVER3=%V_NVVER:~-4,1%&set V_NVVER4=%V_NVVER:~-5,1%&set V_NVVER5=%V_NVVER:~-7,1% set V_NVVER=v%V_NVVER5%%V_NVVER4%%V_NVVER3%%V_NVVER2%%V_NVVER1% Link to comment Share on other sites More sharing options...
hazart Posted April 16, 2005 Report Share Posted April 16, 2005 Oh my goodness! :) I have to take a look at it! Thanks a lot. Link to comment Share on other sites More sharing options...
®®® Posted April 17, 2005 Author Report Share Posted April 17, 2005 (edited) oh my god, i just found it :P fasten your seat belt, it's tooo simple to believe: SET /A v_result="0x7c9" results in 1993 :) and i wrote code and code and code. //explanation: just set 0x (for hex or 0b for binaries) in front of the %variable%: set /a v_result="0x%variable%" source (as always :( ): ss64.com Now the only thing which i need is the RAM location in the registry. And i don't care now anymore if it's a hex or binary value :) Edited April 17, 2005 by ®®® Link to comment Share on other sites More sharing options...
hazart Posted April 17, 2005 Report Share Posted April 17, 2005 :) Ah, this "set /a" usage is actually detailed in the SET's built-in help. :) C:\DOCUME~1\???>set/?Displays, sets, or removes cmd.exe environment variables. SET [variable=[string]] variable Specifies the environment-variable name. string Specifies a series of characters to assign to the variable. Type SET without parameters to display the current environment variables. If Command Extensions are enabled SET changes as follows: SET command invoked with just a variable name, no equal sign or value will display the value of all variables whose prefix matches the name given to the SET command. For example: SET P would display all variables that begin with the letter 'P' SET command will set the ERRORLEVEL to 1 if the variable name is not found in the current environment. SET command will not allow an equal sign to be part of the name of a variable. Two new switches have been added to the SET command: SET /A expression SET /P variable=[promptString] The /A switch specifies that the string to the right of the equal sign is a numerical expression that is evaluated. The expression evaluator is pretty simple and supports the following operations, in decreasing order of precedence: () - grouping ! ~ - - unary operators * / % - arithmetic operators + - - arithmetic operators << >> - logical shift & - bitwise and ^ - bitwise exclusive or | - bitwise or = *= /= %= += -= - assignment &= ^= |= <<= >>= , - expression separator If you use any of the logical or modulus operators, you will need to enclose the expression string in quotes. Any non-numeric strings in the expression are treated as environment variable names whose values are converted to numbers before using them. If an environment variable name is specified but is not defined in the current environment, then a value of zero is used. This allows you to do arithmetic with environment variable values without having to type all those % signs to get their values. If SET /A is executed from the command line outside of a command script, then it displays the final value of the expression. The assignment operator requires an environment variable name to the left of the assignment operator. Numeric values are decimal numbers, unless prefixed by 0x for hexadecimal numbers, and 0 for octal numbers. So 0x12 is the same as 18 is the same as 022. Please note that the octal notation can be confusing: 08 and 09 are not valid numbers because 8 and 9 are not valid octal digits. The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty. Environment variable substitution has been enhanced as follows: %PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of "str1" in the expanded result with "str2". "str2" can be the empty string to effectively delete all occurrences of "str1" from the expanded output. "str1" can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first occurrence of the remaining portion of str1. May also specify substrings for an expansion. %PATH:~10,5% would expand the PATH environment variable, and then use only the 5 characters that begin at the 11th (offset 10) character of the expanded result. If the length is not specified, then it defaults to the remainder of the variable value. If either number (offset or length) is negative, then the number used is the length of the environment variable value added to the offset or length specified. %PATH:~-10% would extract the last 10 characters of the PATH variable. %PATH:~0,-2% would extract all but the last 2 characters of the PATH variable. Finally, support for delayed environment variable expansion has been added. This support is always disabled by default, but may be enabled/disabled via the /V command line switch to CMD.EXE. See CMD /? Delayed environment variable expansion is useful for getting around the limitations of the current expansion which happens when a line of text is read, not when it is executed. The following example demonstrates the problem with immediate variable expansion: set VAR=before if "%VAR%" == "before" ( set VAR=after if "%VAR%" == "after" @echo If you see this, it worked ) would never display the message, since the %VAR% in BOTH IF statements is substituted when the first IF statement is read, since it logically includes the body of the IF, which is a compound statement. So the IF inside the compound statement is really comparing "before" with "after" which will never be equal. Similarly, the following example will not work as expected: set LIST= for %i in (*) do set LIST=%LIST% %i echo %LIST% in that it will NOT build up a list of files in the current directory, but instead will just set the LIST variable to the last file found. Again, this is because the %LIST% is expanded just once when the FOR statement is read, and at that time the LIST variable is empty. So the actual FOR loop we are executing is: for %i in (*) do set LIST= %i which just keeps setting LIST to the last file found. Delayed environment variable expansion allows you to use a different character (the exclamation mark) to expand environment variables at execution time. If delayed variable expansion is enabled, the above examples could be written as follows to work as intended: set VAR=before if "%VAR%" == "before" ( set VAR=after if "!VAR!" == "after" @echo If you see this, it worked ) set LIST= for %i in (*) do set LIST=!LIST! %i echo %LIST% If Command Extensions are enabled, then there are several dynamic environment variables that can be expanded but which don't show up in the list of variables displayed by SET. These variable values are computed dynamically each time the value of the variable is expanded. If the user explicitly defines a variable with one of these names, then that definition will override the dynamic one described below: %CD% - expands to the current directory string. %DATE% - expands to current date using same format as DATE command. %TIME% - expands to current time using same format as TIME command. %RANDOM% - expands to a random decimal number between 0 and 32767. %ERRORLEVEL% - expands to the current ERRORLEVEL value %CMDEXTVERSION% - expands to the current Command Processor Extensions version number. %CMDCMDLINE% - expands to the original command line that invoked the Command Processor. We should have read the help carefully first. :P Link to comment Share on other sites More sharing options...
hazart Posted April 17, 2005 Report Share Posted April 17, 2005 I have a free little tool (the latest version) which can be used to monitor registry changes. The program is self-explanatory. Hope it is useful to you. :) regshot.zip Link to comment Share on other sites More sharing options...
®®® Posted April 17, 2005 Author Report Share Posted April 17, 2005 Currently it's like this: if /i "%v_os%"=="2k" (call :KILLPROCESS) else (if /i "%v_os%"=="xphome" (call :KILLPROCESS) else (start /w /min "killcpax" taskkill /F /IM cpax* /T)) . . more code... . more code... . . ::SUBROUTINES :KILLPROCESS set v_head_info= Pls. close the cPax process and after that press a key to continue.&call :HEAD_INFO&taskmgr.exe&pause >NUL&goto :eof but i intent to shorten the double code, so do you know if it's possible to write code like this: if /i "%v_os%"=="2k" OR if /i "%v_os%"=="xphome" (call :KILLPROCESS) else [in case of xphome/2k3](start /w /min "killcpax" taskkill /F /IM cpax* /T) See, i want that if both 2k OR xphome is detected there is one and the same action done (call :KILLPROCESS subroutine). I know that there is the || (or), but from the explanation it will not work how i want it: An OR list of commands has the form command1 || command2 command2 is executed if, and only if, command1 fails I want that the command "call :KILLPROCESS" is executed in both cases in combination with: if OS=2k and xphome.The '&' is also not siutable i think in combination with 'if' A single "&" will always execute both commands command1 & command2 Any ideas? Link to comment Share on other sites More sharing options...
hazart Posted April 18, 2005 Report Share Posted April 18, 2005 This is what I want to know as well. A part of my batch looks like this for two years. It works perfectly, but just doesn't look very professional :) if "%1"=="/?" goto CPHELP if "%2"=="/?" goto CPHELP if "%3"=="/?" goto CPHELP if "%4"=="/?" goto CPHELP if "%5"=="/?" goto CPHELP if /i "%1"=="/h" goto CPHELP if /i "%2"=="/h" goto CPHELP if /i "%3"=="/h" goto CPHELP if /i "%4"=="/h" goto CPHELP if /i "%5"=="/h" goto CPHELP if /i "%1"=="/ver" goto CPDISKOPTVER if /i "%2"=="/ver" goto CPDISKOPTVER if /i "%3"=="/ver" goto CPDISKOPTVER if /i "%4"=="/ver" goto CPDISKOPTVER if /i "%5"=="/ver" goto CPDISKOPTVER Many lines above could have been combined, but I don't know how. Link to comment Share on other sites More sharing options...
®®® Posted April 19, 2005 Author Report Share Posted April 19, 2005 What are the %2 %3 %4 %5 needed for? I just began to dig deeper into the switches thing. Not much experience here, but it works great in one of my batches. Link to comment Share on other sites More sharing options...
hazart Posted April 21, 2005 Report Share Posted April 21, 2005 What are the%2 %3 %4 %5 needed for? I just began to dig deeper into the switches thing. Not much experience here, but it works great in one of my batches. %1 - first parameter %2 - second parameter %3 - third parameter and so on... For example: For the command chkbat /r /s /f /r=1% /s=2% /f=3% :) Link to comment Share on other sites More sharing options...
Recommended Posts