hello friends!
is there anyway Run .exe as the user instead of administrator when i opened my AHK as admin?
Thank you very much!
run exe as user (AHK is opened as Admin)
Re: run exe as user (AHK is opened as Admin)
Hallo,
This is meant to be integrated into your main script.
Function: The main script is first started as User.
It deletes sub-script Run.ahk, rewrites it, integrates its own full path, starts it (hidden) as User and then makes itself Admin via restart.
Finally, when the main script runs as admin, its Run(target) function serves as an instruction to the UserScript Run.ahk to start the target.
To transfer the contents of the Target variable to Run.ahk, Run(Target) uses the clipboard.
With line: q::Run("Notepad.exe") Hotkey Q becomes the instruction: "Start Notepad.exe as User".
When the main script is closed, Run.ahk closes itself.
This is meant to be integrated into your main script.
Function: The main script is first started as User.
It deletes sub-script Run.ahk, rewrites it, integrates its own full path, starts it (hidden) as User and then makes itself Admin via restart.
Finally, when the main script runs as admin, its Run(target) function serves as an instruction to the UserScript Run.ahk to start the target.
To transfer the contents of the Target variable to Run.ahk, Run(Target) uses the clipboard.
With line: q::Run("Notepad.exe") Hotkey Q becomes the instruction: "Start Notepad.exe as User".
When the main script is closed, Run.ahk closes itself.
Code: Select all
#SingleInstance, Force
If !A_IsAdmin
{
DetectHiddenWindows On
WinGetTitle, Title, ahk_id %A_ScriptHwnd%
FileDelete, Run.ahk
FileAppend,
( LTrim
#SingleInstance, Force
#NoTrayIcon ; (hidden)
DetectHiddenWindows On
WinWaitClose,`% Title := "%Title%"
WinWait,`% Title ;Admin-Script
WinWaitClose
ExitApp
^!#vkFF::Run,`% ClipBoard
), Run.ahk, UTF-8 ;User-Script
Run, Run.ahk
Run, *RunAs "%A_ScriptFullPath%",,, %ErrorLevel%
}
q::Run("Notepad.exe") ;Start Notepad.exe as User
Run(Target)
{
ClipSaved := ClipBoardAll
ClipBoard := Target
Sleep, 100
Send, ^!#{vkFF}
Sleep, 100
ClipBoard := ClipSaved
}