Run my exe as admin without prompt?
Run my exe as admin without prompt?
On Microsoft Windows, how can a user run my exe as an admin, when logged in as a standard user, without getting the UAC prompt every time? And when the PC boots up with my app, the UAC prompt appears for it, which is stupid because the user will be expecting my app to be running after they've made their morning coffee.
I know it can be done with a batch file (I do it that way for "Recuva" by Piriform), but is that the right way to do this? Or do I make a "helper exe" that launches the main exe with admin rights?
Thanks for any advice.
I know it can be done with a batch file (I do it that way for "Recuva" by Piriform), but is that the right way to do this? Or do I make a "helper exe" that launches the main exe with admin rights?
Thanks for any advice.
Last edited by Dude on Sun Dec 30, 2018 2:51 am, edited 2 times in total.
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: Run my exe as admin without prompt?
It is always with prompt.
But you can register your application as a Windows service, then you always have administrators and system rights without prompt.
UAC is only necessary once when creating the Windows service.
But you can register your application as a Windows service, then you always have administrators and system rights without prompt.
UAC is only necessary once when creating the Windows service.
Re: Run my exe as admin without prompt?
If you mean that you create a task via schtasks from that .bat file?I know it can be done with a batch file
Yeah, that's the correct way to do it
Re: Run my exe as admin without prompt?
@Forumuser: Yes, the batch file looks like this:
So the first time I ran that batch file, it asked for my admin name and password, then it remembers it ("save credentials"). Now I just double-click that shortcut to run Recuva without ever getting the annoying UAC prompt.
[Edit] So, I just tried this with my PureBasic exe and it works. Nope, see new post below.
Code: Select all
runas.exe /user:Limited-PC\Administrator /savecred Recuva.exe
[Edit] So, I just tried this with my PureBasic exe and it works. Nope, see new post below.
Last edited by Dude on Sun Dec 30, 2018 3:30 am, edited 4 times in total.
- RSBasic
- Moderator
- Posts: 1218
- Joined: Thu Dec 31, 2009 11:05 pm
- Location: Gernsbach (Germany)
- Contact:
Re: Run my exe as admin without prompt?
That's a possibility, too.
If "save credentials" works, then it is the better solution.
If "save credentials" works, then it is the better solution.
Re: Run my exe as admin without prompt?
Using a batch file is NOT the solution after all, as it no longer works. How do other people make their exes run with admin rights? Does the user have to be logged in as admin all the time? Or are they just accepting the UAC prompt for the app every time their PC boots for the day?
Re: Run my exe as admin without prompt?
Again: Use schtasks to register your app as a task!
- Michael Vogel
- Addict
- Posts: 2680
- Joined: Thu Feb 09, 2006 11:27 pm
- Contact:
Re: Run my exe as admin without prompt?
Hm, if you want to run a program without needing to do interaction you have some chances to do this using WMIC (if enabled on your PC):
wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
Re: Run my exe as admin without prompt?
Thanks Michael, but that doesn't work.Michael Vogel wrote:wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
@forumuser, I tried to create a scheduled task but that fails too, and also requires admin rights to create the task in the first place, so that's not really a viable solution.
From what I've read online, "runas" doesn't allow credentials to be saved anymore for security reasons. Apparently you'll always need to physically enter the admin password at some point now.
So the best I could manage was a VBS script I found to run my exe in elevated mode and prompt the user for the admin password. This has two benefits: the user can choose to run my exe alone to use it with limited rights, or run it from the VBS script to use it with admin rights. (If I set "Request administrator" in compiler options, then the user doesn't get a choice on how to launch it).
The VBS code I found was as simple as this (saved as "MyApp.vbs"):
Code: Select all
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "MyApp.exe", , , "runas", 1
Re: Run my exe as admin without prompt?
@Dude - not sure if I fully understood your issue, but you may want to give ElevateAs a try:
https://www.trustprobe.com/fs1/apps.html
https://www.trustprobe.com/fs1/apps.html
Re: Run my exe as admin without prompt?
Nope, ElevateAs played havoc with my PC and I had to reboot. It was like it was locked in an infinite loop trying to run my exe. Couldn't even kill it in the Task Manager because it kept restarting itself with a different process ID.
Re: Run my exe as admin without prompt?
Hmm that's rather weird. I've been using it for a while, without any trouble.Dude wrote:Nope, ElevateAs played havoc with my PC and I had to reboot. It was like it was locked in an infinite loop trying to run my exe. Couldn't even kill it in the Task Manager because it kept restarting itself with a different process ID.
It does trigger a UAC prompt, but at least you can pass the password on the command line.
Re: Run my exe as admin without prompt?
Can you explain? wmic should be available on most Windows PC's.Dude wrote:Thanks Michael, but that doesn't work.Michael Vogel wrote:wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
Code: Select all
wmic /node:localhost /user:Admin /password:xyz process process call create "C:\Program.exe"
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Run my exe as admin without prompt?
And it fails because of what?I tried to create a scheduled task but that fails too
Em, what? It is a viable solution to let the user enter the password on each single start of the .exe (which is a tedious process) but not just a single time to create the task? *baffled*and also requires admin rights to create the task in the first place, so that's not really a viable solution.
Re: Run my exe as admin without prompt?
It never gave me a UAC prompt, and my PC's mouse pointer became the "wait" circle that kept flickering on/off very fast. My exe didn't launch. Checked Task Manager, and "Elevateas.exe" kept disappearing and reappearing with a new PID. Because my mouse was hosed, I had to reboot as I couldn't click on anything.firace wrote:Hmm that's rather weird. I've been using it for a while, without any trouble.
It does trigger a UAC prompt, but at least you can pass the password on the command line.
Tried the above from a batch file and my exe doesn't launch at all. A command box appears for a moment and then closes. Used the right user/pass combo for it.skywalk wrote:Can you explain? wmic should be available on most Windows PC's.Code: Select all
wmic /node:localhost /user:Admin /password:xyz process call create "C:\Program.exe"
The scheduled task gets created, and my exe is (apparently) run with admin rights at logon, but it seems to run "silently" in that no window is displayed, it doesn't respond to its hotkeys, its system tray icon doesn't appear, etc. I can see it in the Task Manager and the user name is the LIMITED user name instead of ADMIN user name, and it says "Enabled" for UAC virtualization; however despite all this I can't actually use it.forumuser wrote:And it fails because of what?
Here's what I used to add it; maybe you can spot the problem, or provide a working alternative?
Code: Select all
; This procedure MUST be run with admin rights to work!
Procedure RunAtLogin(taskname$,exe$,username$="",password$="",elevated=0)
p$="/Create /TN "+Chr(34)+taskname$+Chr(34)+" /SC ONLOGON /TR "+exe$+" /RU "+username$+" /RP "+password$
If elevated=1
p$+" /RL HIGHEST"
EndIf
ok=RunProgram("schtasks.exe",p$,"",#PB_Program_Hide)
ProcedureReturn ok
EndProcedure
Debug RunAtLogin("Run exe at login","c:\path\to\myapp.exe","admin-name","admin-password",1)