#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Notepad++Forward.ico #AutoIt3Wrapper_UseX64=y #AutoIt3Wrapper_Res_Fileversion=1.0.0.4 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #pragma compile(AutoItExecuteAllowed, true) Global $sAppTitle = 'Notepad++ Forward', $sNppPath = @ScriptDir & '\Notepad++.exe' If @Compiled And Not FileExists($sNppPath) Then Exit MsgBox(0x30, 'Notepad++', 'Cannot find ' & $sNppPath) If $CmdLine[0] Then If ($CmdLine[1] = '/install' Or $CmdLine[1] = '/uninstall') And Not IsAdmin() Then MsgBox(0x10, $sAppTitle, 'Must run this program as an administrator.') ElseIf $CmdLine[1] = '/install' Then If MsgBox(0x124, $sAppTitle, 'Install Notepad++ replacement?') = 6 Then Dim $t RegWrite('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe', 'Debugger', 'REG_SZ', '"' & @ScriptFullPath & '"') $t = @error RegWrite('HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe', 'Debugger', 'REG_SZ', '"' & @ScriptFullPath & '"') $t &= @error If $t = '00' Then MsgBox(0x40, $sAppTitle, 'Install complete. To uninstall, run this program with the /uninstall parameter.') Else MsgBox(0x30, $sAppTitle, 'Install incomplete. Unable to write to registry. (Error: ' & $t & ')') EndIf EndIf ElseIf $CmdLine[1] = '/uninstall' Then If MsgBox(0x124, $sAppTitle, 'Uninstall Notepad++ replacement?') = 6 Then Dim $t RegDelete('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe', 'Debugger') $t = @error RegDelete('HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe', 'Debugger') $t &= @error If $t = '00' Then MsgBox(0x40, $sAppTitle, 'Uninstall complete') Else MsgBox(0x30, $sAppTitle, 'Uninstall incomplete. Unable to modify registry. (Error: ' & $t & ')') EndIf EndIf ElseIf $CmdLine[0] < 2 Then RunWait($sNppPath) Else Dim $sFile = StringRegExpReplace($CmdLineRaw, '^.*?\Q' & $CmdLine[1] & '\E.*? ', '') Dim $sFileCheck = StringRegExpReplace($sFile, '^"(.*)"$', '\1') If Not FileExists($sFileCheck) Then If MsgBox(0x134, $sAppTitle, 'Could not find file:' & @LF & $sFileCheck & @LF & @LF & 'Continue anyway?') = 7 Then Exit EndIf RunWait($sNppPath & ' ' & $sFile) EndIf Else Dim $iMsgBox = MsgBox(0x243, $sAppTitle, 'Install or uninstall forwarder?' & @CRLF & _ ' · [Yes] Install' & @CRLF & _ ' · [No] Uninstall' & @CRLF & _ 'Or run program with /install or /uninstall parameter.') ; Yes: 6, No: 7, Cancel: 2 If $iMsgBox = 6 Then _Elevate('install') ElseIf $iMsgBox = 7 Then _Elevate('uninstall') EndIf EndIf Func _Elevate($s) Do Local $tmp = @TempDir & '\' & Random(0, 0xffff, 1) Until Not FileExists($tmp) FileWrite($tmp, StringFormat('#NoTrayIcon\r\n#RequireAdmin\r\nRun("""%s"" /%s")\r\nFileDelete(FileGetShortName(@ScriptFullPath))', @ScriptFullPath, $s)) RunWait('"' & @AutoItExe & '" /AutoIt3ExecuteScript ' & $tmp) EndFunc