# PureBasic Forum

 It is currently Sat Feb 16, 2019 10:41 am

 All times are UTC + 1 hour

 Page 1 of 2 [ 23 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Run my exe as admin without prompt?Posted: Wed May 23, 2018 8:49 am

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
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.

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Wed May 23, 2018 9:16 am
 Moderator

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 722
Location: Berlin and Ibiza
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.

_________________

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Wed May 23, 2018 9:36 am
 User

Joined: Wed Apr 18, 2018 8:24 am
Posts: 68
Quote:
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

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Wed May 23, 2018 10:18 am

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
@Forumuser: Yes, the batch file looks like this:

Code:
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.

 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.

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Wed May 23, 2018 10:24 am
 Moderator

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 722
Location: Berlin and Ibiza
That's a possibility, too.
If "save credentials" works, then it is the better solution.

_________________

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 3:31 am

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
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?

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 7:45 am
 User

Joined: Wed Apr 18, 2018 8:24 am
Posts: 68
Again: Use schtasks to register your app as a task!

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 10:38 am

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 2372
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"

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 12:34 pm

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
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. 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:
Set oShell = CreateObject("Shell.Application")
oShell.ShellExecute "MyApp.exe", , , "runas", 1

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 1:04 pm
 Enthusiast

Joined: Wed Nov 09, 2011 8:58 am
Posts: 404
@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

_________________
I'm the eternal noob.

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 1:30 pm

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
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.

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 2:35 pm
 Enthusiast

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

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.

_________________
I'm the eternal noob.

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 6:26 pm

Joined: Wed Dec 23, 2009 10:14 pm
Posts: 2828
Location: Boston, MA
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:
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

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Sun Dec 30, 2018 11:25 pm
 User

Joined: Wed Apr 18, 2018 8:24 am
Posts: 68
Quote:
I tried to create a scheduled task but that fails too

And it fails because of what?

Quote:
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*

Top

 Post subject: Re: Run my exe as admin without prompt?Posted: Mon Dec 31, 2018 2:55 am

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1774
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:
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:
; 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
ProcedureReturn ok
EndProcedure

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 2 [ 23 posts ] Go to page 1, 2  Next

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 5 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forum

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite