Page 1 of 1
Error 87 (ERROR_INVALID_PARAMETER)
Posted: 21 Jun 2021, 19:31
by Ecimeric
Code: Select all
ValueType := "REG_DWORD"
KeyName := "HKLM\SOFTWARE\Policies\Google\Chrome"
ValueName := "IncognitoModeAvailability"
Run, % "AutoHotkeyU32.exe RegWrite.ahk " ValueType " " KeyName " " ValueName " " 0
; RegWrite.ahk
Loop, %0%
params .= A_Space %A_Index%
params := SubStr(params, 2)
; https://autohotkey.com/docs/Run#RunAs
full_command_line := DllCall("GetCommandLine", "str")
if !(A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)")) {
try {
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" "%params%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" "%params%"
}
ExitApp
}
RegWrite, % A_Args[1], % A_Args[2], % A_Args[3], % A_Args[4]
if ErrorLevel
MsgBox, % A_LastError "`n`n" """" params """"
else
MsgBox, % "No error"
How can I resolve error 87 (ERROR_INVALID_PARAMETER)?
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 22 Jun 2021, 04:52
by mikeyww
Hard to say, but you can display your command-line parameters to see what they are in the script.
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 22 Jun 2021, 15:42
by Ecimeric
I added a MsgBox to display the parameters; I even stripped an extra space from params.
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 22 Jun 2021, 17:26
by mikeyww
The following worked for me.
Code: Select all
If !A_IsAdmin && !RegExMatch(DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
ExitApp
}
ValueType := "REG_DWORD"
KeyName := "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome"
ValueName := "IncognitoModeAvailability"
Run, AutoHotkeyU32.exe RegWrite.ahk %ValueType% %KeyName% %ValueName% 0
; =====================================
; RegWrite.ahk
RegWrite, % A_Args[1], % A_Args[2], % A_Args[3], % A_Args[4]
MsgBox, 64, ErrorLevel, %ErrorLevel%
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 23 Jun 2021, 02:58
by Ecimeric
Thank you. A little disappointing having to elevate/restart the primary script, but at least it works; I may as well create a function in place of RegWrite.ahk.
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 23 Jun 2021, 03:20
by just me
Ecimeric:
Code: Select all
try {
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" "%params%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" "%params%"
Run as Administrator:
Code: Select all
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
}
They are different.
Re: Error 87 (ERROR_INVALID_PARAMETER) Topic is solved
Posted: 23 Jun 2021, 09:04
by mikeyww
Alternative (& see info above about compiled versions):
Code: Select all
ValueType := "REG_DWORD"
KeyName := "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome"
ValueName := "IncognitoModeAvailability"
Run, AutoHotkeyU32.exe RegWrite.ahk %ValueType% %KeyName% %ValueName% 0
; ==========================
; RegWrite.ahk
If !A_IsAdmin && !RegExMatch(cline := DllCall("GetCommandLine", "str"), " /restart(?!\S)") {
Try Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" "%cline%"
ExitApp
}
part := StrSplit(A_Args.1, " ")
RegWrite, % part.3, % part.4, % part.5, % part.6
MsgBox, 64, ErrorLevel, %ErrorLevel%
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 23 Jun 2021, 15:40
by Ecimeric
Thank you both!
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 24 Jun 2021, 05:39
by just me
Sorry! After reading the docs about
*RunAs silly me thought that parameters would be passed automatically; they are not, of course.
After re-reading i found two errors in the OP's script:
Code: Select all
Run *RunAs "%A_ScriptFullPath%" "%params%" /restart
Wrong parameter order, switches must precede script parameters.
Code: Select all
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" "%params%"
You must not enclose the parameters in double-quotes. (That's also true for the first faulty line.) The script will only recognize one parameter then. But you should enclose every single parameter in double-quotes and separate them with a space.
So I would do something like this:
Code: Select all
#NoEnv ; RegWrite.ahk
; ------------------------------------------------------------------------------
; https://autohotkey.com/docs/Run#RunAs
full_command_line := DllCall("GetCommandLine", "str")
args := ""
Loop, % A_Args.Length()
args .= """" . A_Args[A_Index] . """ "
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
try
{
if A_IsCompiled
Run *RunAs "%A_ScriptFullPath%" /restart %args%
else
Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%" %args%
}
ExitApp
}
; ------------------------------------------------------------------------------
MsgBox, 0, RegWrite, % A_Args.Length() . "`n" . A_Args[1] . "`n" . A_Args[2] . "`n" . A_Args[3] . "`n" . A_Args[4]
ExitApp
Edit: Typo
Re: Error 87 (ERROR_INVALID_PARAMETER)
Posted: 24 Jun 2021, 06:37
by mikeyww
I'm not sure that it matters for this particular script, but just me has a better overall approach to the problem.