-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClickOnce-Unattended.au3
114 lines (88 loc) · 3.97 KB
/
ClickOnce-Unattended.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#cs ----------------------------------------------------------------------------
Title: ClickOnce Unattended
Version: v0.1-beta
AutoIt Version: 3.3.14.2
Author: Eduardo Mozart de Oliveira
Script Function:
Unattended installer for ClickOnce applications.
#ce ----------------------------------------------------------------------------
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include "AutoIt-ProcessClass\ProcessClass.au3"
AutoItSetOption("TrayIconDebug", 1)
Opt("WinWaitDelay", 250)
;OnAutoItExitRegister("OnAutoItExit")
HotKeySet("{ESCAPE}", "OnAutoItExit")
ConsoleWrite("$CmdLine[0]: " & $CmdLine[0])
If $CmdLine[0] = 0 Then Main(_FileOpenDialog())
If $CmdLine[0] = 1 Then Main($CmdLine[1])
If $CmdLine[0] > 1 Then help()
Func Main($ClickOnceStub)
If Not FileExists($ClickOnceStub) Then
ConsoleWrite("ERROR: File " & $ClickOnceStub & " not found.")
Exit 1
EndIf
EnvSet("SEE_MASK_NOZONECHECKS","1")
ShellExecute($ClickOnceStub)
EnvSet("SEE_MASK_NOZONECHECKS","0")
ProcessWait("dfsvc.exe")
AdlibRegister("OnAutoItExitAdlib")
While _Process2Win("dfsvc.exe") = -1
Sleep(250)
ConsoleWrite('_Process2Win("dfsvc.exe"): ' & _Process2Win("dfsvc.exe") & @CRLF)
WEnd
ConsoleWrite('_Process2Win("dfsvc.exe"): ' & _Process2Win("dfsvc.exe") & @CRLF)
WinWaitActive(_Process2Win("dfsvc.exe"), ControlGetText(_Process2Win("dfsvc.exe"), "", "[NAME:btnInstall]"))
While ControlGetText(_Process2Win("dfsvc.exe"), "", "[NAME:btnInstall]") = ""
Sleep(250)
ConsoleWrite('ControlGetText("btnInstall"): ' & ControlGetText(_Process2Win("dfsvc.exe"), "", "[NAME:btnInstall]") & @CRLF & @CRLF)
WEnd
ControlClick(_Process2Win("dfsvc.exe"), ControlGetText(_Process2Win("dfsvc.exe"), "", "[NAME:btnInstall]"), "[NAME:btnInstall]")
EndFunc
Func OnAutoItExit()
If ProcessExists("dfsvc.exe") Then
ProcessClose("dfsvc.exe")
EndIf
Exit
EndFunc
Func OnAutoItExitAdlib()
; Assign a static variable to hold the number of times the function is called.
; Local Static $iCount = 0
; $iCount += 1
If Not ProcessExists("dfsvc.exe") Then
Exit
EndIf
; ConsoleWrite("MyAdLibFunc called " & $iCount & " time(s)" & @CRLF)
EndFunc ;==>OnAutoItExitAdlib
Func help()
$msg = "ClickOnce-Unattended is a command line utility that silently install ClickOnce Applications." & @CRLF & _
@CRLF & "Syntax:" & @CRLF & _
@CRLF & "ClickOnce-Unattended ""path""" & @CRLF & _
@CRLF & " path I.E. C:\folder\sub-folder\setup.exe (use quotes if there are spaces)" & _
@CRLF & "Example:" & _
@CRLF & "ClickOnce-Unattended ""C:\test fol\setup.exe""" & @CRLF
MsgBox(0, "ClickOnce-Unattended Help", $msg)
Exit
EndFunc ;==>help
Func _FileOpenDialog()
; Create a constant variable in Local scope of the message to display in FileOpenDialog.
; Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files."
Local Const $sMessage = "Select file."
; Display an open dialog to select a list of file(s).
Local $sFileOpenDialog = FileOpenDialog($sMessage, @ScriptDir & "\", "Executables (*.exe)", $FD_FILEMUSTEXIST)
If @error Then
; Display the error message.
MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(@ScriptDir)
Exit 1
Else
; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
FileChangeDir(@ScriptDir)
; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
$sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
; Display the list of selected files.
; ConsoleWrite("You choose the following file:" & @CRLF & $sFileOpenDialog)
EndIf
Return $sFileOpenDialog
EndFunc ;==>Example