Advertisement
HuynhVuThienLoc

Custom URL Protocol

Sep 16th, 2016
6,517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 1.60 KB | None | 0 0
  1. #include-once
  2.  
  3. ; #INDEX# =======================================================================================================================
  4. ; Title .........: Custom URL Protocol
  5. ; UDF Version....: 1.0.0
  6. ; AutoIt Version : 3.3.14.2
  7. ; Description ...: Register custom protocol for your AutoIt application
  8. ; Author(s) .....: Juno_okyo
  9. ; ===============================================================================================================================
  10.  
  11. Func setDefaultValue(ByRef $fileName)
  12.     If $fileName = Default Or Not FileExists($fileName) Then $fileName = @ScriptFullPath
  13. EndFunc   ;==>setDefaultValue
  14.  
  15. Func registerProtocol($protocolName, $iconFileName = Default, $execFileName = Default, $override = False)
  16.     setDefaultValue($iconFileName)
  17.     setDefaultValue($execFileName)
  18.  
  19.     Local $key = 'HKEY_CLASSES_ROOT\' & $protocolName
  20.     Local $test = RegRead($key, '')
  21.  
  22.     ; Not registed yet
  23.     If @error Or $override Then
  24.         If RegWrite($key, '', 'REG_SZ', 'URL:' & $protocolName & ' Protocol') Then
  25.             RegWrite($key, 'URL Protocol', 'REG_SZ', '')
  26.             RegWrite($key & '\DefaultIcon', '', 'REG_SZ', $iconFileName)
  27.             RegWrite($key & '\shell\open\command', '', 'REG_SZ', '"' & $execFileName & '" "%1"')
  28.             Return True
  29.         EndIf
  30.     EndIf
  31.  
  32.     Return False
  33. EndFunc   ;==>registerProtocol
  34.  
  35. Func unregisterProtocol($protocolName)
  36.     Return RegDelete('HKEY_CLASSES_ROOT\' & $protocolName)
  37. EndFunc   ;==>unregisterProtocol
  38.  
  39. Func getParams()
  40.     If $CmdLine[0] = 0 Then Return SetError(1, 0, False)
  41.     Local $params = StringSplit($CmdLine[1], ':', 3)
  42.     Return @error ? SetError(2, 0, False) : $params[1]
  43. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement