How to RunProgram() as admin ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

How to RunProgram() as admin ?

Post by Psychophanta »

How can be run an external program in windows 7 as Administrator?
I am not able to see any parameter in RunProgram() function or any other thing to do it.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to RunProgram() as admin ?

Post by ts-soft »

You can't do this with RunProgram, only with API:
ShellExecute or ShellExecuteEx
Example:

Code: Select all

ShellExecute_(0, "RunAS", "notepad", "", "", #SW_SHOWNORMAL)
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: How to RunProgram() as admin ?

Post by Psychophanta »

Thanx!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Nituvious
Addict
Addict
Posts: 1027
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: How to RunProgram() as admin ?

Post by Nituvious »

How about setting the compiler options to request admin?
▓▓▓▓▓▒▒▒▒▒░░░░░
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: How to RunProgram() as admin ?

Post by LuCiFeR[SD] »

Nituvious wrote:How about setting the compiler options to request admin?
wouldn't work as he is trying to elevate an external programs permissions.
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: How to RunProgram() as admin ?

Post by Shield »

It will work because the administrator rights will be passed to the new process. :wink:
Best solution is to use API.
Image
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
tj1010
Enthusiast
Enthusiast
Posts: 716
Joined: Mon Feb 25, 2013 5:51 pm

Re: How to RunProgram() as admin ?

Post by tj1010 »

if login is wrong it wont run with this API,,, processes ran with PB command and non-auth API run as calling PID token

It's nice this way, the only way to bypass it is manual mapping with a driver or disabling UAC features. Even manual-mapping through ring3 and advanced dll injection won't bypass it because it's allocation and thread based, referenced in kernel tables.
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: How to RunProgram() as admin ?

Post by LuCiFeR[SD] »

Shield wrote:It will work because the administrator rights will be passed to the new process. :wink:
Best solution is to use API.
Actually I meant to write something along the lines of :

"Knowing Psychophanta, he wants to launch an elevated process from a button, so it wouldn't work"

but I wrote some nonsense instead :P
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: How to RunProgram() as admin ?

Post by ts-soft »

The really best way is this function:

Code: Select all

Procedure RunProgrammWithThePowerOfChuckNorris(ProgramName$, Parameters$ = "", WorkingDirectory$ = "")
  Protected shExecInfo.SHELLEXECUTEINFO
  
  With shExecInfo
    \cbSize = SizeOf(SHELLEXECUTEINFO)
    \lpVerb = @"runas"
    \lpParameters = @Parameters$
    \lpFile = @ProgramName$
    \lpDirectory = @WorkingDirectory$
    \nShow = #SW_NORMAL
  EndWith
  
  ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure

RunProgrammWithThePowerOfChuckNorris("notepad.exe") 
:twisted:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
LuCiFeR[SD]
666
666
Posts: 1033
Joined: Mon Sep 01, 2003 2:33 pm

Re: How to RunProgram() as admin ?

Post by LuCiFeR[SD] »

ts-soft wrote:The really best way is this function:

Code: Select all

Procedure RunProgrammWithThePowerOfChuckNorris(ProgramName$, Parameters$ = "", WorkingDirectory$ = "")
  Protected shExecInfo.SHELLEXECUTEINFO
  
  With shExecInfo
    \cbSize = SizeOf(SHELLEXECUTEINFO)
    \lpVerb = @"runas"
    \lpParameters = @Parameters$
    \lpFile = @ProgramName$
    \lpDirectory = @WorkingDirectory$
    \nShow = #SW_NORMAL
  EndWith
  
  ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure

RunProgrammWithThePowerOfChuckNorris("notepad.exe") 
:twisted:
ROFL :) /me loves ts-soft :P
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: How to RunProgram() as admin ?

Post by Psychophanta »

Nice ts-soft,

now how to send data to the notepad.exe to be written there?
The question is that i want to open cmd as admin and then write commands there sending data form other external process
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
tj1010
Enthusiast
Enthusiast
Posts: 716
Joined: Mon Feb 25, 2013 5:51 pm

Re: How to RunProgram() as admin ?

Post by tj1010 »

Both AttachThreadInput and CreatePipe are affected by security tokens.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: How to RunProgram() as admin ?

Post by Kwai chang caine »

RunProgrammWithThePowerOfChuckNorris()
:lol:
ImageThe happiness is a road...
Not a destination
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: How to RunProgram() as admin ?

Post by yrreti »

Cool one ts-soft, Cool one.
You made my day. :lol: :lol: :lol:
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: How to RunProgram() as admin ?

Post by Psychophanta »

ts-soft wrote:The really best way is this function:

Code: Select all

Procedure RunProgrammWithThePowerOfChuckNorris(ProgramName$, Parameters$ = "", WorkingDirectory$ = "")
  Protected shExecInfo.SHELLEXECUTEINFO
  
  With shExecInfo
    \cbSize = SizeOf(SHELLEXECUTEINFO)
    \lpVerb = @"runas"
    \lpParameters = @Parameters$
    \lpFile = @ProgramName$
    \lpDirectory = @WorkingDirectory$
    \nShow = #SW_NORMAL
  EndWith
  
  ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure

RunProgrammWithThePowerOfChuckNorris("notepad.exe") 
:twisted:
I does not work:

Code: Select all

Procedure RunProgrammWithThePowerOfChuckNorris(ProgramName$, Parameters$ = "", WorkingDirectory$ = "")
  Protected shExecInfo.SHELLEXECUTEINFO
  
  With shExecInfo
    \cbSize = SizeOf(SHELLEXECUTEINFO)
    \lpVerb = @"runas"
    \lpParameters = @Parameters$
    \lpFile = @ProgramName$
    \lpDirectory = @WorkingDirectory$
    \nShow = #SW_NORMAL
  EndWith
  
  ProcedureReturn ShellExecuteEx_(shExecInfo)
EndProcedure

RunProgrammWithThePowerOfChuckNorris("diskpart")
May be Norris is too old to Rock'n'Roll :|
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply