Skip to content

Commit 7b89c9a

Browse files
committed
Add examples.
1 parent ce6cb29 commit 7b89c9a

9 files changed

Lines changed: 168 additions & 0 deletions

examples/01-basic-installer.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example: Basic Installer
2+
# This script creates an MSI installer for "My First Product" with a license file.
3+
4+
# Create a sample license.txt file for demonstration
5+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
6+
if (!(Test-Path $licensePath)) {
7+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
8+
}
9+
10+
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
11+
New-InstallerDirectory -PredefinedDirectory "LocalAppDataFolder" -Content {
12+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
13+
New-InstallerFile -Source $licensePath
14+
}
15+
}
16+
} -OutputDirectory (Join-Path $PSScriptRoot "output")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example: All Users Installation
2+
# This script creates an MSI installer for all users (PerMachine) in Program Files.
3+
4+
# Create a sample license.txt file for demonstration
5+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
6+
if (!(Test-Path $licensePath)) {
7+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
8+
}
9+
10+
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
11+
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
12+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
13+
New-InstallerFile -Source $licensePath
14+
}
15+
}
16+
} -OutputDirectory (Join-Path $PSScriptRoot "output") -RequiresElevation
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Example: Installer with Add/Remove Programs Icon
2+
# This script creates an MSI installer with a custom icon for Add/Remove Programs.
3+
4+
# Create a sample license.txt file for demonstration
5+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
6+
if (!(Test-Path $licensePath)) {
7+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
8+
}
9+
10+
# Create a sample icon.ico file for demonstration
11+
$iconPath = Join-Path $PSScriptRoot 'icon.ico'
12+
if (!(Test-Path $iconPath)) {
13+
# Create a blank icon file (not a valid icon, but placeholder for demo)
14+
Set-Content -Path $iconPath -Value $null
15+
}
16+
17+
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
18+
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
19+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
20+
New-InstallerFile -Source $licensePath
21+
}
22+
}
23+
} -OutputDirectory (Join-Path $PSScriptRoot "output") -AddRemoveProgramsIcon $iconPath

examples/04-installer-version.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Example: Installer with Version
2+
# This script creates an MSI installer with a specific version number.
3+
4+
# Create a sample license.txt file for demonstration
5+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
6+
if (!(Test-Path $licensePath)) {
7+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
8+
}
9+
10+
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
11+
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
12+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
13+
New-InstallerFile -Source $licensePath
14+
}
15+
}
16+
} -OutputDirectory (Join-Path $PSScriptRoot "output") -Version 2.0
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Example: Installer with Custom Action
2+
# This script creates an MSI installer that runs a PowerShell script during installation.
3+
4+
# Create a sample custom action script
5+
$customActionPath = Join-Path $PSScriptRoot 'myCustomAction.ps1'
6+
if (!(Test-Path $customActionPath)) {
7+
Set-Content -Path $customActionPath -Value "Write-Host 'Custom action executed during install.'"
8+
}
9+
10+
New-Installer -ProductName "My First Product" -UpgradeCode '1a73a1be-50e6-4e92-af03-586f4a9d9e82' -Content {
11+
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
12+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
13+
New-InstallerFile -Source $customActionPath -Id 'CustomAction'
14+
}
15+
}
16+
} -CustomAction @(
17+
New-InstallerCustomAction -FileId 'CustomAction' -RunOnInstall
18+
) -OutputDirectory (Join-Path $PSScriptRoot "output")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Example: Installer with Configurable Directory
2+
# This script creates an MSI installer with a configurable directory for installation.
3+
4+
# Create a sample license.txt file for demonstration
5+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
6+
if (!(Test-Path $licensePath)) {
7+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
8+
}
9+
10+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
11+
New-InstallerFile -Source $licensePath
12+
} -Configurable

