How to RunProgram() as admin ?
- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
How to RunProgram() as admin ?
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.
I am not able to see any parameter in RunProgram() function or any other thing to do it.
Re: How to RunProgram() as admin ?
You can't do this with RunProgram, only with API:
ShellExecute or ShellExecuteEx
Example:
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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: How to RunProgram() as admin ?
How about setting the compiler options to request admin?
▓▓▓▓▓▒▒▒▒▒░░░░░
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: How to RunProgram() as admin ?
wouldn't work as he is trying to elevate an external programs permissions.Nituvious wrote:How about setting the compiler options to request admin?
Re: How to RunProgram() as admin ?
It will work because the administrator rights will be passed to the new process.
Best solution is to use API.

Best solution is to use API.
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
Re: How to RunProgram() as admin ?
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.
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.
-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: How to RunProgram() as admin ?
Actually I meant to write something along the lines of :Shield wrote:It will work because the administrator rights will be passed to the new process.![]()
Best solution is to use API.
"Knowing Psychophanta, he wants to launch an elevated process from a button, so it wouldn't work"
but I wrote some nonsense instead

Re: How to RunProgram() as admin ?
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")

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.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

-
- 666
- Posts: 1033
- Joined: Mon Sep 01, 2003 2:33 pm
Re: How to RunProgram() as admin ?
ROFLts-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")


- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: How to RunProgram() as admin ?
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
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 ?
Both AttachThreadInput and CreatePipe are affected by security tokens.
- Kwai chang caine
- Always Here
- Posts: 5494
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
Re: How to RunProgram() as admin ?
RunProgrammWithThePowerOfChuckNorris()


Not a destination
Re: How to RunProgram() as admin ?
Cool one ts-soft, Cool one.
You made my day.

You made my day.



- Psychophanta
- Always Here
- Posts: 5153
- Joined: Wed Jun 11, 2003 9:33 pm
- Location: Anare
- Contact:
Re: How to RunProgram() as admin ?
I does not work: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")
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")
