I would like to ask how to prevent shutdown, when running a script or at least give a popup that will ask whenever or not you want to shutdown (like when you open a notepad and write a char, but doesn't save it and the click shutdown).
I have been creating scripts that runs installers silent, but some of them still seems to activate windows shutdown (this can happen if they are missing prerequisites).
Here is the code I use for the installation:
# --- Install ---
$fileExtension = (Get-ChildItem -path $installationFilePath).Extension
if(".msi" -eq $fileExtension)
{
[string[]]$Private:args = New-Object string[] 4
$args[0] = "/qn"
$args[1] = "TRANSFORM=1033.mst"
$args[2] = "REBOOT=Suppress"
$args[3] = "/l*v $errorLogPath"
$process = Start-Process $installationFilePath -ArgumentList $args -PassThru
}
if(".exe" -eq $fileExtension)
{
[string[]]$Private:args = New-Object string[] 2
$args[0] = '/v"' + "/qn TRANSFORM=1033.mst REBOOT=Suppress /l*v $errorLogPath" + '"'
$args[1] = "/s"
$process = Start-Process $installationFilePath -ArgumentList $args -PassThru
}
$processActive = $process
while ($processActive -ne $null)
{
Start-Sleep -Seconds 1
Write-Host '.' -NoNewline
$processActive = Get-Process -Id $processActive.Id -ErrorAction SilentlyContinue
}
I know this should be possible, but I have yet to find out how.