Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Find Drive letter for program files (86)  (Read 14468 times)

0 Members and 1 Guest are viewing this topic.

oxicottin

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    Find Drive letter for program files (86)
    « 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!

    Code: [Select]
    ::@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


    jeb_the_batcher



      Greenhorn

      • Experience: Expert
      • OS: Windows 7
      Re: Find Drive letter for program files (86)
      « Reply #1 on: February 07, 2013, 01:08:40 PM »
      It seems to be obvious.  ;)

      You see it in the output
      Quote
      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)%.

      Quote
      for /F "delims=" %%M in ("%ProgramFiles(x86)%") do set SysType=%%~dM
      echo %SysType%

      Salmon Trout

      • Guest
      Re: Find Drive letter for program files (86)
      « Reply #2 on: February 07, 2013, 01:58:08 PM »
      That screen grab is making my eyes bleed.

      Salmon Trout

      • Guest
      Re: Find Drive letter for program files (86)
      « Reply #3 on: February 07, 2013, 02:13:17 PM »
      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.
       

      oxicottin

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows 7
        Re: Find Drive letter for program files (86)
        « Reply #4 on: February 08, 2013, 07:57:43 AM »
        Will it work for 32bit as well? I have a 64bit so I cant test it.

        oxicottin

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Windows 7
          Re: Find Drive letter for program files (86)
          « Reply #5 on: February 08, 2013, 08:07:10 AM »
          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

          Code: [Select]
          @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



          Lemonilla



            Apprentice

          • "Too sweet"
          • Thanked: 70
          • Computer: Specs
          • Experience: Experienced
          • OS: Windows 7
          Re: Find Drive letter for program files (86)
          « Reply #6 on: February 08, 2013, 09:12:25 AM »
          Code: [Select]
          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)".
          Quote from: patio
          God Bless the DOS Helpers...
          Quote
          If it compiles, send the files.

          oxicottin

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Windows 7
            Re: Find Drive letter for program files (86)
            « Reply #7 on: February 08, 2013, 12:52:16 PM »
            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
            Code: [Select]
            >>SysOS.txt
            Code: [Select]
            @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

            Salmon Trout

            • Guest
            Re: Find Drive letter for program files (86)
            « Reply #8 on: February 08, 2013, 01:54:11 PM »

            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.



            oxicottin

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows 7
              Re: Find Drive letter for program files (86)
              « Reply #9 on: February 08, 2013, 02:00:21 PM »
              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!

              Salmon Trout

              • Guest
              Re: Find Drive letter for program files (86)
              « Reply #10 on: February 08, 2013, 02:01:57 PM »
              Why do you want to create a text file?

              oxicottin

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Windows 7
                Re: Find Drive letter for program files (86)
                « Reply #11 on: February 08, 2013, 02:15:19 PM »
                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.

                Salmon Trout

                • Guest
                Re: Find Drive letter for program files (86)
                « Reply #12 on: February 08, 2013, 02:57:59 PM »
                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?

                oxicottin

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: Find Drive letter for program files (86)
                  « Reply #13 on: February 08, 2013, 03:08:36 PM »
                  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!!!

                  Salmon Trout

                  • Guest
                  Re: Find Drive letter for program files (86)
                  « Reply #14 on: February 08, 2013, 04:44:20 PM »
                  Where do you think a batch on a CD is going to write a file to?

                  Salmon Trout

                  • Guest
                  Re: Find Drive letter for program files (86)
                  « Reply #15 on: February 08, 2013, 04:49:45 PM »
                  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).

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: Find Drive letter for program files (86)
                  « Reply #16 on: February 08, 2013, 08:48:18 PM »
                  Writing to "%temp%" is always an option.

                  Here's a method from stackoverflow.

                  Code: [Select]
                  @echo off
                  if defined ProgramFiles(x86) (
                  @echo yes
                  @echo Some 64-bit work
                  ) else (
                  @echo no
                  @echo Some 32-bit work
                  )

                  foxidrive



                    Specialist
                  • Thanked: 268
                  • Experience: Experienced
                  • OS: Windows 8
                  Re: Find Drive letter for program files (86)
                  « Reply #17 on: February 08, 2013, 09:02:14 PM »
                  The thread title says you want the drive letter, so this should work.

                  Code: [Select]
                  @echo off
                  if defined ProgramFiles(x86) (
                  for %%a in ("%ProgramFiles(x86)%") do echo the drive letter is %%~da
                  ) else (
                  echo not 64 bit
                  )

                  oxicottin

                    Topic Starter


                    Rookie

                    • Experience: Beginner
                    • OS: Windows 7
                    Re: Find Drive letter for program files (86)
                    « Reply #18 on: February 09, 2013, 10:16:54 PM »
                    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!

                    Code: [Select]
                    @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

                    Salmon Trout

                    • Guest
                    Re: Find Drive letter for program files (86)
                    « Reply #19 on: February 10, 2013, 12:35:26 AM »
                    Quote
                    \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.


                    foxidrive



                      Specialist
                    • Thanked: 268
                    • Experience: Experienced
                    • OS: Windows 8
                    Re: Find Drive letter for program files (86)
                    « Reply #20 on: February 10, 2013, 01:54:50 AM »
                    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:

                    Code: [Select]
                    @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.

                    Salmon Trout

                    • Guest
                    Re: Find Drive letter for program files (86)
                    « Reply #21 on: February 10, 2013, 02:08:39 AM »
                    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


                    « Last Edit: February 10, 2013, 02:19:36 AM by Salmon Trout »

                    Salmon Trout

                    • Guest
                    Re: Find Drive letter for program files (86)
                    « Reply #22 on: February 10, 2013, 02:48:33 AM »
                    ..

                    Salmon Trout

                    • Guest
                    Re: Find Drive letter for program files (86)
                    « Reply #23 on: February 10, 2013, 03:26:00 AM »
                    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)

                    oxicottin

                      Topic Starter


                      Rookie

                      • Experience: Beginner
                      • OS: Windows 7
                      Re: Find Drive letter for program files (86)
                      « Reply #24 on: February 10, 2013, 06:53:30 AM »
                       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:

                      Code: [Select]
                      @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:




                      Thanks... foxidrive & Salmon Trout

                      Salmon Trout

                      • Guest
                      Re: Find Drive letter for program files (86)
                      « Reply #25 on: February 10, 2013, 07:00:31 AM »
                      What you copied was not batch code, it's pseudocode to describe the logic.


                      oxicottin

                        Topic Starter


                        Rookie

                        • Experience: Beginner
                        • OS: Windows 7
                        Re: Find Drive letter for program files (86)
                        « Reply #26 on: February 10, 2013, 08:39:10 AM »
                        Lol that would explain it then....

                        Salmon Trout

                        • Guest
                        Re: Find Drive letter for program files (86)
                        « Reply #27 on: February 10, 2013, 09:02:10 AM »
                        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.



                        oxicottin

                          Topic Starter


                          Rookie

                          • Experience: Beginner
                          • OS: Windows 7
                          Re: Find Drive letter for program files (86)
                          « Reply #28 on: February 10, 2013, 09:20:35 AM »
                          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:

                          Code: [Select]
                          @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...


                          Salmon Trout

                          • Guest
                          Re: Find Drive letter for program files (86)
                          « Reply #29 on: February 10, 2013, 12:39:31 PM »
                          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



                          oxicottin

                            Topic Starter


                            Rookie

                            • Experience: Beginner
                            • OS: Windows 7
                            Re: Find Drive letter for program files (86)
                            « Reply #30 on: February 10, 2013, 01:07:46 PM »
                            So this would give me a better ida then...

                            Code: [Select]
                            @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


                            Quote
                            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

                            Salmon Trout

                            • Guest
                            Re: Find Drive letter for program files (86)
                            « Reply #31 on: February 10, 2013, 01:43:01 PM »
                            You can just do this

                            Code: [Select]
                            @echo off
                            Set OSBits=64
                            IF %PROCESSOR_ARCHITECTURE%==x86 (
                              IF NOT DEFINED PROCESSOR_ARCHITEW6432 Set OSBits=32
                              )
                            Echo Operating System is %OSBits% bit


                            oxicottin

                              Topic Starter


                              Rookie

                              • Experience: Beginner
                              • OS: Windows 7
                              Re: Find Drive letter for program files (86)
                              « Reply #32 on: February 10, 2013, 05:05:31 PM »
                              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!!

                              Code: [Select]
                              @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.

                              Salmon Trout

                              • Guest
                              Re: Find Drive letter for program files (86)
                              « Reply #33 on: February 11, 2013, 03:47:14 AM »
                              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.

                              oxicottin

                                Topic Starter


                                Rookie

                                • Experience: Beginner
                                • OS: Windows 7
                                Re: Find Drive letter for program files (86)
                                « Reply #34 on: February 11, 2013, 06:11:06 AM »
                                (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!

                                Quote
                                Salmon, could you explain "IF NOT DEFINED" please. I searched and I cant really find anything on it.