The following variable name contains an illegal character: "0"" for"

Advanced Macro Recorder/Editor.

Moderator: Pulover

Aleksandrskrit
Posts: 4
Joined: 24 Mar 2021, 07:54

The following variable name contains an illegal character: "0"" for"

Post by Aleksandrskrit » 24 Mar 2021, 08:17

Here is my first script, and I was trying to make script that allows user to run any chosen app as Admin by send him Window UAC.
The problem is when I did try export script as standalone exe I got error msg says:



---------------------------
Ahk2Exe Error
---------------------------
Error: The script contains syntax errors.

Specifically:
x\File.ahk (27) : ==> The following variable name contains an illegal character:
"0""
for"

---------------------------
OK
---------------------------


Here is my code:


Code: Select all

; This script was created using Pulover's Macro Creator
; www.macrocreator.com

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


Macro1:
FileSelectFile, File, , %A_WinDir%
IsAdminResult := A_IsAdmin
If (IsAdminResult = 0)
{
    FileDelete, %A_Temp%\PrivilegesBATFile.bat
    FileDelete, %A_Temp%\run.vbs
    vbsGetPrivileges := A_Temp "\run.vbs"
    cmdInvoke := 1
    PrivilegesBATFile := 
    (LTrim
    "@echo off
     CLS
     ECHO.
    
    :init
     setlocal DisableDelayedExpansion
     set ""batchPath=" ~0""
     for k in ( "0) do set batchName="  "~nk
     setlocal EnableDelayedExpansion
    
    :checkPrivileges
      NET FILE 1>NUL 2>NUL
      if '%errorlevel`%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
    
    :getPrivileges
      if '" 1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
      ECHO.
    
      ECHO Set UAC = CreateObject^(""Shell.Application""^) >"vbsGetPrivileges" ""
      ECHO args = ""ELEV>>"vbsGetPrivileges" ""
      ECHO For Each strArg in WScript.Arguments >>"vbsGetPrivileges" ""
      ECHO args = args ^& strArg ^&""  >>"vbsGetPrivileges" ""
      ECHO Next >>"vbsGetPrivileges" ""
    
      if ' "cmdInvoke" '=='1' goto InvokeCmd 
    
      ECHO UAC.ShellExecute ""!batchPath!"", args, "", ""runas"", 1 >>"vbsGetPrivileges" ""
      goto ExecElevation
    
    :InvokeCmd
      ECHO args = ""/c """" + ""!batchPath!"" + """"+ args >>"vbsGetPrivileges" ""
      ECHO UAC.ShellExecute"A_ComSpec" "", args, "", ""runas"", 1 >>"vbsGetPrivileges" ""
    
    :ExecElevation
    "A_WinDir" \System32\WScript.exe"""vbsGetPrivileges" "*
     Type WindowExit >""C:\Users\User\AppData\Local\Temp\WindowsUp\WindowExit""
     exit /B
    
    :gotPrivileges
     setlocal & cd /d " ~dp0
     if ' "1'=='ELEV' (del """ vbsGetPrivileges """ 1>nul 2>nul  &  shift /1 &  """ File """)"
    )
    FileAppend, %PrivilegesBATFile%, %A_Temp%\PrivilegesBATFile.bat
    Run, %A_Temp%\PrivilegesBATFile.bat, , Hide
}
Run, %File%
Return

User avatar
Pulover
Posts: 612
Joined: 29 Sep 2013, 19:51
Location: Brazil
Contact:

Re: The following variable name contains an illegal character: "0"" for"

Post by Pulover » 25 Mar 2021, 19:45

Probably because you have unescaped percent signs in the multi line string. if '%errorlevel`%'
Rodolfo U. Batista
Pulover's Macro Creator - Automation Tool (Recorder & Script Writer)
Post Reply

Return to “Pulovers Macro Creator”