last day (14 days later) » 

10:27 AM
0
Q: How to run batch file as an elevated user?

cascading-styleI have a batch file that creates another user using this code: net user /add TheAccount passWORD net localgroup administrators TheAccount /add And I did this so that my program would later run commands elevated without the UAC popping up, because it could use its own account... But I hit a r...

 
@SomethingDark That is not at all what I'm looking for. As I said in my question, I DON'T want the UAC prompt to show up at all after the account above is created. The code I included above is from the installer. It creates the account TheAccount as an admin, and I need to execute a program later, as an admin. I have that account set up in the hopes of using that to run my program later without the UAC prompt.
 
Oh. In that case, that's impossible. Imagine if all you needed to do to run a program as administrator was put a little string of code in front of it. Every bit of malware in the world could do whatever they want to your system. It would be a massive security hole.
 
@SomethingDark That's also not what I was saying. My original setup program gets the UAC prompt, and after the setup program gets elevation, it creates an elevated user account, and remembers the password... If I have an administrator account and know the password I should be able to execute a program later, without a UAC.
 
Yeah, if you're logged in as that account and run the script from there, sure. But if you're not running as that use you should absolutely not be able to run a script a user who has a password without entering that password.
 
10:27 AM
@SomethingDark I get that, my setup program requests with UAC, but after it gets UAC admin once, it creates an account with net user /add TheAccount passWORD && net localgroup administrators TheAccount /add. That creates an Administrator account. And I need to execute a program later knowing that there is an admin account the setup created with the username TheAccount and the password passWORD... So I do know the password.
 
NirCmd might help.
 
Only thing I could possibly imagine would be creating the account and then use it in the Task Scheduler... @ender_scythe Questions asks for a solution without third-party tools
 
Well I'm sorry that it's virtually impossible with "vanilla" Batch.
 
Look at Firefox Updater. You need a similar mechanism.
 
@DmitrySokolov I agree, but, how do I make a program like that?
 
10:27 AM
Try RunAsService. Sorry, it's third-party.
You just need a simple Windows Service that will run a .cmd. But don't make it accessible for other users, for security reasons.
 
Upon further investigation, this may be relevant.
 
@SomethingDark can you write an answer using that method? With some code, please?
 
I mean the entire code is literally just set __COMPAT_LAYER=RunAsAdmin, but if it solved your problem, sure.
 
@SomethingDark where do I put that line?
 
Anywhere above the line where you call the program.
 
10:27 AM
@SomethingDark so set __COMPAT_LAYER=RunAsAdmin [crlf] myprogram.exe?
 
Yeah, that should work.
 
user6017774
If you don't mind an invisible program then schedule it in Task Scheduler and set the security on the task to allow whoever to run it.
 
@Noodles I kind of need it to be visible...
 
user6017774
Well if you can elevate without actually having too Viruses will do the same.
 
10:27 AM
@noodles I have a setup program that gets the UAC, and the admin setup program creates a new account with admin privileges. I also have a program that doesn't request UAC because it uses the admin account previously created by the setup program.
@DmitrySokolov yes I need something like Firefox Updater.
any help would be appreciated.
 

last day (14 days later) »