Reload as Admin with same parameters? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
KilliK
Posts: 175
Joined: 10 Mar 2016, 21:19

Reload as Admin with same parameters?

08 Mar 2018, 12:45

Hello.

I have created a script which reloads with elevated rights when necessary with this common code:

Code: Select all

;restart script in admin mode
if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%" 
   ExitApp
}
The script is also loaded with a parameter which is not always the same.
for example: c:\myscript.ahk par1

The problem is that if the script reloads as admin, the original parameter gets lost.
How can I maintain it in the reloaded script?

I tried this Run *RunAs "%A_ScriptFullPath%" "%1%" but it doesnt work.
I also searched the forum but I found some old complicated solutions in the old boards which require dllcalls etc to work.
Is there a simple way to resolve this?
User avatar
gregster
Posts: 1494
Joined: 30 Sep 2013, 06:48

Re: Reload as Admin with same parameters?  Topic is solved

08 Mar 2018, 12:58

Try Run *RunAs %A_ScriptFullPath% %1%
KilliK
Posts: 175
Joined: 10 Mar 2016, 21:19

Re: Reload as Admin with same parameters?

08 Mar 2018, 13:02

ok, I found the problem, it was an #include script messing the parameter.

the Run *RunAs %A_ScriptFullPath% %1% works now. thanx for the help, gregster.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], grimboto, newbieforever, tt_1111, Xtra and 105 guests