examples/07-shortcut-installer.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Example: Installer with Shortcut
2+
# This script creates an MSI installer with a shortcut on the Desktop to a file.
3+
4+
# Create a sample file for shortcut
5+
$testFilePath = Join-Path $PSScriptRoot 'MyTextFile.txt'
6+
if (!(Test-Path $testFilePath)) {
7+
Set-Content -Path $testFilePath -Value "This is a test file for shortcut."
8+
}
9+
10+
New-Installer -ProductName "My First Product" -UpgradeCode (New-Guid) -Version 1.0.0 -Content {
11+
New-InstallerFile -Source $testFilePath -Id "myTestFile"
12+
New-InstallerDirectory -PredefinedDirectory "DesktopFolder" -Content {
13+
New-InstallerShortcut -Name "My Test File" -FileId "myTestFile"
14+
}
15+
} -OutputDirectory (Join-Path $PSScriptRoot "output")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Example: Installer with Shortcut and Working Directory
2+
# This script creates an MSI installer with a shortcut on the Desktop that sets the working directory.
3+
4+
# Create a sample image file for demonstration
5+
$imagePath = Join-Path $PSScriptRoot 'services.png'
6+
if (!(Test-Path $imagePath)) {
7+
# Create a blank PNG file (not a valid image, but placeholder for demo)
8+
Set-Content -Path $imagePath -Value $null
9+
}
10+
11+
New-Installer -ProductName "MyImage" -UpgradeCode (New-Guid) -Version 1.0.0 -Content {
12+
New-InstallerDirectory -PredefinedDirectoryName ProgramFilesFolder -Content {
13+
New-InstallerDirectory -DirectoryName 'MyDir' -Id 'MyDir' -Content {
14+
New-InstallerFile -Id 'Image' -Source $imagePath
15+
}
16+
}
17+
New-InstallerDirectory -PredefinedDirectoryName DesktopFolder -Content {
18+
New-InstallerShortcut -Name 'Test' -FileId 'Image' -WorkingDirectoryId 'MyDir'
19+
}
20+
} -OutputDirectory (Join-Path $PSScriptRoot "installer") -RequiresElevation
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Example: Installer with Custom User Interface
2+
# This script creates an MSI installer with a custom EULA and graphics.
3+
4+
# Create sample EULA and images for demonstration
5+
$eulaPath = Join-Path $PSScriptRoot 'eula.rtf'
6+
if (!(Test-Path $eulaPath)) {
7+
Set-Content -Path $eulaPath -Value "{\rtf1\ansi\deff0 {\fonttbl {\f0 Arial;}}\f0\fs20 This is a sample EULA.}"
8+
}
9+
$bannerPath = Join-Path $PSScriptRoot 'banner.png'
10+
if (!(Test-Path $bannerPath)) {
11+
Set-Content -Path $bannerPath -Value $null
12+
}
13+
$welcomePath = Join-Path $PSScriptRoot 'welcome.png'
14+
if (!(Test-Path $welcomePath)) {
15+
Set-Content -Path $welcomePath -Value $null
16+
}
17+
18+
$UserInterface = New-InstallerUserInterface -Eula $eulaPath -TopBanner $bannerPath -Welcome $welcomePath
19+
20+
# Create a sample license.txt file for demonstration
21+
$licensePath = Join-Path $PSScriptRoot 'license.txt'
22+
if (!(Test-Path $licensePath)) {
23+
Set-Content -Path $licensePath -Value "This is a sample license file for My First Product."
24+
}
25+
26+
New-Installer -ProductName "My First Product" -UpgradeCode (New-Guid) -Version 1.0.0 -Content {
27+
New-InstallerDirectory -PredefinedDirectory "ProgramFilesFolder" -Content {
28+
New-InstallerDirectory -DirectoryName "My First Product" -Content {
29+
New-InstallerFile -Source $licensePath
30+
}
31+
}
32+
} -UserInterface $UserInterface -OutputDirectory (Join-Path $PSScriptRoot "output")

0 commit comments

Comments
 (0)