diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-30 18:35:58 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-04-30 20:19:50 +0200 |
commit | 5bf363ec2155f64cc9ace90357af9be44a963bd6 (patch) | |
tree | 4c3b882b2c864927b83d87835aa437365d742758 /installer | |
parent | service: inform UIs it is time to quit so they can kill tray (diff) | |
download | wireguard-windows-5bf363ec2155f64cc9ace90357af9be44a963bd6.tar.xz wireguard-windows-5bf363ec2155f64cc9ace90357af9be44a963bd6.zip |
installer: stop/uninstall/start all WireGuard services
Also clean up quite a few things.
Signed-off-by: Simon Rozman <simon@rozman.si>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'installer')
-rw-r--r-- | installer/ca.js | 41 | ||||
-rw-r--r-- | installer/wireguard.wxs | 15 |
2 files changed, 52 insertions, 4 deletions
diff --git a/installer/ca.js b/installer/ca.js new file mode 100644 index 00000000..811d3016 --- /dev/null +++ b/installer/ca.js @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2019 WireGuard LLC. All Rights Reserved. + */ + +function EvaluateWireGuardServices() { + var inst = Session.Installer; + var db = Session.Database; + var view = db.OpenView("INSERT INTO `ServiceControl` (`ServiceControl`, `Name`, `Event`, `Component_`) VALUES(?, ?, ?, ?) TEMPORARY"); + var rec = inst.CreateRecord(4); + var wsh = new ActiveXObject("WScript.Shell"); + var shl = new ActiveXObject("Shell.Application"); + var fso = new ActiveXObject("Scripting.FileSystemObject"); + var serviceKey = "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services"; + var servicePrefix = "WireGuardTunnel$"; + var serviceKeyPrefix = serviceKey + "\\" + servicePrefix; + var allowedNameFormat = new RegExp("^[a-zA-Z0-9_=+.-]{1,32}$"); + var msiOperators = new RegExp("[=+-]", "g"); + var index = 0; + + function insertServiceControl(serviceName) { + rec.StringData (1/*ServiceControl*/) = serviceName.replace(msiOperators, "_") + (index++).toString(); + rec.StringData (2/*Name */) = serviceName; + rec.IntegerData(3/*Event */) = 0x2/*msidbServiceControlEventStop*/ | 0x20/*msidbServiceControlEventUninstallStop*/ | 0x80/*msidbServiceControlEventUninstallDelete*/ | (shl.IsServiceRunning(serviceName) ? 0x1/*msidbServiceControlEventStart*/ : 0); + rec.StringData (4/*Component */) = "WireGuardExecutable"; + + view.Execute(rec); + } + + insertServiceControl("WireGuardManager"); + + var exe = wsh.Exec(fso.BuildPath(fso.GetSpecialFolder(1), "reg.exe") + " QUERY \"" + serviceKey + "\""); + var lines = exe.StdOut.ReadAll().split(new RegExp("\r?\n", "g")); + for (var i = 0; i < lines.length; ++i) { + if (lines[i].length > serviceKeyPrefix.length && lines[i].substring(0, serviceKeyPrefix.length) == serviceKeyPrefix) { + var tunnelName = lines[i].substring(serviceKeyPrefix.length); + if (tunnelName.match(allowedNameFormat) != null) + insertServiceControl(servicePrefix + tunnelName); + } + } +} diff --git a/installer/wireguard.wxs b/installer/wireguard.wxs index da31c3c6..3d4766dc 100644 --- a/installer/wireguard.wxs +++ b/installer/wireguard.wxs @@ -27,12 +27,13 @@ <MediaTemplate EmbedCab="yes" CompressionLevel="high"/> <Icon Id="icon.ico" SourceFile="..\ui\icon\icon.ico"/> + <Binary Id="ca.js" SourceFile="ca.js"/> <Property Id="ARPPRODUCTICON" Value="icon.ico"/> <Property Id="ARPURLINFOABOUT" Value="https://www.wireguard.com/"/> - <Property Id="ARPNOREPAIR" Value="yes" /> <Property Id="ARPNOMODIFY" Value="yes" /> <Property Id="DISABLEADVTSHORTCUTS" Value="yes"/> + <Property Id="MSIRESTARTMANAGERCONTROL" Value="Disable" /> <!-- Upgrading @@ -75,9 +76,7 @@ <File Source="..\$(var.Platform)\wireguard.exe" KeyPath="yes"> <Shortcut Id="WireGuardStartMenuShortcut" Directory="ProgramMenuFolder" Name="WireGuard" Description="WireGuard: Fast, Modern, Secure VPN Tunnel" WorkingDirectory="INSTALLFOLDER" Advertise="yes" /> </File> - <ServiceControl Id="RemoveWireGuardManagerService" Name="WireGuardManager" Remove="both" Stop="both"></ServiceControl> - <ServiceControl Id="RemoveWireGuardTunnelServices" Name="WireGuardTunnel$test" Remove="both" Stop="both"></ServiceControl> - <!-- TODO: "test" is just a temporary hack. We need to enumerate all services that are "WireGuardTunnel$*" and remove those. --> + <ServiceControl Id="DummyService.3AA0C492_29F4_4342_B608_DB95B2DECB13" Name="DummyService.3AA0C492_29F4_4342_B608_DB95B2DECB13"></ServiceControl><!-- A dummy to make WiX create ServiceControl table for us. --> </Component> </ComponentGroup> @@ -99,6 +98,14 @@ </Feature> <!-- + Evaluate WireGuard services and populate ServiceControl table + --> + <CustomAction Id="EvaluateWireGuardServices" BinaryKey="ca.js" JScriptCall="EvaluateWireGuardServices"/> + <InstallExecuteSequence> + <Custom Action="EvaluateWireGuardServices" After="FindRelatedProducts"/> + </InstallExecuteSequence> + + <!-- Launch wireguard.exe after setup complete --> <CustomAction Id="LaunchApplication" HideTarget="yes" Impersonate="no" Execute="deferred" FileKey="wireguard.exe" ExeCommand="" Return="asyncNoWait"/> |