Back to Folder
ID | ee8ee5ad-1df5-4544-a6aa-12e5ff6ff052 |
Filename |
Main.ps1
|
Size | 46.67 KB |
Uploaded | 2025-05-08 07:08:12 |
Downloads | 2 |
MIME Type | text/plain |
Hashes |
- CRC32: 67bf037c
- MD5: 74838e6a177684ecf28336ff37bc6e8f
- SHA1: 5bf02a93871916eb11d15a598f4d6c89069915c2
- SHA256: 7189f80df431c7395d8daba0667a5a217ea4fae268fabad36662738103f1bb09
|
Download file
Preview (text)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Get-Location }
Set-Location -Path $scriptDir
# Check for admin rights
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
[System.Windows.Forms.MessageBox]::Show("This application requires administrative privileges. Please run PowerShell as an administrator.", "Error", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
exit
}
# Set DPI awareness
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class DPI {
[DllImport("user32.dll")]
public static extern int SetProcessDPIAware();
public static void Enable() {
SetProcessDPIAware();
}
}
"@
[DPI]::Enable()
# Enable TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Create main form
$form = New-Object System.Windows.Forms.Form
$form.Text = "Office Click-to-Run URL Generator"
$form.Size = New-Object System.Drawing.Size(1100, 580)
$form.StartPosition = "CenterScreen"
$form.Font = New-Object System.Drawing.Font("Segoe UI", 8)
$form.BackColor = [System.Drawing.Color]::FromArgb(240, 240, 240)
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$form.MaximizeBox = $false
# Create main layout panel
$mainPanel = New-Object System.Windows.Forms.TableLayoutPanel
$mainPanel.Dock = "Fill"
$mainPanel.ColumnCount = 2
$mainPanel.RowCount = 1
$mainPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 65)))
$mainPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 35)))
$mainPanel.Padding = New-Object System.Windows.Forms.Padding(15)
$form.Controls.Add($mainPanel)
# Left panel (Configuration)
$leftPanel = New-Object System.Windows.Forms.Panel
$leftPanel.Dock = "Fill"
$leftPanel.BackColor = [System.Drawing.Color]::White
$leftPanel.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$mainPanel.Controls.Add($leftPanel, 0, 0)
# Right panel (Applications)
$rightPanel = New-Object System.Windows.Forms.Panel
$rightPanel.Dock = "Fill"
$rightPanel.BackColor = [System.Drawing.Color]::FromArgb(245, 245, 245)
$rightPanel.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle
$mainPanel.Controls.Add($rightPanel, 1, 0)
# Left panel content (using a regular Panel for absolute positioning)
$leftContent = New-Object System.Windows.Forms.Panel
$leftContent.Dock = "Fill"
$leftContent.AutoScroll = $true
$leftContent.Padding = New-Object System.Windows.Forms.Padding(15)
$leftPanel.Controls.Add($leftContent)
# Configuration group
$configGroup = New-Object System.Windows.Forms.GroupBox
$configGroup.Text = "Configuration Options"
$configGroup.Size = New-Object System.Drawing.Size(650, 150)
$configGroup.Location = New-Object System.Drawing.Point(15, 15)
$configGroup.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
$leftContent.Controls.Add($configGroup)
$configPanel = New-Object System.Windows.Forms.TableLayoutPanel
$configPanel.Dock = "Fill"
$configPanel.ColumnCount = 4
$configPanel.RowCount = 3
$configPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Absolute, 100)))
$configPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Absolute, 200)))
$configPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Absolute, 100)))
$configPanel.ColumnStyles.Add((New-Object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Absolute, 200)))
$configPanel.RowStyles.Add((New-Object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 33.33)))
$configPanel.RowStyles.Add((New-Object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 33.33)))
$configPanel.RowStyles.Add((New-Object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 33.33)))
$configPanel.Padding = New-Object System.Windows.Forms.Padding(15, 10, 15, 10)
$configGroup.Controls.Add($configPanel)
# Channel ComboBox
$channelLabel = New-Object System.Windows.Forms.Label
$channelLabel.Text = "Channel:"
$channelLabel.Size = New-Object System.Drawing.Size(100, 25)
$channelLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$channelLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($channelLabel, 0, 0)
$channelComboBox = New-Object System.Windows.Forms.ComboBox
$channelComboBox.Size = New-Object System.Drawing.Size(200, 25)
$channelComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$channelComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$channels = @(
"InsiderFast", "MonthlyPreview", "Monthly", "MonthlyEnterprise", "SemiAnnualPreview", "SemiAnnual",
"DogfoodDevMain", "MicrosoftElite", "PerpetualVL2019", "MicrosoftLTSC", "PerpetualVL2021",
"MicrosoftLTSC2021", "PerpetualVL2024", "MicrosoftLTSC2024"
)
$channelComboBox.Items.AddRange($channels)
$channelComboBox.SelectedItem = "PerpetualVL2021"
$configPanel.Controls.Add($channelComboBox, 1, 0)
# Windows Level ComboBox
$levelLabel = New-Object System.Windows.Forms.Label
$levelLabel.Text = "Windows Level:"
$levelLabel.Size = New-Object System.Drawing.Size(100, 25)
$levelLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$levelLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($levelLabel, 2, 0)
$levelComboBox = New-Object System.Windows.Forms.ComboBox
$levelComboBox.Size = New-Object System.Drawing.Size(200, 25)
$levelComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$levelComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$levels = @("Default (Windows 11/10)", "Win7", "Win81")
$levelComboBox.Items.AddRange($levels)
$levelComboBox.SelectedIndex = 0
$configPanel.Controls.Add($levelComboBox, 3, 0)
# Bitness ComboBox
$bitnessLabel = New-Object System.Windows.Forms.Label
$bitnessLabel.Text = "Bitness:"
$bitnessLabel.Size = New-Object System.Drawing.Size(100, 25)
$bitnessLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$bitnessLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($bitnessLabel, 0, 1)
$bitnessComboBox = New-Object System.Windows.Forms.ComboBox
$bitnessComboBox.Size = New-Object System.Drawing.Size(200, 25)
$bitnessComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$bitnessComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$bitness = @("x86", "x64", "x86x64", "x86arm64", "x64arm64")
$bitnessComboBox.Items.AddRange($bitness)
$bitnessComboBox.SelectedItem = "x64"
$configPanel.Controls.Add($bitnessComboBox, 1, 1)
# Language ComboBox
$languageLabel = New-Object System.Windows.Forms.Label
$languageLabel.Text = "Language:"
$languageLabel.Size = New-Object System.Drawing.Size(100, 25)
$languageLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$languageLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($languageLabel, 2, 1)
$languageComboBox = New-Object System.Windows.Forms.ComboBox
$languageComboBox.Size = New-Object System.Drawing.Size(200, 25)
$languageComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$languageComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$languages = @(
"en-US", "ar-SA", "bg-BG", "cs-CZ", "da-DK", "de-DE", "el-GR", "es-ES", "et-EE",
"fi-FI", "fr-FR", "he-IL", "hr-HR", "hu-HU", "it-IT", "ja-JP", "ko-KR", "lt-LT",
"lv-LV", "nb-NO", "nl-NL", "pl-PL", "pt-BR", "pt-PT", "ro-RO", "ru-RU", "sk-SK",
"sl-SI", "sr-Latn-RS", "sv-SE", "th-TH", "tr-TR", "uk-UA", "zh-CN", "zh-TW",
"hi-IN", "id-ID", "kk-KZ", "MS-MY", "vi-VN", "en-GB", "es-MX", "fr-CA"
)
$languageComboBox.Items.AddRange($languages)
$languageComboBox.SelectedItem = "tr-TR"
$configPanel.Controls.Add($languageComboBox, 3, 1)
# Product Type ComboBox
$productLabel = New-Object System.Windows.Forms.Label
$productLabel.Text = "Product Type:"
$productLabel.Size = New-Object System.Drawing.Size(100, 25)
$productLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$productLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($productLabel, 0, 2)
$productComboBox = New-Object System.Windows.Forms.ComboBox
$productComboBox.Size = New-Object System.Drawing.Size(200, 25)
$productComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$productComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$products = @("Full Office Source", "Language Pack", "Proofing Tools")
$productComboBox.Items.AddRange($products)
$productComboBox.SelectedItem = "Full Office Source"
$configPanel.Controls.Add($productComboBox, 1, 2)
# Output Type ComboBox
$outputLabel = New-Object System.Windows.Forms.Label
$outputLabel.Text = "Output Type:"
$outputLabel.Size = New-Object System.Drawing.Size(100, 25)
$outputLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleLeft
$outputLabel.Margin = New-Object System.Windows.Forms.Padding(5)
$configPanel.Controls.Add($outputLabel, 2, 2)
$outputComboBox = New-Object System.Windows.Forms.ComboBox
$outputComboBox.Size = New-Object System.Drawing.Size(200, 25)
$outputComboBox.DropDownStyle = [System.Windows.Forms.ComboBoxStyle]::DropDownList
$outputComboBox.Margin = New-Object System.Windows.Forms.Padding(5)
$outputs = @("Aria2 script", "Wget script", "cURL script", "Text file")
$outputComboBox.Items.AddRange($outputs)
$outputComboBox.SelectedItem = "Aria2 script"
$configPanel.Controls.Add($outputComboBox, 3, 2)
# Buttons panel (below Configuration group)
$buttonsPanel = New-Object System.Windows.Forms.Panel
$buttonsPanel.Size = New-Object System.Drawing.Size(670, 60)
$buttonsPanel.Location = New-Object System.Drawing.Point(5, 380)
$buttonsPanel.Padding = New-Object System.Windows.Forms.Padding(0, 10, 0, 0)
$leftContent.Controls.Add($buttonsPanel)
# Generate Button
$generateButton = New-Object System.Windows.Forms.Button
$generateButton.Text = "Generate"
$generateButton.Size = New-Object System.Drawing.Size(315, 30)
$generateButton.Location = New-Object System.Drawing.Point(10, 10)
$generateButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$generateButton.BackColor = [System.Drawing.Color]::Gray
$generateButton.ForeColor = [System.Drawing.Color]::White
$generateButton.Font = New-Object System.Drawing.Font("Segoe UI", 8, [System.Drawing.FontStyle]::Bold)
$buttonsPanel.Controls.Add($generateButton)
# Add Configuration XML Button
$xmlButton = New-Object System.Windows.Forms.Button
$xmlButton.Text = "Add Configuration XML"
$xmlButton.Size = New-Object System.Drawing.Size(315, 30) # 300'den 305'e değiştirildi, Generate ile aynı boyutta
$xmlButton.Location = New-Object System.Drawing.Point(345, 10) # 360'tan 325'e değiştirildi, aradaki mesafe azaltıldı
$xmlButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$xmlButton.BackColor = [System.Drawing.Color]::Gray
$xmlButton.ForeColor = [System.Drawing.Color]::White
$xmlButton.Font = New-Object System.Drawing.Font("Segoe UI", 8, [System.Drawing.FontStyle]::Bold)
$buttonsPanel.Controls.Add($xmlButton)
# Progress Bar (below Buttons panel)
$progressBar = New-Object System.Windows.Forms.ProgressBar
$progressBar.Size = New-Object System.Drawing.Size(650, 20)
$progressBar.Location = New-Object System.Drawing.Point(15, 440)
$progressBar.Style = "Continuous"
$progressBar.Visible = $false
$leftContent.Controls.Add($progressBar)
# Summary group (below Progress Bar)
$summaryGroup = New-Object System.Windows.Forms.GroupBox
$summaryGroup.Text = "Summary"
$summaryGroup.Size = New-Object System.Drawing.Size(650, 200)
$summaryGroup.Location = New-Object System.Drawing.Point(15, 180)
$summaryGroup.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
$leftContent.Controls.Add($summaryGroup)
$summaryTextBox = New-Object System.Windows.Forms.RichTextBox
$summaryTextBox.Dock = "Fill"
$summaryTextBox.ReadOnly = $true
$summaryTextBox.BackColor = [System.Drawing.Color]::FromArgb(250, 250, 250)
$summaryTextBox.BorderStyle = [System.Windows.Forms.BorderStyle]::None
$summaryTextBox.Font = New-Object System.Drawing.Font("Segoe UI", 8)
$summaryTextBox.ScrollBars = [System.Windows.Forms.RichTextBoxScrollBars]::Vertical
$summaryTextBox.Padding = New-Object System.Windows.Forms.Padding(10)
$summaryGroup.Controls.Add($summaryTextBox)
# Error Label (below Summary group)
$errorLabel = New-Object System.Windows.Forms.Label
$errorLabel.Size = New-Object System.Drawing.Size(650, 40)
$errorLabel.Location = New-Object System.Drawing.Point(15, 460)
$errorLabel.ForeColor = [System.Drawing.Color]::Red
$errorLabel.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
$leftContent.Controls.Add($errorLabel)
# Right panel content
$rightContent = New-Object System.Windows.Forms.FlowLayoutPanel
$rightContent.Dock = "Fill"
$rightContent.FlowDirection = "TopDown"
$rightContent.AutoScroll = $true
$rightContent.Padding = New-Object System.Windows.Forms.Padding(15)
$rightPanel.Controls.Add($rightContent)
# Office Applications group
$officeAppsGroup = New-Object System.Windows.Forms.GroupBox
$officeAppsGroup.Text = "Office Applications"
$officeAppsGroup.Size = New-Object System.Drawing.Size(350, 180)
$officeAppsGroup.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
$rightContent.Controls.Add($officeAppsGroup)
$officeAppsPanel = New-Object System.Windows.Forms.FlowLayoutPanel
$officeAppsPanel.Dock = "Fill"
$officeAppsPanel.FlowDirection = "TopDown"
$officeAppsPanel.AutoScroll = $true
$officeAppsPanel.Padding = New-Object System.Windows.Forms.Padding(10)
$officeAppsGroup.Controls.Add($officeAppsPanel)
$global:officeAppCheckboxes = @{}
$officeApps = @(
@{ Name = "Word"; Default = $true },
@{ Name = "Excel"; Default = $true },
@{ Name = "PowerPoint"; Default = $true },
@{ Name = "Outlook"; Default = $true },
@{ Name = "Access"; Default = $false },
@{ Name = "Publisher"; Default = $false },
@{ Name = "OneNote"; Default = $false },
@{ Name = "Teams"; Default = $false },
@{ Name = "Lync"; Default = $false },
@{ Name = "Groove"; Default = $false },
@{ Name = "Bing"; Default = $false }
)
foreach ($app in $officeApps) {
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $app.Name
$checkbox.Checked = $app.Default
$checkbox.AutoSize = $true
$checkbox.Margin = New-Object System.Windows.Forms.Padding(5)
$global:officeAppCheckboxes[$app.Name] = $checkbox
$officeAppsPanel.Controls.Add($checkbox)
}
# Additional Products group
$additionalProductsGroup = New-Object System.Windows.Forms.GroupBox
$additionalProductsGroup.Text = "Additional Products"
$additionalProductsGroup.Size = New-Object System.Drawing.Size(340, 120)
$additionalProductsGroup.Font = New-Object System.Drawing.Font("Segoe UI", 9, [System.Drawing.FontStyle]::Bold)
$rightContent.Controls.Add($additionalProductsGroup)
$additionalProductsPanel = New-Object System.Windows.Forms.FlowLayoutPanel
$additionalProductsPanel.Dock = "Fill"
$additionalProductsPanel.FlowDirection = "TopDown"
$additionalProductsPanel.AutoScroll = $true
$additionalProductsPanel.Padding = New-Object System.Windows.Forms.Padding(10)
$additionalProductsGroup.Controls.Add($additionalProductsPanel)
$global:additionalProductsCheckboxes = @{}
$additionalProducts = @(
@{ Name = "Visio"; Default = $true },
@{ Name = "Project"; Default = $true }
)
foreach ($product in $additionalProducts) {
$checkbox = New-Object System.Windows.Forms.CheckBox
$checkbox.Text = $product.Name
$checkbox.Checked = $product.Default
$checkbox.AutoSize = $true
$checkbox.Margin = New-Object System.Windows.Forms.Padding(5)
$global:additionalProductsCheckboxes[$product.Name] = $checkbox
$additionalProductsPanel.Controls.Add($checkbox)
}
# Helper Dictionaries
$ffnGuids = @{
"InsiderFast" = "5440fd1f-7ecb-4221-8110-145efaa6372f"
"MonthlyPreview" = "64256afe-f5d9-4f86-8936-8840a6a4f5be"
"Monthly" = "492350f6-3a01-4f97-b9c0-c7c6ddf67d60"
"MonthlyEnterprise" = "55336b82-a18d-4dd6-b5f6-9e5095c314a6"
"SemiAnnualPreview" = "b8f9b850-328d-4355-9145-c59439a0c4cf"
"SemiAnnual" = "7ffbc6bf-bc32-4f92-8982-f9dd17fd3114"
"DogfoodDevMain" = "ea4a4090-de26-49d7-93c1-91bff9e53fc3"
"MicrosoftElite" = "b61285dd-d9f7-41f2-9757-8f61cba4e9c8"
"PerpetualVL2019" = "f2e724c1-748f-4b47-8fb8-8e0d210e9208"
"MicrosoftLTSC" = "1d2d2ea6-1680-4c56-ac58-a441c8c24ff9"
"PerpetualVL2021" = "5030841d-c919-4594-8d2d-84ae4f96e58e"
"MicrosoftLTSC2021" = "86752282-5841-4120-ac80-db03ae6b5fdb"
"PerpetualVL2024" = "7983bac0-e531-40cf-be00-fd24fe66619c"
"MicrosoftLTSC2024" = "c02d8fe6-5242-4da8-972f-82ee55e00671"
}
$lcids = @{
"en-US" = "1033"; "ar-SA" = "1025"; "bg-BG" = "1026"; "cs-CZ" = "1029"; "da-DK" = "1030";
"de-DE" = "1031"; "el-GR" = "1032"; "es-ES" = "3082"; "et-EE" = "1061"; "fi-FI" = "1035";
"fr-FR" = "1036"; "he-IL" = "1037"; "hr-HR" = "1050"; "hu-HU" = "1038"; "it-IT" = "1040";
"ja-JP" = "1041"; "ko-KR" = "1042"; "lt-LT" = "1063"; "lv-LV" = "1062"; "nb-NO" = "1044";
"nl-NL" = "1043"; "pl-PL" = "1045"; "pt-BR" = "1046"; "pt-PT" = "2070"; "ro-RO" = "1048";
"ru-RU" = "1049"; "sk-SK" = "1051"; "sl-SI" = "1060"; "sr-Latn-RS" = "9242"; "sv-SE" = "1053";
"th-TH" = "1054"; "tr-TR" = "1055"; "uk-UA" = "1058"; "zh-CN" = "2052"; "zh-TW" = "1028";
"hi-IN" = "1081"; "id-ID" = "1057"; "kk-KZ" = "1087"; "MS-MY" = "1086"; "vi-VN" = "1066";
"en-GB" = "2057"; "es-MX" = "2058"; "fr-CA" = "3084"
}
$bitnessMap = @{
"x86" = @("x86", "32")
"x64" = @("x64", "64")
"x86x64" = @("x86", "32")
"x86arm64" = @("x86", "32")
"x64arm64" = @("x64", "64")
}
# Global Variables
$global:vvv = $null
$global:utc = $null
# Update Summary
$updateSummary = {
$summary = "Channel: $($channelComboBox.SelectedItem)`r`n"
$summary += "Version: $(if ($global:vvv) { $global:vvv } else { '-' })`r`n"
$summary += "Updated: $(if ($global:utc) { $global:utc } else { '-' })`r`n"
$summary += "Bitness: $($bitnessComboBox.SelectedItem)`r`n"
$summary += "Language: $($languageComboBox.SelectedItem)`r`n"
$summary += "Product: $($productComboBox.SelectedItem)`r`n"
$summary += "Output: $($outputComboBox.SelectedItem)`r`n"
$selectedApps = ($global:officeAppCheckboxes.GetEnumerator() | Where-Object { $_.Value.Checked } | ForEach-Object { $_.Key }) -join ", "
$summary += "Selected Apps: $selectedApps`r`n"
$selectedProducts = ($global:additionalProductsCheckboxes.GetEnumerator() | Where-Object { $_.Value.Checked } | ForEach-Object { $_.Key }) -join ", "
$summary += "Additional Products: $selectedProducts"
$summaryTextBox.Text = $summary
}
# Write Log to Summary
$writeLog = {
param (
[string]$Message,
[string]$Color = "Black"
)
$timestamp = Get-Date -Format "HH:mm:ss"
$formattedMessage = "[$timestamp] $Message"
$summaryTextBox.SelectionStart = $summaryTextBox.TextLength
$summaryTextBox.SelectionLength = 0
$summaryTextBox.SelectionColor = [System.Drawing.Color]::FromName($Color)
$summaryTextBox.AppendText("$formattedMessage`r`n")
$summaryTextBox.SelectionColor = [System.Drawing.Color]::Black
$summaryTextBox.ScrollToCaret()
$form.Refresh()
}
# Event Handlers for Summary Updates
$channelComboBox.Add_SelectedIndexChanged($updateSummary)
$levelComboBox.Add_SelectedIndexChanged($updateSummary)
$bitnessComboBox.Add_SelectedIndexChanged($updateSummary)
$languageComboBox.Add_SelectedIndexChanged($updateSummary)
$productComboBox.Add_SelectedIndexChanged($updateSummary)
$outputComboBox.Add_SelectedIndexChanged($updateSummary)
foreach ($checkbox in $global:officeAppCheckboxes.Values) {
$checkbox.Add_CheckedChanged($updateSummary)
}
foreach ($checkbox in $global:additionalProductsCheckboxes.Values) {
$checkbox.Add_CheckedChanged($updateSummary)
}
# Generate Button Click
$generateButton.Add_Click({
try {
$errorLabel.Text = ""
$progressBar.Visible = $true
$progressBar.Value = 0
if (-not $channelComboBox.SelectedItem -or
-not $levelComboBox.SelectedItem -or
-not $bitnessComboBox.SelectedItem -or
-not $languageComboBox.SelectedItem -or
-not $productComboBox.SelectedItem -or
-not $outputComboBox.SelectedItem) {
$errorLabel.Text = "Please select all required options"
$progressBar.Visible = $false
return
}
$progressBar.Value = 10
&$writeLog "Starting script generation..."
$channel = $channelComboBox.SelectedItem
$level = $levelComboBox.SelectedItem
$bitness = $bitnessComboBox.SelectedItem
$language = $languageComboBox.SelectedItem
$product = $productComboBox.SelectedItem
$outputType = $outputComboBox.SelectedItem
&$writeLog "Selected options: Channel=$channel, Bitness=$bitness, Language=$language, Product=$product, Output=$outputType" "Blue"
if (-not $ffnGuids.ContainsKey($channel)) {
&$writeLog "Error: Invalid channel selected: $channel" "Red"
$errorLabel.Text = "Invalid channel selected"
$progressBar.Visible = $false
return
}
$ffn = $ffnGuids[$channel]
$lcid = $lcids[$language]
$arch = $bitnessMap[$bitness][0]
$bit = $bitnessMap[$bitness][1]
$isDual = ($bitness -eq "x86x64")
$isChpe = ($bitness -eq "x86arm64")
$isXarm = ($bitness -eq "x64arm64")
$isFull = ($product -eq "Full Office Source")
$isProof = ($product -eq "Proofing Tools")
$osver = $null
if ($level -eq "Win7") {
$osver = "6.1"
} elseif ($level -eq "Win81") {
$osver = "6.3"
}
# Fetch version info
try {
$url = "https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData?audienceFFN=$ffn"
if ($osver) {
$url += "&osver=Client|$osver"
}
&$writeLog "Fetching version from: $url" "Blue"
$response = Invoke-WebRequest -Uri $url -UseBasicParsing -TimeoutSec 30
$json = ConvertFrom-Json $response.Content
$global:vvv = $json.AvailableBuild
$global:utc = $json.TimestampUtc
if (-not $global:vvv) {
throw "No version information returned from server."
}
&$writeLog "Fetched version: $global:vvv, Timestamp: $global:utc" "Green"
}
catch {
&$writeLog "Failed to fetch version info: $($_.Exception.Message)" "Red"
$global:vvv = "UnknownVersion"
$global:utc = "Unknown"
}
$progressBar.Value = 30
&$writeLog "Using version: $global:vvv, bitness: $bitness" "Blue"
$baseUrl = "https://officecdn.microsoft.com/db/$ffn/Office/Data"
$setupUrl = "https://officecdn.microsoft.com/db/492350f6-3a01-4f97-b9c0-c7c6ddf67d60/Office/Data"
$proofSetupUrl = "https://officecdn.microsoft.com/db/wsus"
$tag = "$global:vvv`_$bitness`_$language`_$channel"
&$writeLog "Constructed tag: $tag" "Blue"
if (-not $isFull) {
$tag += if ($isProof) { "_Proofing" } else { "_LangPack" }
}
if ($level -eq "Win7") {
$tag += "_W7"
} elseif ($level -eq "Win81") {
$tag += "_W81"
}
$outputFile = "$tag"
$outputFile += switch ($outputType) {
"Aria2 script" { "_aria2.cmd" }
"Wget script" { "_wget.cmd" }
"cURL script" { "_curl.cmd" }
default { ".txt" }
}
&$writeLog "Output file name: $outputFile" "Blue"
$outputContent = @()
$destDir = "C2R_$channel"
$files = @()
if ($isProof) {
$files += "sp$bit$lcid.cab", "i${bit}0.cab", "s${bit}0.cab", "stream.$arch.$language.proof.dat"
if (-not ($isXarm -or $isChpe -or $isDual) -and $arch -eq "x86") {
$files += "i640.cab"
}
if ($isDual) {
$files += "sp64$lcid.cab", "i640.cab", "s640.cab", "stream.x64.$language.proof.dat"
}
} else {
$files += "i${bit}$lcid.cab", "s${bit}$lcid.cab", "i${bit}0.cab", "s${bit}0.cab", "stream.$arch.$language.dat"
if ($isChpe) {
$files += "sc320.cab", "stream.x86.x-none.chpe.dat"
}
if ($isXarm) {
$files += "sa640.cab", "stream.x64.x-none.arm64x.dat"
}
if (-not ($isXarm -or $isChpe -or $isDual) -and $arch -eq "x86") {
$files += "i64$lcid.cab", "i640.cab"
}
if ($isFull) {
$files += "stream.$arch.x-none.dat"
}
if ($isDual) {
$files += "i64$lcid.cab", "s64$lcid.cab", "i640.cab", "s640.cab", "stream.x64.$language.dat"
if ($isFull) {
$files += "stream.x64.x-none.dat"
}
}
}
if ($outputType -eq "Aria2 script") {
$outputContent += @"
@echo off
:: Limit the download speed, example: 1M, 500K "0 = unlimited"
set "speedLimit=0"
:: Set the number of parallel downloads
set "parallel=1"
set "_work=%~dp0"
set "_work=%_work:~0,-1%"
set "_batn=%~nx0"
setlocal EnableDelayedExpansion
pushd "!_work!"
set exist=0
if exist "aria2c.exe" set exist=1
for %%i in (aria2c.exe) do @if not "%%~$PATH:i"=="" set exist=1
if !exist!==0 echo.&&echo Error: aria2c.exe is not detected&&echo.&&popd&&pause&&exit /b
set "destDir=$destDir"
set "uri=temp_aria2.txt"
echo Downloading...
echo.
if exist "%uri%" del /f /q "%uri%"
"@
$outputContent += "("
$outputContent += "echo $baseUrl/v${bit}_$global:vvv.cab"
$outputContent += "echo out=Office\Data\v$bit.cab"
$outputContent += "echo."
$outputContent += "echo $baseUrl/v${bit}_$global:vvv.cab"
$outputContent += "echo out=Office\Data\v${bit}_$global:vvv.cab"
$outputContent += "echo."
foreach ($file in $files) {
$outputContent += "echo $baseUrl/$global:vvv/$file"
$outputContent += "echo out=Office\Data\$global:vvv\$file"
$outputContent += "echo."
}
if ($isDual) {
$outputContent += "echo $baseUrl/v64_$global:vvv.cab"
$outputContent += "echo out=Office\Data\v64.cab"
$outputContent += "echo."
$outputContent += "echo $baseUrl/v64_$global:vvv.cab"
$outputContent += "echo out=Office\Data\v64_$global:vvv.cab"
$outputContent += "echo."
}
if (-not $isFull) {
$outputContent += "echo $setupUrl/SetupLanguagePack.$arch.$language.exe"
$outputContent += "echo out=SetupLanguagePack.$arch.$language.exe"
$outputContent += "echo."
if ($isDual) {
$outputContent += "echo $setupUrl/SetupLanguagePack.x64.$language.exe"
$outputContent += "echo out=SetupLanguagePack.x64.$language.exe"
$outputContent += "echo."
}
}
if ($isFull -or $isProof) {
$outputContent += "echo $proofSetupUrl/Setup.exe"
$outputContent += "echo out=Setup.exe"
$outputContent += "echo."
}
$outputContent += ") > `"%uri%`""
$outputContent += "aria2c.exe -x16 -s16 -j%parallel% -c -R --max-overall-download-limit=%speedLimit% -d`"%destDir%`" -i`"%uri%`""
$outputContent += "if exist `"%uri%`" del /f /q `"%uri%`""
$outputContent += "echo."
$outputContent += "echo Done."
$outputContent += "echo Press any key to exit."
$outputContent += "popd"
$outputContent += "pause >nul"
$outputContent += "exit /b"
} elseif ($outputType -eq "Wget script") {
$outputContent += @"
@echo off
:: Limit the download speed, example: 1M, 500K "0 = unlimited"
set "speedLimit=0"
set "_work=%~dp0"
set "_work=%_work:~0,-1%"
set "_batn=%~nx0"
setlocal EnableDelayedExpansion
pushd "!_work!"
set exist=0
if exist "wget.exe" set exist=1
for %%i in (wget.exe) do @if not "%%~$PATH:i"=="" set exist=1
if !exist!==0 echo.&&echo Error: wget.exe is not detected&&echo.&&popd&&pause&&exit /b
set "destDir=$destDir"
set "uri=temp_wget.txt"
echo Downloading...
echo.
if exist "%uri%" del /f /q "%uri%"
call :GenTXT TXinfo > "%uri%"
wget.exe --limit-rate=%speedLimit% --directory-prefix="%destDir%" --input-file="%uri%" --no-verbose --show-progress --progress=bar:force:noscroll --continue --retry-connrefused --tries=5 --ignore-case --force-directories --no-host-directories --cut-dirs=2
if exist "%destDir%\Office\Data\v32_*.cab" xcopy /cqry "%destDir%\Office\Data\v32_*.cab" "%destDir%\Office\Data\v32.cab*"
if exist "%destDir%\Office\Data\v64_*.cab" xcopy /cqry "%destDir%\Office\Data\v64_*.cab" "%destDir%\Office\Data\v64.cab*"
if exist "%destDir%\Office\Data\SetupLanguagePack*.exe" move /y "%destDir%\Office\Data\SetupLanguagePack*.exe" "%destDir%\"
"@
if ($isProof) {
$outputContent += "if exist `"$global:vvv`_x86_$language`_Proofing.xml`" move /y `"$global:vvv`_x86_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x86.xml`""
if ($isDual) {
$outputContent += "if exist `"$global:vvv`_x64_$language`_Proofing.xml`" move /y `"$global:vvv`_x64_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x64.xml`""
}
}
$outputContent += @"
echo.
echo Done.
echo Press any key to exit.
popd
pause >nul
exit /b
:GenTXT
set [=&for /f "delims=:" %%s in ('findstr /nbrc:":%~1:\[" /c:":%~1:\]" "!_batn!"') do if defined [ (set /a ]=%%s-3) else set /a [=%%s-1
<"!_batn!" ((for /l %%i in (0 1 %[%) do set /p =)&for /l %%i in (%[% 1 %]%) do (set txt=&set /p txt=&echo(!txt!)) &exit/b
:TXinfo:[
"@
$outputContent += "$baseUrl/v${bit}_$global:vvv.cab"
foreach ($file in $files) {
$outputContent += "$baseUrl/$global:vvv/$file"
}
if ($isDual) {
$outputContent += "$baseUrl/v64_$global:vvv.cab"
}
if (-not $isFull) {
$outputContent += "$setupUrl/SetupLanguagePack.$arch.$language.exe"
if ($isDual) {
$outputContent += "$setupUrl/SetupLanguagePack.x64.$language.exe"
}
}
if ($isFull -or $isProof) {
$outputContent += "$proofSetupUrl/Setup.exe"
}
$outputContent += ":TXinfo:]"
$outputContent += "exit /b"
} elseif ($outputType -eq "cURL script") {
$outputContent += @"
@echo off
:: Limit the download speed, example: 1M, 500K "empty means unlimited"
set speedLimit=
set "_work=%~dp0"
set "_work=%_work:~0,-1%"
set "_batn=%~nx0"
setlocal EnableDelayedExpansion
pushd "!_work!"
set exist=0
if exist "curl.exe" set exist=1
for %%i in (curl.exe) do @if not "%%~$PATH:i"=="" set exist=1
if !exist!==0 echo.&&echo Error: curl.exe is not detected&&echo.&&popd&&pause&&exit /b
set "uri=temp_curl.txt"
if defined speedLimit set "speedLimit=--limit-rate %speedLimit%"
echo Downloading...
echo.
if exist "%uri%" del /f /q "%uri%"
call :GenTXT TXinfo > "%uri%"
curl.exe -q --create-dirs --retry 5 --retry-connrefused %speedLimit% -k -L -C - -K "%uri%"
if exist "%uri%" del /f /q "%uri%"
"@
if ($isProof) {
$outputContent += "if exist `"$global:vvv`_x86_$language`_Proofing.xml`" move /y `"$global:vvv`_x86_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x86.xml`""
if ($isDual) {
$outputContent += "if exist `"$global:vvv`_x64_$language`_Proofing.xml`" move /y `"$global:vvv`_x64_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x64.xml`""
}
}
$outputContent += @"
echo.
echo Done.
echo Press any key to exit.
popd
pause >nul
exit /b
:GenTXT
set [=&for /f "delims=:" %%s in ('findstr /nbrc:":%~1:\[" /c:":%~1:\]" "!_batn!"') do if defined [ (set /a ]=%%s-3) else set /a [=%%s-1
<"!_batn!" ((for /l %%i in (0 1 %[%) do set /p =)&for /l %%i in (%[% 1 %]%) do (set txt=&set /p txt=&echo(!txt!)) &exit/b
:TXinfo:[
"@
$outputContent += "url $baseUrl/v${bit}_$global:vvv.cab"
$outputContent += "-o $destDir\Office\Data\v$bit.cab"
$outputContent += "url $baseUrl/v${bit}_$global:vvv.cab"
$outputContent += "-o $destDir\Office\Data\v${bit}_$global:vvv.cab"
foreach ($file in $files) {
$outputContent += "url $baseUrl/$global:vvv/$file"
$outputContent += "-o $destDir\Office\Data\$global:vvv\$file"
}
if ($isDual) {
$outputContent += "url $baseUrl/v64_$global:vvv.cab"
$outputContent += "-o $destDir\Office\Data\v64.cab"
$outputContent += "url $baseUrl/v64_$global:vvv.cab"
$outputContent += "-o $destDir\Office\Data\v64.cab"
}
if (-not $isFull) {
$outputContent += "url $setupUrl/SetupLanguagePack.$arch.$language.exe"
$outputContent += "-o $destDir\SetupLanguagePack.$arch.$language.exe"
if ($isDual) {
$outputContent += "url $setupUrl/SetupLanguagePack.x64.$language.exe"
$outputContent += "-o $destDir\SetupLanguagePack.x64.$language.exe"
}
}
if ($isFull -or $isProof) {
$outputContent += "url $proofSetupUrl/Setup.exe"
$outputContent += "-o $destDir\Setup.exe"
}
$outputContent += ":TXinfo:]"
$outputContent += "exit /b"
} else {
$outputContent += "$baseUrl/v${bit}_$global:vvv.cab"
foreach ($file in $files) {
$outputContent += "$baseUrl/$global:vvv/$file"
}
if ($isDual) {
$outputContent += "$baseUrl/v64_$global:vvv.cab"
}
if (-not $isFull) {
$outputContent += "$setupUrl/SetupLanguagePack.$arch.$language.exe"
if ($isDual) {
$outputContent += "$setupUrl/SetupLanguagePack.x64.$language.exe"
}
}
if ($isFull -or $isProof) {
$outputContent += "$proofSetupUrl/Setup.exe"
}
}
if ($isProof) {
$xmlContent = @"
<Configuration>
<Add OfficeClientEdition="$bit">
<Product ID="ProofingTools">
<Language ID="$language"/>
</Product>
</Add>
</Configuration>
"@
$xmlFile = "$global:vvv`_x86_$language`_Proofing.xml"
$xmlContent | Out-File -FilePath $xmlFile -Encoding UTF8
if (Test-Path -Path $xmlFile) {
&$writeLog "Successfully generated XML: $xmlFile" "Green"
} else {
&$writeLog "Failed to generate XML: $xmlFile" "Red"
}
if ($isDual) {
$xmlContent = $xmlContent -replace "OfficeClientEdition=`"$bit`"", "OfficeClientEdition=`"64`""
$xmlFile = "$global:vvv`_x64_$language`_Proofing.xml"
$xmlContent | Out-File -FilePath $xmlFile -Encoding UTF8
if (Test-Path -Path $xmlFile) {
&$writeLog "Successfully generated XML: $xmlFile" "Green"
} else {
&$writeLog "Failed to generate XML: $xmlFile" "Red"
}
}
}
if ($isFull) {
$bitXml = if ($bitness -eq "x64") { "64" } else { "32" }
$excludedApps = $global:officeAppCheckboxes.GetEnumerator() | Where-Object { -not $_.Value.Checked } | ForEach-Object { $_.Key }
$includeVisio = $global:additionalProductsCheckboxes["Visio"].Checked
$includeProject = $global:additionalProductsCheckboxes["Project"].Checked
$productId = switch ($channel) {
{ $_ -in @("InsiderFast", "MonthlyPreview", "Monthly", "MonthlyEnterprise", "SemiAnnualPreview", "SemiAnnual", "DogfoodDevMain", "MicrosoftElite") } { "O365ProPlusRetail" }
"PerpetualVL2024" { "ProPlus2024Volume" }
"MicrosoftLTSC2024" { "ProPlus2024Volume" }
"PerpetualVL2021" { "ProPlus2021Volume" }
"MicrosoftLTSC2021" { "ProPlus2021Volume" }
"PerpetualVL2019" { "ProPlus2019Volume" }
"MicrosoftLTSC" { "ProPlus2019Volume" }
default { "O365ProPlusRetail" }
}
$visioId = switch ($channel) {
"PerpetualVL2024" { "VisioPro2024Volume" }
"MicrosoftLTSC2024" { "VisioPro2024Volume" }
"PerpetualVL2021" { "VisioPro2021Volume" }
"MicrosoftLTSC2021" { "VisioPro2021Volume" }
"PerpetualVL2019" { "VisioPro2019Volume" }
"MicrosoftLTSC" { "VisioPro2019Volume" }
default { "VisioProRetail" }
}
$projectId = switch ($channel) {
"PerpetualVL2024" { "ProjectPro2024Volume" }
"MicrosoftLTSC2024" { "ProjectPro2024Volume" }
"PerpetualVL2021" { "ProjectPro2021Volume" }
"MicrosoftLTSC2021" { "ProjectPro2021Volume" }
"PerpetualVL2019" { "ProjectPro2019Volume" }
"MicrosoftLTSC" { "ProjectPro2019Volume" }
default { "ProjectProRetail" }
}
$xmlContent = @"
<Configuration ID="$(New-Guid)">
<Add OfficeClientEdition="$bitXml" Channel="$channel" AllowCdnFallback="TRUE">
<Product ID="$productId">
<Language ID="$language" />
$(
if ($excludedApps) {
($excludedApps | ForEach-Object { " <ExcludeApp ID=`"$_`" />" }) -join "`n"
}
)
</Product>
$(
if ($includeVisio) {
@"
<Product ID="$visioId">
<Language ID="$language" />
$(
if ($excludedApps) {
($excludedApps | ForEach-Object { " <ExcludeApp ID=`"$_`" />" }) -join "`n"
}
)
</Product>
"@
}
)
$(
if ($includeProject) {
@"
<Product ID="$projectId">
<Language ID="$language" />
$(
if ($excludedApps) {
($excludedApps | ForEach-Object { " <ExcludeApp ID=`"$_`" />" }) -join "`n"
}
)
</Product>
"@
}
)
</Add>
<Property Name="SharedComputerLicensing" Value="0" />
<Property Name="FORCEAPPSHUTDOWN" Value="TRUE" />
<Property Name="DeviceBasedLicensing" Value="0" />
<Property Name="SCLCacheOverride" Value="0" />
<Property Name="AUTOACTIVATE" Value="1" />
<Updates Enabled="TRUE" />
<RemoveMSI />
<Display Level="Full" AcceptEULA="TRUE" />
</Configuration>
"@
if (-not (Test-Path -Path $destDir)) {
New-Item -Path $destDir -ItemType Directory -Force | Out-Null
&$writeLog "Created output directory: $destDir" "Green"
}
$xmlFile = Join-Path $destDir "Configuration.xml"
$xmlContent | Out-File -FilePath $xmlFile -Encoding UTF8 -Force
if (Test-Path -Path $xmlFile) {
&$writeLog "Successfully generated Configuration XML: $xmlFile" "Green"
$setupCmdContent = @"
@echo off
setlocal
set "setupPath=%~dp0setup.exe"
set "configPath=%~dp0Configuration.xml"
if not exist "%setupPath%" (
echo Error: setup.exe not found in current directory
pause
exit /b 1
)
if not exist "%configPath%" (
echo Error: Configuration.xml not found in current directory
pause
exit /b 1
)
echo Starting Office installation...
"%setupPath%" /configure "%configPath%"
if %errorlevel% equ 0 (
echo Installation completed successfully
) else (
echo Installation failed with error code %errorlevel%
)
pause
"@
$setupCmdFile = Join-Path $destDir "setup.cmd"
$setupCmdContent | Out-File -FilePath $setupCmdFile -Encoding ASCII -Force
if (Test-Path -Path $setupCmdFile) {
&$writeLog "Successfully generated setup script: $setupCmdFile" "Green"
} else {
&$writeLog "Failed to generate setup script: $setupCmdFile" "Red"
}
} else {
&$writeLog "Failed to generate Configuration XML: $xmlFile" "Red"
}
}
if ($outputType -eq "Text file") {
$arrangeFile = "$tag`_arrange.cmd"
$arrangeContent = @"
@echo off
set _ver=$global:vvv
set _rot=$destDir
set _dst=$destDir\Office\Data
set _uri=%_dst%\%_ver%
set "_work=%~dp0"
setlocal EnableDelayedExpansion
pushd "!_work!"
if not exist *.cab if not exist *.dat (
echo ==== ERROR ====
echo no cab or dat files detected
echo.
echo Press any key to exit.
popd
pause >nul
goto :eof
)
if not exist %_uri%\stream*.dat mkdir %_uri%
for %%i in (
i32*.cab
i64*.cab
s32*.cab
s64*.cab
sp32*.cab
sp64*.cab
sc32*.cab
sa64*.cab
stream*.dat
) do (
if exist "%%i" move /y %%i %_uri%\
)
for %%i in (
SetupLanguagePack*.exe
Setup.exe
) do (
if exist "%%i" move /y %%i %_rot%\
)
for %%i in (
v32*.cab
v64*.cab
) do (
if exist "%%i" move /y %%i %_dst%\
)
if exist "%_dst%\v32_*.cab" xcopy /cqry "%_dst%\v32_*.cab" "%_dst%\v32.cab*"
if exist "%_dst%\v64_*.cab" xcopy /cqry "%_dst%\v64_*.cab" "%_dst%\v64.cab*"
"@
if ($isProof) {
$arrangeContent += "if exist `"$global:vvv`_x86_$language`_Proofing.xml`" move /y `"$global:vvv`_x86_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x86.xml`""
if ($isDual) {
$arrangeContent += "if exist `"$global:vvv`_x64_$language`_Proofing.xml`" move /y `"$global:vvv`_x64_$language`_Proofing.xml`" `"$destDir\Office\Proofing_$language`_x64.xml`""
}
}
$arrangeContent += @"
echo.
echo Done.
echo Press any key to exit.
popd
pause >nul
goto :eof
"@
$arrangeContent | Out-File -FilePath $arrangeFile -Encoding ASCII
if (Test-Path -Path $arrangeFile) {
&$writeLog "Successfully generated arrange script: $arrangeFile" "Green"
} else {
&$writeLog "Failed to generate arrange script: $arrangeFile" "Red"
}
}
$outputContent | Out-File -FilePath $outputFile -Encoding ASCII
if (Test-Path -Path $outputFile) {
&$writeLog "Successfully generated output file: $outputFile" "Green"
} else {
&$writeLog "Failed to generate output file: $outputFile" "Red"
$errorLabel.Text = "Output file creation failed"
$progressBar.Visible = $false
return
}
$progressBar.Value = 100
&$writeLog "Script generation completed successfully!" "Green"
}
catch {
&$writeLog "Error during script generation: $($_.Exception.Message)" "Red"
$errorLabel.Text = $_.Exception.Message
}
finally {
&$updateSummary
$progressBar.Visible = $false
}
})
# Add Configuration XML Button Click
$xmlButton.Add_Click({
try {
$errorLabel.Text = ""
$channel = $channelComboBox.SelectedItem
if (-not $channel) {
$errorLabel.Text = "Please select a channel first"
return
}
$destDir = "C2R_$channel"
$xmlFile = Join-Path $destDir "Configuration.xml"
if (-not (Test-Path -Path $destDir)) {
New-Item -Path $destDir -ItemType Directory -Force | Out-Null
&$writeLog "Created output directory: $destDir" "Green"
}
$openFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*"
$openFileDialog.Title = "Select Configuration XML File"
if ($openFileDialog.ShowDialog() -eq "OK") {
$selectedFile = $openFileDialog.FileName
try {
[xml](Get-Content -Path $selectedFile) | Out-Null
Copy-Item -Path $selectedFile -Destination $xmlFile -Force
&$writeLog "Successfully copied and validated XML file to: $xmlFile" "Green"
$setupCmdContent = @"
@echo off
setlocal
set "setupPath=%~dp0setup.exe"
set "configPath=%~dp0Configuration.xml"
if not exist "%setupPath%" (
echo Error: setup.exe not found in current directory
pause
exit /b 1
)
if not exist "%configPath%" (
echo Error: Configuration.xml not found in current directory
pause
exit /b 1
)
echo Starting Office installation...
"%setupPath%" /configure "%configPath%"
if %errorlevel% equ 0 (
echo Installation completed successfully
) else (
echo Installation failed with error code %errorlevel%
)
pause
"@
$setupCmdFile = Join-Path $destDir "setup.cmd"
$setupCmdContent | Out-File -FilePath $setupCmdFile -Encoding ASCII -Force
if (Test-Path -Path $setupCmdFile) {
&$writeLog "Successfully generated setup script: $setupCmdFile" "Green"
} else {
&$writeLog "Failed to generate setup script: $setupCmdFile" "Red"
$errorLabel.Text = "Setup.cmd file creation failed"
}
}
catch {
&$writeLog "Error: Selected file is not a valid XML: $($_.Exception.Message)" "Red"
$errorLabel.Text = "Selected file is not a valid XML"
}
}
}
catch {
&$writeLog "Error in Add Configuration XML operation: $($_.Exception.Message)" "Red"
$errorLabel.Text = "An error occurred during XML operation"
}
})
# Initial summary update
&$updateSummary
# Show the form
$form.ShowDialog()