Computer Hope
Microsoft => Microsoft DOS => Topic started by: oxicottin on February 07, 2013, 11:34:33 AM
-
Hello, I have the code below to fin if you have program files (86) and if so every time I used "%SysType%" it would give me the drive its on. For some reason I cant get it to work. Whats missing? The reason I want tis is because im running a bat from a cd and it needs to see if your running a 64bit 0r 32bit system and return text on what your running. Thanks!
::@echo off
color 2a
for %%a in (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if exist %%a:\%programfiles(x86)% set SysType=%%a:
echo.
echo Your drive is letter is "%SysType%"
echo Press any key to exit...
pause >nul
(http://i54.photobucket.com/albums/g94/oxicottin/SysType_zpsf7eb10d5.jpg)
-
It seems to be obvious. ;)
You see it in the output
if exist B:\C:\Program Files (x86) set SysType=B:
This type of path can never exist, there are two drive specifications.
And as you can see it is always there, it's C: in your case.
You don't need a loop, you only need to strip it from %programFiles(x86)%.
for /F "delims=" %%M in ("%ProgramFiles(x86)%") do set SysType=%%~dM
echo %SysType%
-
That screen grab is making my eyes bleed.
-
You don't need a loop, you only need to strip it from %programFiles(x86)%.
What about 32 bit OS? %%~d won't work, I think.
-
Will it work for 32bit as well? I have a 64bit so I cant test it.
-
Here is what I was using but it wont work it gives me the errors below. thats all I wanted to do is have it say whether or not its a 64bit or 32bit computer but be able to tell you from a CD or DVD because thats where it resides. The code below is what I was using and the picture is what it gave me when put on a DVD and ran. lol hope its better on the eyes.... ;D
@echo.off
IF EXIST "%systemroot%\programfiles(x86)" %SysType%\ (GOTO 64-Bit) ELSE (GOTO 32-Bit)
:32-Bit
ECHO. 32-Bit O/S detected
GOTO END
:64-Bit
ECHO. 64-Bit O/S detected
GOTO END
:END
echo.
echo.
echo.
echo Press any key to exit...
pause >nul
(http://i54.photobucket.com/albums/g94/oxicottin/Error_zpse968a275.jpg)
-
cd %systemroot%
cd ..
if exist "Program Files (x86)" (
set SysType=64
) else (
set SysType=32
)
on my computer, %systemroot% is "C:\Windows" whereas my programs folder is "C:\Program Files (x86)".
-
Thanks, Would I be able to capture the result to a txt file? I tried and no matter what I do I keep getting "access denied".
This is what I have added >>SysOS.txt
@echo off
color 2A
cd %systemroot%
cd ..
if exist "Program Files (x86)" (
set SysType=64
) else (
set SysType=32
)
echo.
echo.
echo. Your Operating System is %SysType%Bit >>SysOS.txt
GOTO END
:END
echo.
echo.
echo.
echo. Press any key to exit...
pause >nul
-
Would I be able to capture the result to a txt file? I tried and no matter what I do I keep getting "access denied".
echo. Your Operating System is %SysType%Bit >>SysOS.txt
Are you running it off a CD? If so, you can't write a file there. If not, maybe you do not have write permissions for the folder.
-
I will be running it from a CD but im testing from PC right now and the results posted are from my PC not a CD. When I do run from CD I thought it would creat the file on the desktop automatically but from your response it sounds like other. Im administrator on the PC... Thoughts? Thanks!
-
Why do you want to create a text file?
-
Im going to display the text from it in a button, I cant grab the text from a batch file it has to be a text file.
-
How can you be sure that any program or script run from a CD is going to have write permission on just any computer? It is bad security to allow it and many machines will not allow it. Are you trying to create an installer?
-
Salmon Trout, I don't want to go back and forth about this and your help and everyone else s in the community very much appreciated BUT I just want to know if it can be done and how and if not then so be it I will move on. I'm just trying to learn this for fun and its on my cd for personal use. Thanks!!!
-
Where do you think a batch on a CD is going to write a file to?
-
Salmon Trout, I don't want to go back and forth about this and your help and everyone else s in the community very much appreciated BUT I just want to know if it can be done and how and if not then so be it I will move on. I'm just trying to learn this for fun and its on my cd for personal use. Thanks!!!
You don't seem to understand how forums work. The idea is you state your problem clearly and people try to answer it. If you have not stated the problem clearly or if your remarks seem to indicate some kind of comprehension or knowledge issue people are going to ask questions to get to the nitty-gritty. Until they lose patience or interest. Or you tell them to stop (like you seem to be doing).
-
Writing to "%temp%" is always an option.
Here's a method from stackoverflow.
@echo off
if defined ProgramFiles(x86) (
@echo yes
@echo Some 64-bit work
) else (
@echo no
@echo Some 32-bit work
)
-
The thread title says you want the drive letter, so this should work.
@echo off
if defined ProgramFiles(x86) (
for %%a in ("%ProgramFiles(x86)%") do echo the drive letter is %%~da
) else (
echo not 64 bit
)
-
I got it to work from a DVD on 32bit and 64bit systems. The systems I tested it on were:
- 64bit system was running Win8
- 32bit was running Win7
The reason I wanted the drive letter was I thought it would have been easier that way in the initial code I started with. I hope this will help somone else since I couldn't find any information on the matter. I still am messing with trying to to figure out how to write it to a text file foxidrive, I will read about how to do the %temp% option and post results. Thank You!
@echo off
Color 2A
::(Registry Code Start)
::============================================================
echo.
echo.
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% 2>NUL | find /I /N "x86">NUL
If [%ERRORLEVEL%] == [0] (
GOTO X86
) ELSE (
GOTO X64
)
:X86
echo. 32 bit OS
GOTO END
:X64
echo. 64 bit OS
GOTO END
:END
::============================================================
::(Registry Code End)
echo.
echo. Press any key to exit...
pause >nul
-
\Hardware\Description\System\CentralProcessor
The bitness of the CPU does always not tell you the bitness of the OS. A 64 bit CPU could be running either a 32 bit or a 64 bit OS version.
-
I still am messing with trying to to figure out how to write it to a text file foxidrive, I will read about how to do the %temp% option and post results.
Instead of just echoing the drive letter, use this:
@echo off
del "%temp%\64bit.txt" 2>nul
if defined ProgramFiles(x86) for %%a in ("%ProgramFiles(x86)%") do >"%temp%\64bit.txt" echo %%~da
Then if the file doesn't exist the system is 32 bit, and if it does exist the file contains the drive letter of the %ProgramFiles(x86)% variable.
-
The bitness of the CPU does always not tell you the bitness of the OS. A 64 bit CPU could be running either a 32 bit or a 64 bit OS version.
Also command line methods for testing the bitness ("bit count") of the OS may give different results on a 64 bit system depending on whether you are running the 32 or 64 bit cmd.exe (a 64 bit system has one of each). If you shell out from a 32 bit process you get the 32 bit cmd.exe.
64 bit: %windir%\System32\cmd.exe
32 bit: %windir%\SysWoW64\cmd.exe
64 bit
C:\>set processor_a
PROCESSOR_ARCHITECTURE=AMD64
32 bit
C:\>set processor_a
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
Handy tips here
http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx
-
..
-
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
This reg key shows x86 on 32 bit Windows XP which is running on a 64 bit machine (Intel Core 2 Duo T7500)
-
foxidrive, Im going to try that...... and see what happens!
Salmon Trout, so what you saying is I might get a false reading if the system is 64bit capable but I installed a 32bit OS? Is there a way I could determine the capability of the CPU and displaying something like:
"Your CPU is Capable of runing 64bit software but OS installed is 32bit" instead of your either a 32bit or 64 bit like I been doing. Salmon, I found Davids article while searching the other day and tried it the results on a 64bit PC running Win8 and it said:
@echo off
IF PROCESSOR_ARCHITECTURE == amd64 OR
PROCESSOR_ARCHITEW6432 == amd64 THEN
echo. 64bit
ELSE
echo. 32bit
echo.
IF PROCESSOR_ARCHITECTURE == x86 AND
PROCESSOR_ARCHITEW6432 NOT DEFINED THEN
echo. 32bit
ELSE
echo. 64bit
pause
Results:
(http://i54.photobucket.com/albums/g94/oxicottin/res1_zpsb750ccc2.jpg)
Thanks... foxidrive & Salmon Trout
-
What you copied was not batch code, it's pseudocode to describe the logic.
-
Lol that would explain it then....
-
Salmon Trout, so what you saying is I might get a false reading if the system is 64bit capable but I installed a 32bit OS?
Yes. A 32 bit OS seems to report the CPU as x86 even if it is not, at least from batch. Of course in XP a user can go into Control Panel and click the System applet and see what kind of CPU they have.
-
Ok so after reading around im finding if I use PROCESSOR_ARCHITECTURE it will tell me what my Processor is capable of not what OS im runing, Correct? Or the ::(Registry Code Start) code I posted finds the processor not the OS?
Something like:
@echo off
IF %processor_architecture% == AMD64 echo 64-bit
IF %processor_architecture% == x86 echo 32-bit
pause
Then I need to find the OS ist running....
Here is a chart I found...
(http://i54.photobucket.com/albums/g94/oxicottin/CompatableChart_zpsef24f4a1.jpg)
-
Ok so after reading around im finding if I use PROCESSOR_ARCHITECTURE it will tell me what my Processor is capable of not what OS im runing, Correct?
Not quite. You can tell the OS type and in the case of a 64 bit OS you know you have a 64 bit cpu (because you already know a 64 bit OS can only run on 64 bit hardware)
Whether or not a cpu is 64 bit, processor type will always be reported as x86 by a 32 bit operating system.
Whether or not a cpu is 64 bit, processor type will always be reported as x86 by a 32 bit process in a 64 bit OS
If a cpu is 64 bit, it will be correctly reported as AMD64 or IA64 by a 64 bit process in a 64 bit OS.
of course you can find the CPU identifier from the registry, and if you happen to know what the ProcessorNameString means, then you can say if it's 32 or 64 bit.
64 bit Windows 7 running on 64 bit CPU (AMD Phenom II 945)
C:\>reg query HKLM\Hardware\Description\System\CentralProcessor\0
HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0
Component Information REG_BINARY 00000000000000000000000000000000
Identifier REG_SZ AMD64 Family 16 Model 4 Stepping 3
Configuration Data REG_FULL_RESOURCE_DESCRIPTOR FFFFFFFFFFFFFFFF0000000000000000
ProcessorNameString REG_SZ AMD Phenom(tm) II X4 945 Processor
VendorIdentifier REG_SZ AuthenticAMD
FeatureSet REG_DWORD 0x203b7dfe
~MHz REG_DWORD 0xbb8
MicrocodeUpdateStatus REG_SZ Newer Patch Not Available
PreviousPatchLevel REG_DWORD 0x0
CurrentPatchLevel REG_DWORD 0x0
PreferredPatchLevel REG_DWORD 0x0
32 bit Windows XP running on 64 bit CPU (Intel Core 2 Duo T7500)
C:\>reg query HKLM\Hardware\Description\System\CentralProcessor\0
! REG.EXE VERSION 3.0
HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0
Component Information REG_BINARY 00000000000000000000000001000000
Identifier REG_SZ x86 Family 6 Model 15 Stepping 11
Configuration Data REG_NONE FFFFFFFFFFFFFFFF0000000000000000
ProcessorNameString REG_SZ Intel(R) Core(TM)2 Duo CPU T7500 @ 2.20GHz
VendorIdentifier REG_SZ GenuineIntel
FeatureSet REG_DWORD 0xa0033fff
~MHz REG_DWORD 0x892
Update Signature REG_BINARY 00000000B3000000
Update Status REG_DWORD 0x6
Previous Update Signature REG_BINARY 00000000B3000000
Platform ID REG_DWORD 0x80
-
So this would give me a better ida then...
@echo off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt > StringCheck.txt
If %ERRORLEVEL% == 0 (
Echo "This is 32 Bit Operating system"
) ELSE (
Echo "This is 64 Bit Operating System"
)
pause
HKEY_LOCAL_MACHINE\Hardware\Description\System\CentralProcessor\0
Component Information REG_BINARY 00000000000000000000000000000000
Identifier REG_SZ Intel64 Family 6 Model 58 Stepping 9
Configuration Data REG_FULL_RESOURCE_DESCRIPTOR FFFFFFFFFFFFFFFF0000000000000000
ProcessorNameString REG_SZ Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
VendorIdentifier REG_SZ GenuineIntel
FeatureSet REG_DWORD 0x3d193fff
~MHz REG_DWORD 0x95b
Update Revision REG_BINARY 0000000015000000
Update Status REG_DWORD 0x7
Previous Update Revision REG_BINARY 0000000015000000
Platform Specific Field 1 REG_DWORD 0x10
-
You can just do this
@echo off
Set OSBits=64
IF %PROCESSOR_ARCHITECTURE%==x86 (
IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set OSBits=32
)
Echo Operating System is %OSBits% bit
-
Salmon, could you explain "IF NOT DEFINED" please. I searched and I cant really find anything on it. Thanks! Also I added Foxidives code to save to temp and it works well. Thanks for that code as well Foxidrive!!
@echo off
Color 2A
Set OSBits=64
del "%temp%\64bit.txt" 2>nul
IF %PROCESSOR_ARCHITECTURE%==x86 (
IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set OSBits=32
)
Echo Operating System is %OSBits% bit do >"%temp%\64bit.txt"
echo.
-
You can use an IF test to see if a variable is "defined", i.e. if it has been declared, either by a SET statement or by the system (like %username%, etc) The test is IF DEFINED variablename command. As with all IF tests you can test for the opposite (if it has NOT been defined) by inserting the word NOT after the IF keyword. That variable only exists in a 64 bit session on a 64 bit system. Thus if it is not defined we might not have a 64 bit system.
(You did know you can look all this kind of thing up on the web?) Type if defined batch into Google.
-
(You did know you can look all this kind of thing up on the web?) Type if defined batch into Google.
Yes I did a google search prior to asking. I think by searching the entire phrase gave me limited results. Thanks again!
Salmon, could you explain "IF NOT DEFINED" please. I searched and I cant really find anything on it.