RunAs - built-in
RunAs - built-in
G'day folks.
I have been using RunAs, the function in Droopy's library, for quite a while. Until mow it has served me quite well; however, I now find it limiting.
I need to be able to find out when the executed problem has closed, and get return codes. I have been using GetPIDProcess on the executed file, and waiting until the name can no longer be found in memory, but this has obvious drawbacks.
It does not have exactly the same functions as RunProgram, more specifically the #PB_Program_Hide and #PB_Program_Open. If possible, I'd love to have an inbuilt function added to the RunProgram switches, with the ability to run under a certain user account.
If I have missed an already existent function, please let me know.
Cheers
I have been using RunAs, the function in Droopy's library, for quite a while. Until mow it has served me quite well; however, I now find it limiting.
I need to be able to find out when the executed problem has closed, and get return codes. I have been using GetPIDProcess on the executed file, and waiting until the name can no longer be found in memory, but this has obvious drawbacks.
It does not have exactly the same functions as RunProgram, more specifically the #PB_Program_Hide and #PB_Program_Open. If possible, I'd love to have an inbuilt function added to the RunProgram switches, with the ability to run under a certain user account.
If I have missed an already existent function, please let me know.
Cheers
Re: RunAs - built-in
Maybe some functions posted in this thread will help you?!
-> http://www.purebasic.fr/english/viewtop ... 13&t=41952
-> http://www.purebasic.fr/english/viewtop ... 13&t=41952
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Re: RunAs - built-in
Everything you asked for can already be done. Look at the manual in the section "Process".
Re: RunAs - built-in
Looked, but I can't find that function mate... what version did it get introduced in? Using v1.32 (15/12/2009).Droopy wrote:SuperRunas() from the DroopyLib do this
Uh, I've looked and can't find anything that would allow me to run an app under a different user account... any pointers?Trond wrote:Everything you asked for can already be done. Look at the manual in the section "Process".
Cheers
Re: RunAs - built-in
Oups, I didn't see that, sorry. You can do that with API, but I'm not sure how you want to handle passwords.ctg wrote:Uh, I've looked and can't find anything that would allow me to run an app under a different user account... any pointers?Trond wrote:Everything you asked for can already be done. Look at the manual in the section "Process".
Cheers
Re: RunAs - built-in
I don't mind throwing the password in a parameter, launched by the compiled exe.Trond wrote:Oups, I didn't see that, sorry. You can do that with API, but I'm not sure how you want to handle passwords.ctg wrote:Uh, I've looked and can't find anything that would allow me to run an app under a different user account... any pointers?Trond wrote:Everything you asked for can already be done. Look at the manual in the section "Process".
Cheers
Can this please be added natively into PureBasic? AutoIT has it but I don't want to have to include the dll with any app I create that needs this function...
Re: RunAs - built-in
It's not as elegant as it would be native, but it seems to work:
I don't know how to read/write to the process though.
Code: Select all
Prototype PCPWLW(A, B, C, D, E, F, G, H, I, J, K)
Advapi = OpenLibrary(#PB_Any, "advapi32.dll")
Global CreateProcessWithLogonW.PCPWLW = GetFunction(Advapi, "CreateProcessWithLogonW")
#LOGON_WITH_PROFILE = 1
Procedure RunAs(Program.s, User.s, Password.s)
pi.PROCESS_INFORMATION
Ok = CreateProcessWithLogonW(@User, 0, @Password, #LOGON_WITH_PROFILE, 0, @Program, 0, 0, 0, 0, @pi)
CloseHandle_(pi\hProcess)
CloseHandle_(pi\hThread)
ProcedureReturn Ok
EndProcedure
RunAs("notepad.exe", "testuser", "password")
Re: RunAs - built-in
Thanks mate... I also need to wait until the app is closed too, so I need to get an app handle...
Cheers.
Cheers.
Re: RunAs - built-in
The handle you're looking for is probably pi\hProcess.
Re: RunAs - built-in
Trond's simple and easy code above no longer works for me. It used to! But now this just returns 0 (failure):
Why would this suddenly stop working after all these years? One of my apps uses it and now it's failing.
Code: Select all
Debug RunAs("C:\Windows\RegEdit.exe",admin$,password$) ; Opens RegEdit with admin rights.
Re: RunAs - built-in
Perhaps OS Bug.
Windows 7 is work, but not on windows 10...
Link: https://answers.microsoft.com/en-us/win ... 3933571bcb
Attention. The KB4462933 also has errors again...
Windows 7 is work, but not on windows 10...
Link: https://answers.microsoft.com/en-us/win ... 3933571bcb
Attention. The KB4462933 also has errors again...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: RunAs - built-in
I only use Windows 7, and it used to work with 7, but not anymore. Doesn't open RegEdit with admin rights here.
Re: RunAs - built-in
Same on my machine.
Program stopped because UAC Requester not visible.
Program stopped because UAC Requester not visible.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: RunAs - built-in
After some testing, I've come to the conclusion that this is actually not an issue.
As mk-soft said, it's failing because UAC is not being accepted. Confirmed by Shift+RightClicking RegEdit and selecting "Run as different user" (not "Run as administrator"). Then I get a prompt for the user name and password, just like the code above does. But then, the UAC prompt also appears, which stops everything dead.
I note with interest, however, that I can still use the code to run other "safe" apps as a different user, such as Notepad. These will appear with the different user name in Task Manager for the process. So maybe just "critical" apps that need UAC (like RegEdit) can't use it anymore.
So, all good.
As mk-soft said, it's failing because UAC is not being accepted. Confirmed by Shift+RightClicking RegEdit and selecting "Run as different user" (not "Run as administrator"). Then I get a prompt for the user name and password, just like the code above does. But then, the UAC prompt also appears, which stops everything dead.
I note with interest, however, that I can still use the code to run other "safe" apps as a different user, such as Notepad. These will appear with the different user name in Task Manager for the process. So maybe just "critical" apps that need UAC (like RegEdit) can't use it anymore.
So, all good.