首页 > 解决方案 > RegWrite 不写入注册表

问题描述

ValueType := A_Args[1]
KeyName   := A_Args[2]
ValueName := A_Args[3]
ValueData := A_Args[4]
Loop, %0%
    params .= A_Space %A_Index%

; 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, % ValueType, % KeyName, % ValueName, % ValueData

当我将参数传递给脚本时,为什么 RegWrite 不写入注册表?

标签: autohotkey

解决方案


A_LastError 代码

代码 87 表示无效参数。你传递给RegWrite什么?

这是我用于调试的一个函数。如果isCondition为真,则显示自定义错误消息并停止一切。

fAbort(isCondition, sFuncName, sNote, dVars:="") {
    If isCondition {
        sAbortMessage := % sFuncName ": " sNote
        . "`n`nA_LineNumber: """ A_LineNumber """`nErrorLevel: """ ErrorLevel """`nA_LastError: """ A_LastError """`n"
        For sName, sValue in dVars
            sAbortMessage .= "`n" sName ": """ sValue """"
        MsgBox, 16,, % sAbortMessage
        ExitApp
    }
}

之后RegWrite它可以像这样使用:

fAbort(ErrorLevel                   ; 1, if RegWrite unsuccessful.
, "Script or function name here"    ; Could use A_ThisFunc for current function name.
, "Registry write unsuccessful."    ; Your custom message here.
, { x: "blabla", y: 13 }            ; Additional vars you want to see in the msgbox.
)

推荐阅读