Page 1 of 2

How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 11:36 am
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.

Re: How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 12:03 pm
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)

Re: How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 8:50 pm
by Psychophanta
Thanx!

Re: How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 10:57 pm
by Nituvious
How about setting the compiler options to request admin?

Re: How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 11:25 pm
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.

Re: How to RunProgram() as admin ?

Posted: Sun Apr 07, 2013 11:59 pm
by Shield
It will work because the administrator rights will be passed to the new process. :wink:
Best solution is to use API.

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 1:09 am
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.

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 2:07 pm
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

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 3:03 pm
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:

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 7:27 pm
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

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 7:50 pm
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

Re: How to RunProgram() as admin ?

Posted: Mon Apr 08, 2013 9:26 pm
by tj1010
Both AttachThreadInput and CreatePipe are affected by security tokens.

Re: How to RunProgram() as admin ?

Posted: Tue Apr 09, 2013 10:35 am
by Kwai chang caine
RunProgrammWithThePowerOfChuckNorris()
:lol:

Re: How to RunProgram() as admin ?

Posted: Tue Apr 09, 2013 3:54 pm
by yrreti
Cool one ts-soft, Cool one.
You made my day. :lol: :lol: :lol:

Re: How to RunProgram() as admin ?

Posted: Fri May 17, 2013 4:51 pm
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 :|