Skip to content

Commit 14913ca

Browse files
committed
SCM functions are now external files and included during build
1 parent 4c26067 commit 14913ca

File tree

3 files changed

+228
-31
lines changed

3 files changed

+228
-31
lines changed

src/HackWindowsInstaller_TEMP_Preprocessed.iss

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ AppId=HackWindowsInstaller
7272
SetupMutex=HackWindowsInstaller_SetupMutex
7373

7474
AppName=Hack Windows Installer
75-
AppVersion=1.2.0
76-
VersionInfoVersion=1.2.0
75+
AppVersion=1.2.1
76+
VersionInfoVersion=1.2.1
7777

7878
AppPublisher=Michael Hex / Source Foundry
7979
AppContact=Michael Hex / Source Foundry
@@ -125,7 +125,7 @@ AllowCancelDuringInstall=False
125125
;SetupAppTitle is displayed in the taskbar
126126
SetupAppTitle=Hack Windows Installer
127127
;SetupWindowsTitle is displayed in the setup window itself so better include the version
128-
SetupWindowTitle=Hack Windows Installer 1.2.0
128+
SetupWindowTitle=Hack Windows Installer 1.2.1
129129

130130
;Message for the "Read to install" wizard page
131131
;NOT USED - "Ready To Install" - below title bar
@@ -191,7 +191,7 @@ Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"; ValueN
191191

192192
[INI]
193193
;Create an ini to make detection for enterprise deployment tools easy
194-
Filename: "{app}\InstallInfo.ini"; Section: "Main"; Key: "Version"; String: "1.2.0"
194+
Filename: "{app}\InstallInfo.ini"; Section: "Main"; Key: "Version"; String: "1.2.1"
195195
Filename: "{app}\InstallInfo.ini"; Section: "Main"; Key: "Name"; String: "Hack Windows Installer"
196196

197197
[UninstallDelete]
@@ -204,6 +204,9 @@ Type: files; Name: "{app}\Log*.txt"
204204

205205

