I have a batch file that renames a file in a folder using:

rename filename.exe filename.bac

This works good in Win XP. But in Vista/7, if the batch file is run under Program Files/ it does not rename the file unless I run it as administrator. Is there any way to bypass the UAC and use this without the need to run it as administrator?

thanks.

link|improve this question
feedback

migrated from stackoverflow.com Jul 3 '10 at 6:31

This question came from our site for professional and enthusiast programmers.

2 Answers

If you ever worked with linux you'll note that even when you are an administrator you don't get to do everything you want without elevation. The same concept applies to UAC. Even if you are logged in as an administrator, you run with standard user privileges by default. So no, you can't just make changes to system files (like the program files directory) - that's exactly what UAC is there to prevent.

You can disable uac if you really want to, but this is a potential security risk.

link|improve this answer
So, you're telling me that there's no way to run rename the file without having to run it under Administrator? – Anonymous Jul 1 '10 at 17:53
2  
It should be noted that disabling UAC is discouraged for kinda obvious reasons. – Joey Jul 1 '10 at 18:22
Yes, you have to run it as an administrator if you want to change things in program files. That's the point of UAC - it prevents non-administrators from making changes to program files. – nhinkle Dec 18 '10 at 0:36
feedback

Modifying folders and files in the program files directory requires elevation, even if you are logged in as an administrator. There are a few potential solutions to your problem:

  • Always elevate the batch file when you run it. If it is being used as a scheduled task, you can check the box for Run this task with highest privileges.

  • Use the Windows Vista/7 Elevation powertoy script to elevate just that command

  • Change the permissions in that specific subdirectory of program files to allow normal users to rename files

    To do this, go to the directory with the file you will be renaming. Right-click on the folder and click on Properties. Go to the security tab. Click advanced and then Change Permissions. Click Add and choose the account which will be running the batch file. Grant that account the necessary permissions - probably create files and delete files at a minimum. Then click OK however many times you need to dismiss all the dialogs. The specified account will now be able to modify files in that folder without needing to elevate.

  • Disable UAC. This is not recommended, as it leaves your system vulnerable

link|improve this answer
feedback

Your Answer

 
or
required, but never shown