This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckProcesses-ModulesAndExecDos ANSI.iss
428 lines (390 loc) · 18 KB
/
CheckProcesses-ModulesAndExecDos ANSI.iss
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
[Setup]
AppName=Example ANSI
AppVersion=1.0
CreateAppDir=no
Uninstallable=no
WizardImageFile=compiler:WizModernImage-IS.bmp
ArchitecturesInstallIn64BitMode=x64
WizardSmallImageFile=compiler:WizModernSmallImage-IS.bmp
DisableWelcomePage=no
PrivilegesRequired=lowest
DisableReadyPage=yes
OutputBaseFilename=Example ANSI
; for InnoSetup 6+:
WizardResizable=yes
WizardStyle=modern
#Include "ExecDosAndCheckRunning.isi"
[Types]
Name: "custom"; Description: "Custom"; Flags: IsCustom;
[Components]
Name: "execute"; Description: "Extract to a ""%tmp%"" and execute from [Files] section via [Code] with output on installing page:";
Name: "execute\a"; Description: "1.cmd (dir %WinDir%)"; Types: custom;
Name: "execute\b"; Description: "2.cmd (ping.exe -w 1000 -l 1 -n 5 0.0.0.0)"; Types: custom;
Name: "execute\c"; Description: "3.cmd (tree /a %WinDir%\System32)"; Types: custom;
Name: "execute\d"; Description: "4.cmd (Please wait.....)"; Types: custom;
[CustomMessages]
StatusMsg=It's executed from script section [Files] via [Code]:
FilesMsg= Executing "%1" via "cmd.exe"
[Files]
// explanation of use -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> -=> AfterInstall: ExecDosWithOutputOnInstallingPageA('program', 'cmd-line params', 'WorkDir', 'StatusMsg message', 'FilesMsg message'); // Working Dir and both last two messages can be empty
DestDir: "{tmp}"; Source: "1.cmd"; Flags: DeleteAfterInstall IgnoreVersion; Components: "execute\a"; AfterInstall: "ExecDosWithOutputOnInstallingPageA('""cmd.exe""', '/c ""{tmp}\1.cmd""', '', '{cm:StatusMsg}', '{cm:FilesMsg,{tmp}\1.cmd}')";
DestDir: "{tmp}"; Source: "2.cmd"; Flags: DeleteAfterInstall IgnoreVersion; Components: "execute\b"; AfterInstall: "ExecDosWithOutputOnInstallingPageA('""cmd.exe""', '/c ""{tmp}\2.cmd""', '', '{cm:StatusMsg}', '{cm:FilesMsg,{tmp}\2.cmd}')";
DestDir: "{tmp}"; Source: "3.cmd"; Flags: DeleteAfterInstall IgnoreVersion; Components: "execute\c"; AfterInstall: "ExecDosWithOutputOnInstallingPageA('""cmd.exe""', '/c ""{tmp}\3.cmd""', '', '{cm:StatusMsg}', '{cm:FilesMsg,{tmp}\3.cmd}')";
DestDir: "{tmp}"; Source: "4.cmd"; Flags: DeleteAfterInstall IgnoreVersion; Components: "execute\d"; AfterInstall: "ExecDosWithOutputOnInstallingPageA('""cmd.exe""', '/c ""{tmp}\4.cmd""', '', '{cm:StatusMsg}', '{cm:FilesMsg,{tmp}\4.cmd}')";
[Code]
Var
InstallingListBox: TListBox;
Procedure ListBoxWrite(ListBox: TListBox; Str: String);
begin
ListBox.Items.Insert(0, Str);
AppProcessMessagesA();
end;
procedure InstallingCallBackA(const Output: PAnsiChar);
begin
ListBoxWrite(InstallingListBox, Output);
end;
Function ExpandScript(Str: String): String;
begin
If (Pos('{', Str) > 0) and (Pos('}', Str) > 0) then
Result := ExpandConstant(Str)
else
Result := Str;
end;
Procedure ExecDosWithOutputOnInstallingPageA(const FileNameOrFullPath, Params, WorkDir, StatusMsg, FilesMsg: String);
Var
Int, ExitCode: Integer;
Str: String;
begin
With WizardForm do
begin
Update;
Repaint;
With InstallingPage do
begin
StatusLabel.Caption := ExpandScript(StatusMsg);
FilenameLabel.Caption := ExpandScript(FilesMsg);
end; // InstallingPage.
end; // WizardForm.
With InstallingListBox.Items do
begin
ExitCode := ExecDosA( ExpandScript(FileNameOrFullPath), ExpandScript(Params), ExpandScript(WorkDir), SW_HIDE, @InstallingCallBackA, True );
For Int := 0 to 30 do
Str := Str + '-=';
Str := Str + '-';
Insert(0, Str);
Insert(0, 'ExitCode: ' + IntToStr(ExitCode) + ', ' + SysErrorMessage(ExitCode) );
Insert(0, Str);
end; // InstallingListBox.Lines.
end;
Var
FileListPage, TreeListPage, ErrorListPage: TOutputMsgMemoWizardPage;
Procedure MemoWrite(Memo: TMemo; Str: String);
begin
Memo.Lines.Add(Str);
end;
procedure FileListCallBackA(const Output: PAnsiChar);
begin
MemoWrite(FileListPage.RichEditViewer, Output);
end;
procedure TreeListCallBackA(const Output: PAnsiChar);
begin
MemoWrite(TreeListPage.RichEditViewer, Output);
end;
procedure ErrorListCallBackA(const Output: PAnsiChar);
begin
MemoWrite(ErrorListPage.RichEditViewer, Output);
end;
// for InnoSetup 6.05 Extended Edition -> https://wilenty.wixsite.com/SoftwareByWilenty/inno-setup-xp-ee-script-studio-port
Function InitializeSetup(): Boolean;
begin
With TApplication.Create(nil) do
begin
HintPause := 0;
HintHidePause := 1000 * 30;// 30s
HintShortPause := 0;
Free;
end; // TApplication.Create(nil).
Result := True;
end;
// ^_^
Procedure InitializeWizard();
Var
Str: String;
ProcessID: DWORD;
ProgramOrDLL: String;
Int: Integer;
begin
With WizardForm do
begin
InstallingListBox := TListBox.Create(InstallingPage);
With InstallingListBox do
begin
Parent := InstallingPage;
Left := 0;
Top := ProgressGauge.Top + ProgressGauge.Height + ScaleY(5);
Width := InstallingPage.ClientWidth;
Height := InstallingPage.ClientHeight - Top;
Color := clBlack;
With Font do
begin
Color := clLtGray;
Style := Style + [fsBold];
end; // Font.
// for InnoSetup 6+:
Anchors := [akLeft, akTop, akRight, akBottom];
end; // InstallingListBox.
WelcomeLabel2.Visible := False;
With TRichEditViewer.Create(WelcomePage) do
begin
Parent := WelcomePage;
Left := WizardBitmapImage.Left + WizardBitmapImage.Width + ScaleX(10);
Top := WelcomeLabel1.Top + WelcomeLabel1.Height;
Width := WelcomePage.ClientWidth - Left - ScaleX(10);
Height := WelcomePage.ClientHeight - Top - ScaleY(10);
ScrollBars := ssBoth;
ReadOnly := True;
WantReturns := False;
// for InnoSetup 6+:
Anchors := [akLeft, akTop, akRight, akBottom];
With Lines do
begin
ProcessID := GetHWndPID(WizardForm.Handle);
Add('This sample installer process ID is: ' + IntToStr(ProcessID) + #13#10 + 'and it''s path is: "' + GetPIDpathA(ProcessID) + '"'#13#10);
ProgramOrDLL := 'cmd.exe';
If IsProgramRunningA( ProgramOrDLL ) then
Add('"' + ProgramOrDLL + '" is running...' + #13#10 + 'it''s path is: "' + GetProgramInfoA(ProgramOrDLL, ProcessID) + '"'#13#10'and process ID is: ' + IntToStr(ProcessID) + #13#10)
else
Add('"' + ProgramOrDLL + '" process not found.' + #13#10);
ProgramOrDLL := 'Kernel32.dll';
If IsModuleLoadedA( ProgramOrDLL ) then
Add('"' + ProgramOrDLL + '" is loaded...' + #13#10 + 'and it''s path is: "' + GetModuleInfoA(ProgramOrDLL, ProcessID) + '"'#13#10)
else
Add('"' + ProgramOrDLL + '" not loaded.' + #13#10);
ProgramOrDLL := 'richtx32.ocx';
If IsModuleLoadedA( ProgramOrDLL ) then
Add('"' + ProgramOrDLL + '" is loaded...' + #13#10 + 'and it''s path is: "' + GetModuleInfoA(ProgramOrDLL, ProcessID) + '"'#13#10)
else
Add('"' + ProgramOrDLL + '" not loaded.' + #13#10);
ProgramOrDLL := 'User32.dll';
If IsModuleLoadedA( ProgramOrDLL ) then
Add('"' + ProgramOrDLL + '" is loaded...' + #13#10 + 'and it''s path is: "' + GetModuleInfoA(ProgramOrDLL, ProcessID) + '"'#13#10)
else
Add('"' + ProgramOrDLL + '" not loaded.' + #13#10);
ProgramOrDLL := 'Explorer.exe';
Add('"' + ProgramOrDLL + '" is running...' + #13#10 + 'it''s path is: "' + GetProgramInfoA(ProgramOrDLL, ProcessID) + '"'#13#10'process ID is: ' + IntToStr(ProcessID) + #13#10'and first active window handle is: $' + Format('%x', [GetPIDhWnd(ProcessID)]) + #13#10 );
For Int := 0 to 25 do
Str := Str + '-=';
Str := Str + '-';
Add(Str);
Add(' This sample created by Wilenty:');
Add(' https://www.buymeacoffee.com/Wilenty');
Add(Str);
Insert(0, '');
Delete(0);
end; // Lines.
end; // TRichEditViewer.Create(WelcomePage).
With BackButton do
begin
Left := Left - Width;
ShowHint := True;
end; // BackButton.
With NextButton do
begin
Left := Left - Width;
Width := Width + Width;
ShowHint := True;
end; // NextButton.
With ComponentsList do
begin
ShowHint := True;
Hint := 'In this script there is no the [Run] section';
end; // ComponentsList.
end; // WizardForm.
FileListPage := CreateOutputMsgMemoPage(wpUserInfo, 'Listing files and/or folders.', 'It''s fully executed from InnoSetup code.', 'Example 1 of 3'#13#10 + '"' + ExpandConstant('{cmd}') + '" /c dir "' + ExpandConstant('{win}') +'":', '');
With FileListPage.RichEditViewer do
begin
ScrollBars := ssBoth;
Color := clBlack;
UseRichEdit := False;
With Font do
begin
Color := clLtGray;
Style := Style + [fsBold];
end; // Font.
end; // FileListPage.RichEditViewer.
ErrorListPage := CreateOutputMsgMemoPage(FileListPage.ID, 'Here you see an error example.', 'It''s fully executed from InnoSetup code.', 'Example 2 of 3'#13#10'"ping.exe" -w 1000 -l 1 -n 5 0.0.0.0:', '');
With ErrorListPage.RichEditViewer do
begin
ScrollBars := ssBoth;
Color := clBlack;
UseRichEdit := False;
With Font do
begin
Color := clLtGray;
Style := Style + [fsBold];
end; // Font.
end; // ErrorListPage.RichEditViewer.
TreeListPage := CreateOutputMsgMemoPage(ErrorListPage.ID, 'Listing folders as a tree.', 'It''s fully executed from InnoSetup code.', 'Example 3 of 3'#13#10 + '"' + ExpandConstant('{cmd}') + '" /c tree /a "' + ExpandConstant('{sys}') + '":', '');
With TreeListPage.RichEditViewer do
begin
ScrollBars := ssBoth;
Color := clBlack;
UseRichEdit := False;
With Font do
begin
Color := clLtGray;
Style := Style + [fsBold];
end; // Font.
end; // TreeListPage.RichEditViewer.
end;
Function ExecuteA(const Prog, Params: String; ListPage: TOutputMsgMemoWizardPage; ExecOutCallBack: TExecOutCallBackA; Wait: Boolean): Integer;
Var
Int: Integer;
Str: String;
begin
Result := -1;
With ListPage do
begin
With Surface do
begin
With RichEditViewer.Lines do
begin
Clear;
Update;
Repaint;
Result := ExecDosA(Prog, Params, '', SW_HIDE, ExecOutCallBack, Wait);
For Int := 0 to 30 do
Str := Str + '-=';
Str := Str + '-';
Add(Str);
Add( 'ExitCode: ' + IntToStr(Result) + ', ' + SysErrorMessage(Result) );
Add(Str);
end; // RichEditViewer.Lines.
end; // Surface.
end; // ListPage.
end;
Function GetHint(Str: String): String;
begin
Result := Copy(Str, 1, Length(Str)-1);
end;
Function ExecuteWithParamsA(const CmdLine: String; ListPage: TOutputMsgMemoWizardPage; ExecOutCallBack: TExecOutCallBackA; Wait: Boolean): Integer;
var
Run: String;
Int: Integer;
begin
CmdLine := Copy( CmdLine, Pos(#13#10, CmdLine)+2, Length(CmdLine) );
Delete(CmdLine, Length(CmdLine), 1);
Int := Pos('" ', CmdLine);
Run := Copy( CmdLine, 1, Int );
CmdLine := Trim( Copy( CmdLine, Int+1, Length(CmdLine) ) );
Result := ExecuteA(Run, CmdLine, ListPage, ExecOutCallBack, Wait);
end;
procedure CurPageChanged(CurPageID: Integer);
begin
With WizardForm do
begin
NextButton.Hint := '';
BackButton.Hint := '';
If CurPageID = wpWelcome then
NextButton.Hint := GetHint(FileListPage.SubCaptionLabel.Caption)
else If CurPageID = FileListPage.ID then
begin
NextButton.Hint := GetHint(ErrorListPage.SubCaptionLabel.Caption);
BackButton.Hint := 'Welcome page';
ExecuteWithParamsA(FileListPage.SubCaptionLabel.Caption, FileListPage, @FileListCallBackA, True);
end
else If CurPageID = ErrorListPage.ID then
begin
NextButton.Hint := GetHint(TreeListPage.SubCaptionLabel.Caption);
BackButton.Hint := GetHint(FileListPage.SubCaptionLabel.Caption);
ExecuteWithParamsA(ErrorListPage.SubCaptionLabel.Caption, ErrorListPage, @ErrorListCallBackA, True);
end
else If CurPageID = TreeListPage.ID then
begin
NextButton.Hint := 'Components page';
BackButton.Hint := GetHint(ErrorListPage.SubCaptionLabel.Caption);
ExecuteWithParamsA(TreeListPage.SubCaptionLabel.Caption, TreeListPage, @TreeListCallBackA, True);
end
else If CurPageID = wpSelectComponents then
begin
NextButton.Hint := ComponentsList.Hint;
NextButton.Caption := FmtMessage( CustomMessage('LaunchProgram'), [''] );
BackButton.Hint := GetHint(TreeListPage.SubCaptionLabel.Caption);
end;
end; // WizardForm.
end;
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "afrikaans"; MessagesFile: "compiler:Languages\Afrikaans.isl"
Name: "albanian"; MessagesFile: "compiler:Languages\Albanian.isl"
Name: "arabic"; MessagesFile: "compiler:Languages\Arabic.islu"
Name: "armenian"; MessagesFile: "compiler:Languages\Armenian.islu"
Name: "asturian"; MessagesFile: "compiler:Languages\Asturian.isl"
Name: "basque"; MessagesFile: "compiler:Languages\Basque.isl"
Name: "belarusian"; MessagesFile: "compiler:Languages\Belarusian.isl"
Name: "bengali"; MessagesFile: "compiler:Languages\Bengali.islu"
Name: "bosnian"; MessagesFile: "compiler:Languages\Bosnian.isl"
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "bulgarian"; MessagesFile: "compiler:Languages\Bulgarian.islu"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.islu"
Name: "chinesetraditional"; MessagesFile: "compiler:Languages\ChineseTraditional.islu"
Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.islu"
Name: "croatian"; MessagesFile: "compiler:Languages\Croatian.islu"
Name: "czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "dutch"; MessagesFile: "compiler:Languages\Dutch.islu"
Name: "englishbritish"; MessagesFile: "compiler:Languages\EnglishBritish.isl"
Name: "esperanto"; MessagesFile: "compiler:Languages\Esperanto.isl"
Name: "estonian"; MessagesFile: "compiler:Languages\Estonian.isl"
Name: "farsi"; MessagesFile: "compiler:Languages\Farsi.isl"
Name: "finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "french"; MessagesFile: "compiler:Languages\French.islu"
Name: "galician"; MessagesFile: "compiler:Languages\Galician.islu"
Name: "georgian"; MessagesFile: "compiler:Languages\Georgian.islu"
Name: "german"; MessagesFile: "compiler:Languages\German.islu"
Name: "greek"; MessagesFile: "compiler:Languages\Greek.islu"
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.isl"
Name: "hindi"; MessagesFile: "compiler:Languages\Hindi.islu"
Name: "hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "icelandic"; MessagesFile: "compiler:Languages\Icelandic.islu"
Name: "indonesian"; MessagesFile: "compiler:Languages\Indonesian.islu"
Name: "italian"; MessagesFile: "compiler:Languages\Italian.islu"
Name: "japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "kazakh"; MessagesFile: "compiler:Languages\Kazakh.islu"
Name: "korean"; MessagesFile: "compiler:Languages\Korean.isl"
Name: "kurdish"; MessagesFile: "compiler:Languages\Kurdish.isl"
Name: "latvian"; MessagesFile: "compiler:Languages\Latvian.isl"
Name: "ligurian"; MessagesFile: "compiler:Languages\Ligurian.isl"
Name: "lithuanian"; MessagesFile: "compiler:Languages\Lithuanian.isl"
Name: "luxemburgish"; MessagesFile: "compiler:Languages\Luxemburgish.isl"
Name: "macedonian"; MessagesFile: "compiler:Languages\Macedonian.isl"
Name: "malaysian"; MessagesFile: "compiler:Languages\Malaysian.isl"
Name: "marathi"; MessagesFile: "compiler:Languages\Marathi.islu"
Name: "mongolian"; MessagesFile: "compiler:Languages\Mongolian.isl"
Name: "montenegrian"; MessagesFile: "compiler:Languages\Montenegrian.isl"
Name: "nepali"; MessagesFile: "compiler:Languages\Nepali.islu"
Name: "norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "norwegiannynorsk"; MessagesFile: "compiler:Languages\NorwegianNynorsk.isl"
Name: "occitan"; MessagesFile: "compiler:Languages\Occitan.isl"
Name: "persian"; MessagesFile: "compiler:Languages\Persian.isl"
Name: "polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "romanian"; MessagesFile: "compiler:Languages\Romanian.isl"
Name: "russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.islu"
Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl"
Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl"
Name: "sinhala"; MessagesFile: "compiler:Languages\Sinhala.islu"
Name: "slovak"; MessagesFile: "compiler:Languages\Slovak.isl"
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "swedish"; MessagesFile: "compiler:Languages\Swedish.isl"
Name: "tatar"; MessagesFile: "compiler:Languages\Tatar.isl"
Name: "thai"; MessagesFile: "compiler:Languages\Thai.isl"
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"
Name: "uyghur"; MessagesFile: "compiler:Languages\Uyghur.islu"
Name: "uzbek"; MessagesFile: "compiler:Languages\Uzbek.isl"
Name: "valencian"; MessagesFile: "compiler:Languages\Valencian.isl"
Name: "vietnamese"; MessagesFile: "compiler:Languages\Vietnamese.islu"