206206
[Code]
207+
208+
//--- START incl_ServiceControlManager-definition.iss ---
209+
207210
type
208211
SERVICE_STATUS = record
209212
dwServiceType : cardinal;
@@ -216,14 +219,15 @@ type
216219
end;
217220
HANDLE = cardinal;
218221
222+
219223
const
224+
SC_MANAGER_ALL_ACCESS = $f003f;
220225
SERVICE_QUERY_CONFIG = $1;
221226
SERVICE_CHANGE_CONFIG = $2;
222227
SERVICE_QUERY_STATUS = $4;
223228
SERVICE_START = $10;
224229
SERVICE_STOP = $20;
225230
SERVICE_ALL_ACCESS = $f01ff;
226-
SC_MANAGER_ALL_ACCESS = $f003f;
227231
SERVICE_WIN32_OWN_PROCESS = $10;
228232
SERVICE_WIN32_SHARE_PROCESS = $20;
229233
SERVICE_WIN32 = $30;
@@ -245,6 +249,10 @@ const
245249
SERVICE_CONTINUE_PENDING = $5;
246250
SERVICE_PAUSE_PENDING = $6;
247251
SERVICE_PAUSED = $7;
252+
253+
//--- END incl_ServiceControlManager-definition.iss ---
254+
255+
248256
249257
250258
var
@@ -266,6 +274,8 @@ var
266274
FontStateBuffer: array of string;
267275
268276
277+
//--- START incl_ServiceControlManager-functions.iss ---
278+
269279
function OpenSCManager(lpMachineName, lpDatabaseName: string; dwDesiredAccess :cardinal): HANDLE;
270280
external 'OpenSCManagerA@advapi32.dll stdcall';
271281
@@ -284,6 +294,7 @@ external 'ControlService@advapi32.dll stdcall';
284294
function QueryServiceStatus(hService :HANDLE;var ServiceStatus :SERVICE_STATUS) : boolean;
285295
external 'QueryServiceStatus@advapi32.dll stdcall';
286296
297+
287298
function OpenServiceManager() : HANDLE;
288299
begin
289300
if UsingWinNT() = true then begin
@@ -314,8 +325,6 @@ begin
314325
end
315326
end;
316327
317-
318-
319328
function StartService(ServiceName: string) : boolean;
320329
var
321330
hSCM : HANDLE;
@@ -371,8 +380,35 @@ begin
371380
end
372381
end;
373382
383+
function StartNTService2(serviceName:string):boolean;
384+
begin
385+
if IsServiceInstalled(serviceName) then begin
386+
if IsServiceRunning(serviceName)=false then begin
387+
log('Starting service ' + serviceName);
388+
StartService(serviceName);
389+
sleep(1500); //give the service some seconds
390+
result:=true;
391+
end;
392+
end;
393+
end;
394+
395+
function StopNTService2(serviceName:string):boolean;
396+
begin
397+
if IsServiceInstalled(serviceName) then begin
398+
if IsServiceRunning(serviceName) then begin
399+
log('Stopping service ' + serviceName);
400+
StopService(serviceName);
401+
sleep(1500);
402+
result:=true;
403+
end;
404+
end;
405+
end;
406+
374407
375408
409+
//--- END incl_ServiceControlManager-functions.iss ---
410+
411+
376412
377413
378414
procedure AddFontData(fontFile, fontName, fontHash :string);
@@ -549,29 +585,6 @@ end;
549585
550586
551587
552-
function StartNTService2(serviceName:string):boolean;
553-
begin
554-
if IsServiceInstalled(serviceName) then begin
555-
if IsServiceRunning(serviceName)=false then begin
556-
log('Starting service ' + serviceName);
557-
StartService(serviceName);
558-
sleep(1500); //give the service some seconds
559-
result:=true;
560-
end;
561-
end;
562-
end;
563-
564-
function StopNTService2(serviceName:string):boolean;
565-
begin
566-
if IsServiceInstalled(serviceName) then begin
567-
if IsServiceRunning(serviceName) then begin
568-
log('Stopping service ' + serviceName);
569-
StopService(serviceName);
570-
sleep(1500);
571-
result:=true;
572-
end;
573-
end;
574-
end;
575588
576589
577590
procedure BeforeInstallAction();
@@ -583,7 +596,7 @@ var
583596
begin
584597
LogAsImportant('---BeforeInstallAction START---');
585598
586-
LogAsImportant('Setup version: 1.2.0');
599+
LogAsImportant('Setup version: 1.2.1');
587600
LogAsImportant('Font version.: 2.020');
588601
LogAsImportant('Local time...: ' + GetDateTimeString('yyyy-dd-mm hh:nn', '-', ':'));
589602
LogAsImportant('Fonts folder.: ' + ExpandConstant('{fonts}'));
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#emit '//--- START incl_ServiceControlManager-definition.iss ---'
2+
3+
type
4+
SERVICE_STATUS = record
5+
dwServiceType : cardinal;
6+
dwCurrentState : cardinal;
7+
dwControlsAccepted : cardinal;
8+
dwWin32ExitCode : cardinal;
9+
dwServiceSpecificExitCode : cardinal;
10+
dwCheckPoint : cardinal;
11+
dwWaitHint : cardinal;
12+
end;
13+
HANDLE = cardinal;
14+
15+
16+
const
17+
SC_MANAGER_ALL_ACCESS = $f003f;
18+
SERVICE_QUERY_CONFIG = $1;
19+
SERVICE_CHANGE_CONFIG = $2;
20+
SERVICE_QUERY_STATUS = $4;
21+
SERVICE_START = $10;
22+
SERVICE_STOP = $20;
23+
SERVICE_ALL_ACCESS = $f01ff;
24+
SERVICE_WIN32_OWN_PROCESS = $10;
25+
SERVICE_WIN32_SHARE_PROCESS = $20;
26+
SERVICE_WIN32 = $30;
27+
SERVICE_INTERACTIVE_PROCESS = $100;
28+
SERVICE_BOOT_START = $0;
29+
SERVICE_SYSTEM_START = $1;
30+
SERVICE_AUTO_START = $2;
31+
SERVICE_DEMAND_START = $3;
32+
SERVICE_DISABLED = $4;
33+
SERVICE_DELETE = $10000;
34+
SERVICE_CONTROL_STOP = $1;
35+
SERVICE_CONTROL_PAUSE = $2;
36+
SERVICE_CONTROL_CONTINUE = $3;
37+
SERVICE_CONTROL_INTERROGATE = $4;
38+
SERVICE_STOPPED = $1;
39+
SERVICE_START_PENDING = $2;
40+
SERVICE_STOP_PENDING = $3;
41+
SERVICE_RUNNING = $4;
42+
SERVICE_CONTINUE_PENDING = $5;
43+
SERVICE_PAUSE_PENDING = $6;
44+
SERVICE_PAUSED = $7;
45+
46+
#emit '//--- END incl_ServiceControlManager-definition.iss ---'
47+
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#emit '//--- START incl_ServiceControlManager-functions.iss ---'
2+
3+
// Service control code from http://www.vincenzo.net/isxkb/index.php?title=Service_-_Functions_to_Start%2C_Stop%2C_Install%2C_Remove_a_Service
4+
function OpenSCManager(lpMachineName, lpDatabaseName: string; dwDesiredAccess :cardinal): HANDLE;
5+
external 'OpenSCManagerA@advapi32.dll stdcall';
6+
7+
function OpenService(hSCManager :HANDLE;lpServiceName: string; dwDesiredAccess :cardinal): HANDLE;
8+
external 'OpenServiceA@advapi32.dll stdcall';
9+
10+
function CloseServiceHandle(hSCObject :HANDLE): boolean;
11+
external 'CloseServiceHandle@advapi32.dll stdcall';
12+
13+
function StartNTService(hService :HANDLE;dwNumServiceArgs : cardinal;lpServiceArgVectors : cardinal) : boolean;
14+
external 'StartServiceA@advapi32.dll stdcall';
15+
16+
function ControlService(hService :HANDLE; dwControl :cardinal;var ServiceStatus :SERVICE_STATUS) : boolean;
17+
external 'ControlService@advapi32.dll stdcall';
18+
19+
function QueryServiceStatus(hService :HANDLE;var ServiceStatus :SERVICE_STATUS) : boolean;
20+
external 'QueryServiceStatus@advapi32.dll stdcall';
21+
22+
23+
function OpenServiceManager() : HANDLE;
24+
begin
25+
if UsingWinNT() = true then begin
26+
Result := OpenSCManager('','ServicesActive',SC_MANAGER_ALL_ACCESS);
27+
if Result = 0 then
28+
MsgBox('the servicemanager is not available', mbError, MB_OK)
29+
end
30+
else begin
31+
MsgBox('only nt based systems support services', mbError, MB_OK)
32+
Result := 0;
33+
end
34+
end;
35+
36+
function IsServiceInstalled(ServiceName: string) : boolean;
37+
var
38+
hSCM : HANDLE;
39+
hService: HANDLE;
40+
begin
41+
hSCM := OpenServiceManager();
42+
Result := false;
43+
if hSCM <> 0 then begin
44+
hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_CONFIG);
45+
if hService <> 0 then begin
46+
Result := true;
47+
CloseServiceHandle(hService)
48+
end;
49+
CloseServiceHandle(hSCM)
50+
end
51+
end;
52+
53+
function StartService(ServiceName: string) : boolean;
54+
var
55+
hSCM : HANDLE;
56+
hService: HANDLE;
57+
begin
58+
hSCM := OpenServiceManager();
59+
Result := false;
60+
if hSCM <> 0 then begin
61+
hService := OpenService(hSCM,ServiceName,SERVICE_START);
62+
if hService <> 0 then begin
63+
Result := StartNTService(hService,0,0);
64+
CloseServiceHandle(hService)
65+
end;
66+
CloseServiceHandle(hSCM)
67+
end;
68+
end;
69+
70+
function StopService(ServiceName: string) : boolean;
71+
var
72+
hSCM : HANDLE;
73+
hService: HANDLE;
74+
Status : SERVICE_STATUS;
75+
begin
76+
hSCM := OpenServiceManager();
77+
Result := false;
78+
if hSCM <> 0 then begin
79+
hService := OpenService(hSCM,ServiceName,SERVICE_STOP);
80+
if hService <> 0 then begin
81+
Result := ControlService(hService,SERVICE_CONTROL_STOP,Status);
82+
CloseServiceHandle(hService)
83+
end;
84+
CloseServiceHandle(hSCM)
85+
end;
86+
end;
87+
88+
function IsServiceRunning(ServiceName: string) : boolean;
89+
var
90+
hSCM : HANDLE;
91+
hService: HANDLE;
92+
Status : SERVICE_STATUS;
93+
begin
94+
hSCM := OpenServiceManager();
95+
Result := false;
96+
if hSCM <> 0 then begin
97+
hService := OpenService(hSCM,ServiceName,SERVICE_QUERY_STATUS);
98+
if hService <> 0 then begin
99+
if QueryServiceStatus(hService,Status) then begin
100+
Result :=(Status.dwCurrentState = SERVICE_RUNNING)
101+
end;
102+
CloseServiceHandle(hService)
103+
end;
104+
CloseServiceHandle(hSCM)
105+
end
106+
end;
107+
108+
//Returns TRUE if a service was started
109+
function StartNTService2(serviceName:string):boolean;
110+
begin
111+
if IsServiceInstalled(serviceName) then begin
112+
if IsServiceRunning(serviceName)=false then begin
113+
log('Starting service ' + serviceName);
114+
StartService(serviceName);
115+
sleep(1500); //give the service some seconds
116+
result:=true;
117+
end;
118+
end;
119+
end;
120+
121+
//Stops a service and returns TRUE if it was stopped
122+
function StopNTService2(serviceName:string):boolean;
123+
begin
124+
if IsServiceInstalled(serviceName) then begin
125+
if IsServiceRunning(serviceName) then begin
126+
log('Stopping service ' + serviceName);
127+
StopService(serviceName);
128+
sleep(1500);
129+
result:=true;
130+
end;
131+
end;
132+
end;
133+
134+
135+
136+
#emit '//--- END incl_ServiceControlManager-functions.iss ---'
137+

0 commit comments

Comments
 (0)