Results 1 to 10 of 10
  1. #1
    2 Star Lounger
    Join Date
    Aug 2004
    Location
    Withyham, Sussex, England
    Posts
    121
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by gws View Post
    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.

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

  3. #3
    2 Star Lounger
    Join Date
    Aug 2004
    Location
    Withyham, Sussex, England
    Posts
    121
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by StuartR View Post
    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.

    1. The syntax IF EXIST D:\NUL no longer seems to work, so I can't check if the drive exists
    2. 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:\users\gws\AppData\Roaming\Microsoft\Windows\Sta rtMenu\Programs 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.

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by gws View Post
    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:\users\gws\AppData\Roaming\Microsoft\Windows\Sta rtMenu\Programs 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 Data\Microsoft\Windows\Start Menu\Programs\Startup
    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.

  5. #5
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,414
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Quote Originally Posted by StuartR View Post
    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

    Time prevents everything happening all at once...

  6. #6
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,414
    Thanks
    33
    Thanked 195 Times in 175 Posts
    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

    Time prevents everything happening all at once...

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by BATcher View Post
    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.

  8. #8
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,414
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Quote Originally Posted by StuartR View Post
    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

    Time prevents everything happening all at once...

  9. #9
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by BATcher View Post
    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!

  10. #10
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    3,414
    Thanks
    33
    Thanked 195 Times in 175 Posts
    Quote Originally Posted by StuartR View Post
    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

    Time prevents everything happening all at once...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •