Run my exe as admin without prompt?

Windows specific forum
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Run my exe as admin without prompt?

Post by Dude »

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.
Last edited by Dude on Sun Dec 30, 2018 2:51 am, edited 2 times in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Run my exe as admin without prompt?

Post by RSBasic »

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.
Image
Image
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Run my exe as admin without prompt?

Post by forumuser »

I know it can be done with a batch file
If you mean that you create a task via schtasks from that .bat file?
Yeah, that's the correct way to do it
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

@Forumuser: Yes, the batch file looks like this:

Code: Select all

runas.exe /user:Limited-PC\Administrator /savecred Recuva.exe
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. :(
Last edited by Dude on Sun Dec 30, 2018 3:30 am, edited 4 times in total.
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Run my exe as admin without prompt?

Post by RSBasic »

That's a possibility, too.
If "save credentials" works, then it is the better solution.
Image
Image
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

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?
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Run my exe as admin without prompt?

Post by forumuser »

Again: Use schtasks to register your app as a task!
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Run my exe as admin without prompt?

Post by Michael Vogel »

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"
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

Michael Vogel wrote:wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
Thanks Michael, but that doesn't work. :(

@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. :shock: 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
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Run my exe as admin without prompt?

Post by firace »

@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
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

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. :shock:
firace
Addict
Addict
Posts: 899
Joined: Wed Nov 09, 2011 8:58 am

Re: Run my exe as admin without prompt?

Post by firace »

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. :shock:
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.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Run my exe as admin without prompt?

Post by skywalk »

Dude wrote:
Michael Vogel wrote:wmic /node:10.0.0.1 /user:Admin /password:SuperSecure process call create "C:\Program.exe"
Thanks Michael, but that doesn't work. :(
Can you explain? wmic should be available on most Windows PC's.

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
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Run my exe as admin without prompt?

Post by forumuser »

I tried to create a scheduled task but that fails too
And it fails because of what?
and also requires admin rights to create the task in the first place, so that's not really a viable solution.
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*
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Run my exe as admin without prompt?

Post by Dude »

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.
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. :(
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"
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.
forumuser wrote:And it fails because of what?
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. :(

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)
Post Reply