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 14691 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?