Here's a much simpler code for this purpose:
if not A_IsAdmin
Run *RunAs "%A_ScriptFullPath%"
It will run the script as Admin if it's not already running as Admin.
If you don't have #SingleInstance Force
on top of your script, it will ask that if you want to replace the running script (not admin) with admin. So to prevent that, add the mentioned line on top of your script.
Also have a look at this code (it didn't work for me):
if !A_IsAdmin
Run, % "*RunAs " (A_IsCompiled ? "" : A_AhkPath " ") Chr(34) A_ScriptFullPath Chr(34)
Chr(34)
returns character "
Source of this code: https://www.autohotkey.com/boards/viewtopic.php?t=39647