Skip to content

Commit c29a65c

Browse files
committed
Next batch; hopefully this is it
1 parent f9bad63 commit c29a65c

8 files changed

+43
-31
lines changed

functions/microwin/Invoke-Microwin.ps1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ function Invoke-Microwin {
1111
return
1212
}
1313

14+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
15+
1416
# Define the constants for Windows API
1517
Add-Type @"
1618
using System;
@@ -136,8 +138,8 @@ public class PowerManagement {
136138

137139
if ($importDrivers) {
138140
Write-Host "Exporting drivers from active installation..."
139-
if (Test-Path "$env:TEMP\DRV_EXPORT") {
140-
Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force
141+
if (Test-Path "$tempDir\DRV_EXPORT") {
142+
Remove-Item "$tempDir\DRV_EXPORT" -Recurse -Force
141143
}
142144
if (($injectDrivers -and (Test-Path "$($sync.MicrowinDriverLocation.Text)"))) {
143145
Write-Host "Using specified driver source..."
@@ -149,16 +151,16 @@ public class PowerManagement {
149151
Write-Host "Failed to export drivers."
150152
}
151153
} else {
152-
New-Item -Path "$env:TEMP\DRV_EXPORT" -ItemType Directory -Force
153-
dism /english /online /export-driver /destination="$env:TEMP\DRV_EXPORT" | Out-Host
154+
New-Item -Path "$tempDir\DRV_EXPORT" -ItemType Directory -Force
155+
dism /english /online /export-driver /destination="$tempDir\DRV_EXPORT" | Out-Host
154156
if ($?) {
155157
Write-Host "Adding exported drivers..."
156-
dism /english /image="$scratchDir" /add-driver /driver="$env:TEMP\DRV_EXPORT" /recurse | Out-Host
158+
dism /english /image="$scratchDir" /add-driver /driver="$tempDir\DRV_EXPORT" /recurse | Out-Host
157159
} else {
158160
Write-Host "Failed to export drivers. Continuing without importing them..."
159161
}
160-
if (Test-Path "$env:TEMP\DRV_EXPORT") {
161-
Remove-Item "$env:TEMP\DRV_EXPORT" -Recurse -Force
162+
if (Test-Path "$tempDir\DRV_EXPORT") {
163+
Remove-Item "$tempDir\DRV_EXPORT" -Recurse -Force
162164
}
163165
}
164166
}
@@ -289,21 +291,21 @@ public class PowerManagement {
289291
Write-Host "Done Create unattend.xml"
290292
Write-Host "Copy unattend.xml file into the ISO"
291293
New-Item -ItemType Directory -Force -Path "$($scratchDir)\Windows\Panther"
292-
Copy-Item "$env:temp\unattend.xml" "$($scratchDir)\Windows\Panther\unattend.xml" -force
294+
Copy-Item "$tempDir\unattend.xml" "$($scratchDir)\Windows\Panther\unattend.xml" -force
293295
New-Item -ItemType Directory -Force -Path "$($scratchDir)\Windows\System32\Sysprep"
294-
Copy-Item "$env:temp\unattend.xml" "$($scratchDir)\Windows\System32\Sysprep\unattend.xml" -force
296+
Copy-Item "$tempDir\unattend.xml" "$($scratchDir)\Windows\System32\Sysprep\unattend.xml" -force
295297
Write-Host "Done Copy unattend.xml"
296298

297299
Write-Host "Create FirstRun"
298300
Microwin-NewFirstRun
299301
Write-Host "Done create FirstRun"
300302
Write-Host "Copy FirstRun.ps1 into the ISO"
301-
Copy-Item "$env:temp\FirstStartup.ps1" "$($scratchDir)\Windows\FirstStartup.ps1" -force
303+
Copy-Item "$tempDir\FirstStartup.ps1" "$($scratchDir)\Windows\FirstStartup.ps1" -force
302304
Write-Host "Done copy FirstRun.ps1"
303305

304306
Write-Host "Copy checkinstall.cmd into the ISO"
305307
Microwin-NewCheckInstall
306-
Copy-Item "$env:temp\checkinstall.cmd" "$($scratchDir)\Windows\checkinstall.cmd" -force
308+
Copy-Item "$tempDir\checkinstall.cmd" "$($scratchDir)\Windows\checkinstall.cmd" -force
307309
Write-Host "Done copy checkinstall.cmd"
308310

309311
Write-Host "Creating a directory that allows to bypass Wifi setup"
@@ -557,8 +559,6 @@ public class PowerManagement {
557559
$expectedADKPath = "$($adkKitsRoot)Assessment and Deployment Kit"
558560
$expectedADKPath_WOW64Environ = "$($adkKitsRoot_WOW64Environ)Assessment and Deployment Kit"
559561

560-
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
561-
562562
# if we downloaded oscdimg from github it will be in the temp directory so use it
563563
# if it is not in temp it is part of ADK and is in global PATH so just set it to oscdimg.exe
564564
$oscdimgPath = "$tempDir\oscdimg.exe"

functions/microwin/Invoke-MicrowinGetIso.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function Invoke-MicrowinGetIso {
6060

6161
# Auto download newest ISO
6262
# Credit: https://github.com/pbatard/Fido
63-
$fidopath = "$env:temp\Fido.ps1"
63+
$fidopath = "$tempDir\Fido.ps1"
6464
$originalLocation = $PSScriptRoot
6565

6666
Invoke-MicrowinBusyInfo -action "wip" -message "Downloading Fido script..." -interactive $false
@@ -89,22 +89,22 @@ function Invoke-MicrowinGetIso {
8989
Set-Location "$originalLocation"
9090
# Use the FullName property to only grab the file names. Using this property is necessary as, without it, you're passing the usual output of Get-ChildItem
9191
# to the variable, and let's be honest, that does NOT exist in the file system
92-
$filePath = (Get-ChildItem -Path "$env:temp" -Filter "Win11*.iso").FullName | Sort-Object LastWriteTime -Descending | Select-Object -First 1
92+
$filePath = (Get-ChildItem -Path "$tempDir" -Filter "Win11*.iso").FullName | Sort-Object LastWriteTime -Descending | Select-Object -First 1
9393
$fileName = [IO.Path]::GetFileName("$filePath")
9494

9595
if (($targetFolder -ne "") -and (Test-Path "$targetFolder"))
9696
{
9797
try
9898
{
99-
# "Let it download to $env:TEMP and then we **move** it to the file path." - CodingWonders
99+
# "Let it download to $tempDir and then we **move** it to the file path." - CodingWonders
100100
$destinationFilePath = "$targetFolder\$fileName"
101101
Write-Host "Moving ISO file. Please wait..."
102102
Move-Item -Path "$filePath" -Destination "$destinationFilePath" -Force
103103
$filePath = $destinationFilePath
104104
}
105105
catch
106106
{
107-
$msg = "Unable to move the ISO file to the location you specified. The downloaded ISO is in the `"$env:TEMP`" folder"
107+
$msg = "Unable to move the ISO file to the location you specified. The downloaded ISO is in the `"$tempDir`" folder"
108108
Write-Host $msg
109109
Write-Host "Error information: $($_.Exception.Message)" -ForegroundColor Yellow
110110
Invoke-MicrowinBusyInfo -action "warning" -message $msg
@@ -148,7 +148,7 @@ function Invoke-MicrowinGetIso {
148148
$msg = "ADK/OSCDIMG is installed, now restart this process."
149149
Invoke-MicrowinBusyInfo -action "done" -message $msg # We set it to done because it immediately returns from this function
150150
[System.Windows.MessageBox]::Show($msg)
151-
Remove-Item -Path "$env:TEMP\adksetup.exe" -Force -ErrorAction SilentlyContinue
151+
Remove-Item -Path "$tempDir\adksetup.exe" -Force -ErrorAction SilentlyContinue
152152
return
153153
}
154154
}

functions/microwin/Microwin-CopyVirtIO.ps1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@ function Microwin-CopyVirtIO {
66
A network connection must be available and the servers of Fedora People must be up. Automatic driver installation will not be added yet - I want this implementation to be reliable.
77
#>
88

9+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
10+
911
try {
1012
Write-Host "Checking existing files..."
11-
if (Test-Path -Path "$($env:TEMP)\virtio.iso" -PathType Leaf) {
13+
if (Test-Path -Path "$($tempDir)\virtio.iso" -PathType Leaf) {
1214
Write-Host "VirtIO ISO has been detected. Deleting..."
13-
Remove-Item -Path "$($env:TEMP)\virtio.iso" -Force
15+
Remove-Item -Path "$($tempDir)\virtio.iso" -Force
1416
}
1517
Write-Host "Getting latest VirtIO drivers. Please wait. This can take some time, depending on your network connection speed and the speed of the servers..."
16-
Start-BitsTransfer -Source "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" -Destination "$($env:TEMP)\virtio.iso" -DisplayName "Downloading VirtIO drivers..."
18+
Start-BitsTransfer -Source "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" -Destination "$($tempDir)\virtio.iso" -DisplayName "Downloading VirtIO drivers..."
1719
# Do everything else if the VirtIO ISO exists
18-
if (Test-Path -Path "$($env:TEMP)\virtio.iso" -PathType Leaf) {
20+
if (Test-Path -Path "$($tempDir)\virtio.iso" -PathType Leaf) {
1921
Write-Host "Mounting ISO. Please wait."
20-
$virtIO_ISO = Mount-DiskImage -PassThru "$($env:TEMP)\virtio.iso"
22+
$virtIO_ISO = Mount-DiskImage -PassThru "$($tempDir)\virtio.iso"
2123
$driveLetter = (Get-Volume -DiskImage $virtIO_ISO).DriveLetter
2224
# Create new directory for VirtIO on ISO
2325
New-Item -Path "$mountDir\VirtIO" -ItemType Directory | Out-Null
2426
$totalTime = Measure-Command { Copy-Files "$($driveLetter):" "$mountDir\VirtIO" -Recurse -Force }
2527
Write-Host "VirtIO contents have been successfully copied. Time taken: $($totalTime.Minutes) minutes, $($totalTime.Seconds) seconds`n"
2628
Get-Volume $driveLetter | Get-DiskImage | Dismount-DiskImage
27-
Remove-Item -Path "$($env:TEMP)\virtio.iso" -Force -ErrorAction SilentlyContinue
29+
Remove-Item -Path "$($tempDir)\virtio.iso" -Force -ErrorAction SilentlyContinue
2830
Write-Host "To proceed with installation of the MicroWin image in QEMU/Proxmox VE:"
2931
Write-Host "1. Proceed with Setup until you reach the disk selection screen, in which you won't see any drives"
3032
Write-Host "2. Click `"Load Driver`" and click Browse"

functions/microwin/Microwin-GetAdkDeploymentTools.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ function Microwin-GetAdkDeploymentTools {
77
Microwin-GetAdkDeploymentTools
88
#>
99

10+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
11+
1012
# ADK 10.1.28000.1 download link is the same; no need to guess it
1113
$adkDownloadLink = "https://download.microsoft.com/download/615540bc-be0b-433a-b91b-1f2b0642bb24/adk/adksetup.exe"
1214
$adkVersion = "10.1.28000.1"
1315
Write-Host "Downloading ADK version $adkVersion ..."
14-
Invoke-WebRequest -UseBasicParsing -Uri "$adkDownloadLink" -OutFile "$env:TEMP\adksetup.exe"
16+
Invoke-WebRequest -UseBasicParsing -Uri "$adkDownloadLink" -OutFile "$tempDir\adksetup.exe"
1517

16-
if ((-not ($?)) -or (-not (Test-Path -Path "$env:TEMP\adksetup.exe" -PathType Leaf))) {
18+
if ((-not ($?)) -or (-not (Test-Path -Path "$tempDir\adksetup.exe" -PathType Leaf))) {
1719
Write-Host "ADK could not be downloaded."
1820
return $false
1921
}
2022

2123
Write-Host "Installing ADK version $adkVersion -- This may take a few minutes..."
22-
Start-Process -FilePath "$env:TEMP\adksetup.exe" -ArgumentList "/features OptionId.DeploymentTools /q /ceip off" -Wait
24+
Start-Process -FilePath "$tempDir\adksetup.exe" -ArgumentList "/features OptionId.DeploymentTools /q /ceip off" -Wait
2325

2426
return $?
2527
}

functions/microwin/Microwin-GetOscdimg.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ function Microwin-GetOscdimg {
1212
[string]$oscdimgPath
1313
)
1414

15-
$oscdimgPath = "$env:TEMP\oscdimg.exe"
15+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
16+
17+
$oscdimgPath = "$tempDir\oscdimg.exe"
1618
$downloadUrl = "https://github.com/ChrisTitusTech/winutil/raw/main/releases/oscdimg.exe"
1719
Invoke-RestMethod -Uri $downloadUrl -OutFile $oscdimgPath
1820
if (-not (Test-Path "$oscdimgPath" -PathType Leaf)) {

functions/microwin/Microwin-NewCheckInstall.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Microwin-NewCheckInstall {
22

3+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
4+
35
# using here string to embed firstrun
46
$checkInstall = @'
57
@echo off
@@ -69,5 +71,5 @@ function Microwin-NewCheckInstall {
6971
echo %HOMEDRIVE%\windows\LogFirstRun.txt does not exist
7072
)
7173
'@
72-
$checkInstall | Out-File -FilePath "$env:temp\checkinstall.cmd" -Force -Encoding Ascii
74+
$checkInstall | Out-File -FilePath "$tempDir\checkinstall.cmd" -Force -Encoding Ascii
7375
}

functions/microwin/Microwin-NewFirstRun.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Microwin-NewFirstRun {
22

3+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
4+
35
# using here string to embed firstrun
46
$firstRun = @'
57
# Set the global error action preference to continue
@@ -148,5 +150,5 @@ public class Win32 {
148150
}
149151
150152
'@
151-
$firstRun | Out-File -FilePath "$env:temp\FirstStartup.ps1" -Force
153+
$firstRun | Out-File -FilePath "$tempDir\FirstStartup.ps1" -Force
152154
}

functions/microwin/Microwin-NewUnattend.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function Microwin-NewUnattend {
22

3+
$tempDir = [IO.Path]::GetTempPath().TrimEnd("\")
4+
35
param (
46
[Parameter(Mandatory, Position = 0)] [string]$userName,
57
[Parameter(Position = 1)] [string]$userPassword
@@ -323,5 +325,5 @@ function Microwin-NewUnattend {
323325
}
324326

325327
# Save unattended answer file with UTF-8 encoding
326-
$unattend | Out-File -FilePath "$env:temp\unattend.xml" -Force -Encoding utf8
328+
$unattend | Out-File -FilePath "$tempDir\unattend.xml" -Force -Encoding utf8
327329
}

0 commit comments

Comments
 (0)