tags:

views:

240

answers:

3

I am trying to write a batch file for my users to run from their Vista machines with UAC. The file is re-writing their hosts file, so it needs to be run with Administrator permissions. I need to be able to send them an email with a link to the .bat file. The desired behavior is that when they right-click on the file and say Open, they will get one of those UAC dialogs that makes the screen go dark and forces them to answer whether they want to give the application permission to run as administrator. Instead, they are just seeing "Access denied" on the command line window.

Is this possible to do differently?

+1  A: 

I don't think you can run a batch file as administrator from another being run as a normal user. If you could it would be an enormous security hole.

Why don't you tell you users to run the batch file you supply as administrator? It would be easier and would also tell your users that they were doing something to the machine configuration rather than hiding it away.

ChrisF
A: 

use the runas command. But, I don't think you can email a .bat file easily.

Josh
A: 

You can't request admin rights from a batch file, but you could write a windows scripting host script in %temp% and run that (and that in turn executes your batch as admin) You want to call the ShellExecute method in the Shell.Application object with "runas" as the verb

Anders