run script as admin on startup error window

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
robinson
Posts: 218
Joined: 12 Sep 2019, 20:28

run script as admin on startup error window

02 Feb 2024, 15:37

Hi, noob here.
I've put a script called admin.ahk in my startup folder.
Why am I getting this error on startup?
Image
p.s. I just found this somewhere, I don't fully undestand it, but I do want the script to run elevated.
Thanks!
User avatar
mikeyww
Posts: 27302
Joined: 09 Sep 2014, 18:38

Re: run script as admin on startup error window

02 Feb 2024, 17:08

It could be because the operation was canceled by the user?

Posting your script may be the next step to help track down the problem.
robinson
Posts: 218
Joined: 12 Sep 2019, 20:28

Re: run script as admin on startup error window

02 Feb 2024, 18:09

@mikeyww
The whole thing is pretty long, but the first few lines look like this:

Code: Select all

SetWorkingDir A_ScriptDir  ; Ensures a consistent starting directory.
SetTitleMatchMode 2  ; match any part of the title
CoordMode("Mouse","Screen")
#SingleInstance Force
#NoTrayIcon
if A_IsAdmin="0" {
   Run("*RunAs " A_ScriptFullPath)
   ExitApp
}
After that it's just a bunch of regular old hotkeys.
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: run script as admin on startup error window

02 Feb 2024, 18:17

If the script's path is the one in the msgbox window, could you try wrapping a_scriptfullpath in double quotes?
exploded for clarity: Run("*RunAs " . '"' . A_ScriptFullPath . '"')
robinson
Posts: 218
Joined: 12 Sep 2019, 20:28

Re: run script as admin on startup error window

02 Feb 2024, 19:32

@coffee Thanks, I'll try that and let you know on the next reboot.
akhiler
Posts: 9
Joined: 10 Jun 2022, 14:27

Re: run script as admin on startup error window

04 Feb 2024, 16:58

Did it work?
If not try below without exitapp? Is exitapp necessary if the #singleinstance force directive is in place?

Code: Select all

if !A_IsAdmin
	Run '*RunAs "' A_ScriptFullPath '"'

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: ajkessel, Draken and 38 guests