• batch files and win 7

    Home » Forums » AskWoody support » Windows » Windows 7 » Questions: Windows 7 » batch files and win 7

    Author
    Topic
    #464015

    Hopefully this will help others. I have been going around in circles trying to get a simple copy.bat file to run in win 7, UAC is the culprit. I found a thread that said if you make a short-cut to the bat file and then run as administrator it will run OK. This is only half true, I have a copy.bat that just copies a db file to a backup drive if this is placed on the desktop it will not run, I tried it in docs (with a shortcut to the desktop and run as admin) and it still would not run, when I placed it in the same directory as the db file and then created a short-cut on the desktop with “run as administrator” it worked.

    Viewing 0 reply threads
    Author
    Replies
    • #1186362

      Hopefully this will help others. I have been going around in circles trying to get a simple copy.bat file to run in win 7, UAC is the culprit. I found a thread that said if you make a short-cut to the bat file and then run as administrator it will run OK. This is only half true, I have a copy.bat that just copies a db file to a backup drive if this is placed on the desktop it will not run, I tried it in docs (with a shortcut to the desktop and run as admin) and it still would not run, when I placed it in the same directory as the db file and then created a short-cut on the desktop with “run as administrator” it worked.

      I have a similar problem with a BAT file that I want to run from my Startup folder. This BAT file shares a drive that doesn’t exist at boot time. I have two problems with this.

        [*]The syntax IF EXIST D:NUL no longer seems to work, so I can’t check if the drive exists[*]I can run the shortcut manually (and accept the UAC warning) but it does nothing at all in the startup folder
      • #1186365

        I have a similar problem with a BAT file that I want to run from my Startup folder. This BAT file shares a drive that doesn’t exist at boot time. I have two problems with this.

          [*]The syntax IF EXIST D:NUL no longer seems to work, so I can’t check if the drive exists[*]I can run the shortcut manually (and accept the UAC warning) but it does nothing at all in the startup folder

        Hi Stuart, I just tried as an experiment my copy.bat file in the start up folder and it worked, I created a shortcut to my file copy.bat and placed it in C:usersgwsAppDataRoamingMicrosoftWindowsStartMenuPrograms gave it “Run as Administrator” rights and rebooted my computer and it created a copy in my backup folder. I dont know enough about Batch file scripting to help you with your script but I suspect others can. Good luck.gws.

        • #1186414

          Hi Stuart, I just tried as an experiment my copy.bat file in the start up folder and it worked, I created a shortcut to my file copy.bat and placed it in C:usersgwsAppDataRoamingMicrosoftWindowsStartMenuPrograms gave it “Run as Administrator” rights and rebooted my computer and it created a copy in my backup folder. I dont know enough about Batch file scripting to help you with your script but I suspect others can. Good luck.gws.

          Thanks for that.

          The folder in which I put a shortcut to my BAT file was c:Program DataMicrosoftWindowsStart MenuProgramsStartup
          I can run the program by clicking on the Start Menu and navigating to the shortcut, but it doesn’t run when I log in.

      • #1186439

        The syntax IF EXIST D:NUL no longer seems to work, so I can’t check if the drive exists

        That NUL check has always produced anomalous results in various versions of Windows, especially when used with short v. long filenames, path in quotes v. path without quotes, or (it is suggested) FAT32 files v. NTFS files.

        You could try

        Code:
        FSUTIL FSINFO DRIVETYPE x:

        which for an absent drive letter gives

        Code:
        x: - No such Root Directory

        but the errorlevel for all drive types comes out as zero… And you need to be an Administrator to run it!

        BATcher

        Plethora means a lot to me.

        • #1186441

          Stuart

          I’ve just tried

          Code:
          IF EXIST x:NUL ECHO x: EXISTS

          for both C: (boot drive) and Q: (non-mapped drive) in both XP and Windows 7, and got the expected results – you you may need to look further…

          I’m just investigating running BATch files “elevated” in Windows 7.

          BATcher

          Plethora means a lot to me.

          • #1186477

            Stuart

            I’ve just tried

            Code:
            IF EXIST x:NUL ECHO x: EXISTS

            for both C: (boot drive) and Q: (non-mapped drive) in both XP and Windows 7, and got the expected results – you you may need to look further…

            I’m just investigating running BATch files “elevated” in Windows 7.

            That is very helpful. Did you test it with a drive that doesn’t exist? My problem was that it always returned success even if the drive didn’t exist.

            • #1186478

              That is very helpful. Did you test it with a drive that doesn’t exist? My problem was that it always returned success even if the drive didn’t exist.

              I wasn’t sufficiently explicit – Q: doesn’t exists, not even as a mapped drive, on my PC!

              BATcher

              Plethora means a lot to me.

            • #1186481

              I wasn’t sufficiently explicit – Q: doesn’t exists, not even as a mapped drive, on my PC!

              Strange, the syntax I was using was

              IF EXIST V:NUL GOTO CREATED
              ECHO do something about it
              PAUSE
              :CREATED

              This is now working correctly, but I swear it was always going straight to the CREATED label when I tested it last week!

            • #1186529

              This is now working correctly, but I swear it was always going straight to the CREATED label when I tested it last week!

              Another computing mystery; I get them daily rather than weekly!

              BATcher

              Plethora means a lot to me.

    Viewing 0 reply threads
    Reply To: batch files and win 7

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: