Skip to content

Instantly share code, notes, and snippets.

@samuelcarreira
Last active May 24, 2018 21:04
Show Gist options
  • Save samuelcarreira/4f832a58df62f3522833779a1d9ad8eb to your computer and use it in GitHub Desktop.
Save samuelcarreira/4f832a58df62f3522833779a1d9ad8eb to your computer and use it in GitHub Desktop.
Inno Setup Script - Get Slack notification when someone installs your app
; Get Slack notification when someone installs your app
; by: Samuel Carreira
; -- Basic code from Inno Setup Example1.iss --
#define MyAppVersion "0.1.0"
#define MyAppName "Your App Name"
[Setup]
AppName=My Program
AppVersion=0.1.0
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
Compression=lzma2
SolidCompression=yes
OutputDir=userdocs:Inno Setup Examples Output
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "Readme.txt"; DestDir: "{app}"; Flags: isreadme
[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
myVersion,
json,
WinHttpReq: Variant;
begin
myVersion := '{#SetupSetting("AppVersion")}';
json := '{"text":"[Automatic Message] {#SetupSetting("AppName")} v.{#SetupSetting("AppVersion")} was installed"}';
if CurStep = ssDone then
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('POST', 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', false);
WinHttpReq.setRequestHeader('Content-type', 'application/json');
WinHttpReq.Send(json);
end;
end;
@samuelcarreira
Copy link
Author

To ignore errors:

begin
  try
      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      WinHttpReq.Open('POST', 'https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', false);
      WinHttpReq.setRequestHeader('Content-type', 'application/json');
      WinHttpReq.Send(json);
   except
      // do nothing on error
   end;
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment