hemichallenger Posted October 6, 2015 Posted October 6, 2015 Hello everyone,Question: When adding #RequireAdmin within the script. It runs everything in the script with administrator rights. That's good because there are some functions i like to run with administrator rights. But I'm curious if it possible If within the script i had a option to open IE or Firefox for example. I don't want that to open with administrator rights. Is it possible when you select to open IE or Firefox, it opens that in a standard user?V/r
trancexx Posted October 6, 2015 Posted October 6, 2015 Yes. See example for _Security__CreateProcessWithToken() inside the help file. ♡♡♡ . eMyvnE
hemichallenger Posted October 6, 2015 Author Posted October 6, 2015 Not sure how this function works. Can you provide and example with CMD.exe?expandcollapse popup#RequireAdmin ; for this example to have sense #include <ProcessConstants.au3> #include <Security.au3> #include <SecurityConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> Example_ProcessWithTok() Func Example_ProcessWithTok() ; Run AutoIt non-elevated regardless of having full administrator rights obtained using #RequireAdmin or by any other means _RunNonElevated(ShellExecute ("C:\Windows\System32\cmd.exe")) EndFunc Func _RunNonElevated($sCommandLine = "") If Not IsAdmin() Then Return Run($sCommandLine) ; if current process is run non-elevated then just Run new one. ; Structures needed for creating process Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO) Local $tPROCESS_INFORMATION = DllStructCreate($tagPROCESS_INFORMATION) ; Process handle of some process that's run non-elevated. For example "Explorer" Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, 0, ProcessExists("explorer.exe")) ; If successful If $hProcess Then ; Token... Local $hTokOriginal = _Security__OpenProcessToken($hProcess, $TOKEN_ALL_ACCESS) ; Process handle is no longer needed. Close it _WinAPI_CloseHandle($hProcess) ; If successful If $hTokOriginal Then ; Duplicate the original token Local $hTokDuplicate = _Security__DuplicateTokenEx($hTokOriginal, $TOKEN_ALL_ACCESS, $SECURITYIMPERSONATION, $TOKENPRIMARY) ; Close the original token _WinAPI_CloseHandle($hTokOriginal) ; If successful If $hTokDuplicate Then ; Create process with this new token _Security__CreateProcessWithToken($hTokDuplicate, 0, $sCommandLine, 0, @ScriptDir, $tSTARTUPINFO, $tPROCESS_INFORMATION) ; Close that token _WinAPI_CloseHandle($hTokDuplicate) ; Close get handles _WinAPI_CloseHandle(DllStructGetData($tPROCESS_INFORMATION, "hProcess")) _WinAPI_CloseHandle(DllStructGetData($tPROCESS_INFORMATION, "hThread")) ; Return PID of newly created process Return DllStructGetData($tPROCESS_INFORMATION, "ProcessID") EndIf EndIf EndIf EndFunc ;==>_RunNonElevated
hemichallenger Posted October 7, 2015 Author Posted October 7, 2015 Thank you. This function is still new to me. How do you use it with IE to go to a specific link?$URL = ("https://www.youtube.com/watch?v=BLU60CD-Poo") _RunNonElevated('C:\Program Files (x86)\Internet Explorer\iexplore.exe') ; This is how I use to open explore to a specific link. Doesn't work with _RunNonElevated $URL = ("https://www.youtube.com/watch?v=BLU60CD-Poo") ShellExecute ("C:\Program Files\Internet Explorer\iexplore.exe", $URL)
trancexx Posted October 7, 2015 Posted October 7, 2015 $sURL = "https://www.nsa.gov/" _RunNonElevated(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $sURL) Radiance and hemichallenger 2 ♡♡♡ . eMyvnE
hemichallenger Posted October 7, 2015 Author Posted October 7, 2015 (edited) Thank you. It worked on my standalone machine I was using for testing. Unfortunately it doesn't work on my domain computer which uses CAC authentication. Edited October 7, 2015 by hemichallenger
hemichallenger Posted October 9, 2015 Author Posted October 9, 2015 Instead of opening IE with _RunNonElevated. If IE is already open, how do I change to the URL i want? And if IE isn't open Msgbox a message please open IE before running.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now