-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<Wix | ||
xmlns="http://schemas.microsoft.com/wix/2006/wi" | ||
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> | ||
<Product | ||
Name='Python Service by WiX' | ||
Version='0.1.0' | ||
Manufacturer='marbx' | ||
Language='1033' | ||
UpgradeCode='a26bc2d3-d9a8-44cb-916c-2c8270fe178e' | ||
Id='*' | ||
> | ||
<Package InstallerVersion='450' Compressed='yes' InstallScope="perMachine"/> | ||
<MediaTemplate EmbedCab="yes"/> | ||
<Directory Id='TARGETDIR' Name='SourceDir'> | ||
<Directory Id='ProgramFiles64Folder' Name='PFiles'> | ||
<Directory Id='Mare' Name='Mare'> | ||
<Component Id='ReadMe.component'> | ||
<File Id='ReadMe.fileID' Name='FoobarAppl10.txt' Source='FoobarAppl10.txt' KeyPath='yes'/> | ||
</Component> | ||
</Directory> | ||
</Directory> | ||
</Directory> | ||
<Feature Id='Complete'> | ||
<ComponentRef Id='ReadMe.component'/> | ||
<ComponentGroupRef Id="service" /> <!-- Includes service.wxs in this directory --> | ||
</Feature> | ||
</Product> | ||
</Wix> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import win32serviceutil | ||
import win32service | ||
import win32event | ||
import servicemanager | ||
import socket | ||
|
||
|
||
|
||
|
||
class AppServerSvc (win32serviceutil.ServiceFramework): | ||
_svc_name_ = "Python_service_by_pywin32" | ||
_svc_display_name_ = "Python_service_by_pywin32" | ||
STRFTIME = '%Y-%m-%dT%H:%M:%S' | ||
run = 0 | ||
|
||
def __init__(self,args): | ||
win32serviceutil.ServiceFramework.__init__(self,args) | ||
self.hWaitStop = win32event.CreateEvent(None,0,0,None) | ||
socket.setdefaulttimeout(60) | ||
|
||
|
||
def SvcStop(self): | ||
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) | ||
win32event.SetEvent(self.hWaitStop) | ||
|
||
|
||
def SvcDoRun(self): | ||
servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, | ||
servicemanager.PYS_SERVICE_STARTED, | ||
(self._svc_name_,'')) | ||
#self.main() | ||
|
||
|
||
def main(self): | ||
import time | ||
import datetime | ||
|
||
while self.run < 900: | ||
self.run += 1 | ||
now = datetime.datetime.now().strftime(self.STRFTIME) | ||
print(now) | ||
with open('/temp/Python_service_by_pywin32', 'a') as f: | ||
f.write(f"{now}\n") | ||
time.sleep(5) | ||
|
||
if __name__ == '__main__': | ||
win32serviceutil.HandleCommandLine(AppServerSvc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
``` | ||
pip install pywin32 | ||
python c:\git\LearnWix3\python_service_by_wix\Python_service_by_pywin32.py start | ||
Starting service Python_service_by_pywin32 | ||
Error starting service: The service did not respond to the start or control request in a timely fashion. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" | ||
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> | ||
<Fragment> | ||
<ComponentGroup Id="service"> | ||
<Component Directory="TARGETDIR" Guid="{9972ea7e-b2ab-40d5-8566-fe007374a3ad}"> | ||
<File Id="python.exe" KeyPath="yes" Source="C:\somewhere\python.exe" /> | ||
<ServiceInstall | ||
Account="LocalSystem" | ||
ErrorControl="normal" | ||
Name="python-service-by-wix" | ||
Start="auto" | ||
Type="ownProcess" | ||
Vital="yes" | ||
Description="python-service-by-wix" | ||
DisplayName="python-service-by-wix" | ||
Id="python-service-by-wix"> | ||
<util:ServiceConfig | ||
FirstFailureActionType="none" | ||
SecondFailureActionType="none" | ||
ThirdFailureActionType="none" /> | ||
</ServiceInstall> | ||
<ServiceControl | ||
Id="python-service-by-wix" | ||
Name="python-service-by-wix" | ||
Remove="uninstall" | ||
Stop="both" | ||
Start="install" | ||
Wait="yes"> | ||
<ServiceArgument /> | ||
</ServiceControl> | ||
<CreateFolder /> | ||
<util:EventSource | ||
Log="Application" | ||
Name="python-service-by-wix" | ||
EventMessageFile="[#python.exe]" /> | ||
<RegistryKey Root="HKLM" Key="System\CurrentControlSet\Services\python-service-by-wix"> | ||
<RegistryKey Key="Parameters"> | ||
<RegistryValue Type="expandable" Name="AppDirectory" Value="C:\somewhere\" /> | ||
<RegistryValue Type="expandable" Name="Application" Value="C:\somewhere\python.exe" /> | ||
<RegistryValue Type="expandable" Name="AppParameters" Value="C:\somewhere\doesnotexist.py" /> | ||
</RegistryKey> | ||
</RegistryKey> | ||
</Component> | ||
</ComponentGroup> | ||
</Fragment> | ||
</Wix> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PowerShell -ExecutionPolicy RemoteSigned -File build.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Set-ExecutionPolicy RemoteSigned | ||
Set-PSDebug -Strict | ||
Set-strictmode -version latest | ||
|
||
$msbuild = "C:\Program Files (x86)\MSBuild\14.0\" # Build tools 2015 | ||
|
||
|
||
function CheckExitCode($txt) { | ||
if ($LastExitCode -ne 0) { | ||
Write-Host -ForegroundColor Red "$txt failed" | ||
exit(1) | ||
} | ||
} | ||
|
||
|
||
Write-Host -ForegroundColor Yellow "Precompiling wxs to wixobj..." | ||
& "$($ENV:WIX)bin\candle.exe" ` | ||
-nologo ` | ||
-sw1150 ` | ||
-arch x64 ` | ||
-ddist=".\" ` | ||
-ext "$($ENV:WIX)bin\WixUtilExtension.dll" ` | ||
-ext "$($ENV:WIX)bin\WixUIExtension.dll" ` | ||
-ext "$($ENV:WIX)bin\WixNetFxExtension.dll" ` | ||
Product.wxs ` | ||
Service.wxs | ||
CheckExitCode "candle" | ||
|
||
|
||
Write-Host -ForegroundColor Yellow "Linking wixobj to msi..." | ||
& "$($ENV:WIX)bin\light" ` | ||
-out "$pwd\Product.msi" ` | ||
-pdbout "$pwd\Product.wixpdb" ` | ||
-cultures:null ` | ||
-ext "$($ENV:WIX)bin\WixUtilExtension.dll" ` | ||
-ext "$($ENV:WIX)bin\WixUIExtension.dll" ` | ||
-ext "$($ENV:WIX)bin\WixNetFxExtension.dll" ` | ||
-sice:ICE03 ` | ||
Service.wixobj ` | ||
Product.wixobj | ||
CheckExitCode "light" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PowerShell -ExecutionPolicy RemoteSigned -File clean.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
function silentdelelete ($path) { | ||
if (Test-Path $path) { | ||
Remove-Item -Recurse -Force $path | ||
} | ||
} | ||
|
||
silentdelelete *.msi | ||
silentdelelete *.log | ||
silentdelelete *.wixpdb | ||
silentdelelete *.wixobj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
msiexec /i Product.msi /l*v Product-install.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
msiexec /x Product.msi /qb! /l*v Product-uninstall.log |