Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Run as Administrator (XP/Vista/7) A_IsAdmin Params [Lib]


  • Please log in to reply
49 replies to this topic
blue_martian
  • Members
  • 48 posts
  • Last active: Feb 12 2016 11:21 PM
  • Joined: 25 Apr 2013

Hi RHCP,

 

Thank you for your answer, I added it to my script and it did seem to clear the error message however it doesn't seem to run the files as administrator.

 

I'm using windows 8 and ahk version v1.1.09.02 (per the help file)

 

Here is the version of the code I used from this thread:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SetWorkingDir \\main\idata\CUSTOMER SERVICE\macros\master Macro\separate scripts
DetectHiddenWindows, on
#WinActivateForce
SetTitleMatchMode, 2
#IfWinActive, Force


RunAsAdmin() {
	Global 0
	IfEqual, A_IsAdmin, 1, Return 0
	Loop, %0%
		params .= A_Space . %A_Index%
	DllCall("shell32\ShellExecute" (A_IsUnicode ? "":"A"),uint,0,str,"RunAs",str,(A_IsCompiled ? A_ScriptFullPath
	: A_AhkPath),str,(A_IsCompiled ? "": """" . A_ScriptFullPath . """" . A_Space) params,str,A_WorkingDir,int,1)
	ExitApp
}

; I have a gui interface here then I call files as follows

prtpickticket:

run, \\main\idata\CUSTOMER SERVICE\macros\master Macro\separate scripts\print fulfillment 2.0.exe
return


Any idea why it may not be running as administrator?

 

Thanks again



RHCP
  • Members
  • 1228 posts
  • Last active: Apr 08 2017 06:17 PM
  • Joined: 29 May 2006

You have only included the function definition. You still need to call the function somewhere, so just add "RunAsAdmin()" within the auto exec (top part) of the script.



blue_martian
  • Members
  • 48 posts
  • Last active: Feb 12 2016 11:21 PM
  • Joined: 25 Apr 2013

that worked perfectly! (I have so much to learn)

 

Thanks again!



Albireo
  • Members
  • 558 posts
  • Last active: Jul 27 2019 10:36 AM
  • Joined: 01 Feb 2006

Hi!

Have I missed something?
I have tried this solution

; Version 1 dec 2014

RunAsAdmin()
MsgBox 64, Rad %A_LineNumber% -> %A_ScriptName%, % A_IsAdmin	;%;

Process Exist, Label32.exe
myPID := ErrorLevel

WinActivate ahk_pid  %myPID%
WinWait ahk_pid  %myPID%

WinGet LabelId, ID, ahk_class TMainForm ahk_pid %myPID%
WinMaximize ahk_id %LabelId% ahk_pid %myPID% ahk_class TMainForm

ControlSend ,,{F2}, ahk_pid %myPID%
; Send {F2}
ExitApp

RunAsAdmin() {
	Global 0
	IfEqual, A_IsAdmin, 1, Return 0
	Loop, %0%
		params .= A_Space . %A_Index%
	DllCall("shell32\ShellExecute" (A_IsUnicode ? "":"A"),uint,0,str,"RunAs",str,(A_IsCompiled ? A_ScriptFullPath
	: A_AhkPath),str,(A_IsCompiled ? "": """" . A_ScriptFullPath . """" . A_Space) params,str,A_WorkingDir,int,1)
	ExitApp
}

But the UAC-window is opened, and asks if it's "OK" everytime.
(I donĀ“t want to disable "UAC" control.)
After I have confirmed the UAC, it seems to work perfect.

 

Is it possible to do the same thing, without the UAC-question?

//Jan



Skrell
  • Members
  • 384 posts
  • Last active: Jul 07 2016 05:03 PM
  • Joined: 23 Aug 2011

Any idea if this would work in 8.1 ?