#region - Daemon Tools install script - (Nullsoft)
#include <Common_Functions.au3>
Opt('TrayIconDebug', 1)
Break(False)

; Installer.
$executable = 'Daemon Tools 4.09.1.exe'
; Default group folder in startmenu.
$group = 'DAEMON Tools'
; Installation folder in Program Files.
$directory = 'DAEMON Tools'

; Run the installer.
$exitcode = _Nullsoft_Custom()
If Not $CMDLINE[0] And $exitcode = 2 Then
    $key_runonce = 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce'
    RegWrite($key_runonce, 'InstallDT4', 'Reg_sz', '"' & @AutoItExe & '" /AutoIt3ExecuteScript "' & @ScriptFullPath & '" /runonce')
    _NeedRestart()
    Exit 0
EndIf

; Mount to CDRom association
$association = RegRead('HKLM\SOFTWARE\Classes\.iso', '')
If @error Or $association <> '' Then
    $key_iso = 'HKLM\SOFTWARE\Classes\.iso'
    $key_isofile = 'HKLM\SOFTWARE\Classes\isofile'
    RegWrite($key_iso, '', 'Reg_sz', 'isofile')
    RegWrite($key_isofile, '', 'Reg_sz', 'ISO Image')
    RegWrite($key_isofile & '\DefaultIcon', '', 'Reg_sz', @SystemDir & '\shell32.dll,188')
    RegWrite($key_isofile & '\Shell\open', '', 'Reg_sz', 'Mount image to CDRom')
    RegWrite($key_isofile & '\Shell\open\command', '', 'Reg_sz', '"' & @ProgramFilesDir & '\' & $directory & '\daemon.exe" -mount 0, "%1"')
;~  If FileExists(@ProgramFilesDir & '\UltraISO\UltraISO.exe') Then
;~      RegWrite($key_isofile & '\Shell\edit', '', 'Reg_sz', 'Edit with UltraISO')
;~      RegWrite($key_isofile & '\Shell\edit\command', '', 'Reg_sz', '"' & @ProgramFilesDir & '\UltraISO\UltraISO.exe"')
;~  EndIf
EndIf

; Remove shortcuts.
If _Programs('DAEMON Tools.lnk') Then
    FileMove($group & '\DAEMON Tools.lnk', 'Emulators\', 9)
    DirRemove($group, 1)
EndIf
_Desktop('DAEMON Tools.lnk')

; Delete spyware installer.
If FileExists(@ProgramFilesDir & '\' & $directory & '\SetupDTSB.exe') Then
    FileDelete(@ProgramFilesDir & '\' & $directory & '\SetupDTSB.exe')
EndIf

; Remove Autorun entry.
RegDelete('HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'DAEMON Tools')
RegDelete('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', 'DAEMON Tools')

Exit $exitcode
#endregion

Func _Nullsoft_Custom($parameters = Default)
    ; Run a Nullsoft Installer  with Default: /S.
    Dim $directory, $executable
    If $parameters = Default Then
        $parameters = '/S'
        If $directory <> '' Then $parameters &= ' /D=' & @ProgramFilesDir & '\' & $directory
    EndIf
    If Not FileExists($executable) And Not FileExists(@ScriptDir & '\' & $executable) Then
        Exit 1
    ElseIf Not FileExists($executable) Then
        FileChangeDir(@ScriptDir)
    EndIf
    Return RunWait('"' & @WorkingDir & '\' & $executable & '" ' & $parameters)
EndFunc