Skip to content

Instantly share code, notes, and snippets.

@WinkelCode
Last active May 2, 2023 09:18
Show Gist options
  • Save WinkelCode/faa1d6000a4ec379e039110cbf97b8de to your computer and use it in GitHub Desktop.
Save WinkelCode/faa1d6000a4ec379e039110cbf97b8de to your computer and use it in GitHub Desktop.
Messing around with Windows drivers can break stuff, use at your own risk. Script requres elevated permissions. You will need PS execution policy "RemoteSigned" (or any that allows running local scripts) and unblock script via file options (or paste it into an empty text file).
# Script to automatically remove and install "appleprecisiontrackpadbluetooth.inf" and "appleprecisiontrackpadusb.inf".
# Script needs to be in an extracted "AppleBcUpdate" folder.
function remove_driver {
$driver_orignames = @("appleprecisiontrackpadbluetooth.inf", "appleprecisiontrackpadusb.inf")
# Get matching installed drivers with pnputil and include previous line (the published name)
$drivers = pnputil /enum-drivers | Select-String -Pattern $driver_orignames -Context 1,0
if ($drivers.Count -gt 2) {
Write-Host "Error: More than 2 drivers found."
return
} elseif ($drivers.Count -eq 0) {
Write-Host "No drivers found."
return
}
foreach ($driver in $drivers) {
if ($driver.Context.PreContext -notmatch "^Published Name" -or $driver.Line -notmatch "^Original Name") {
Write-Host "WARNING: Unexpected output from pnputil (Could not verify 'Published Name' or 'Original Name')."
Write-Host "This might be caused by a non-English Windows installation."
Write-Host "Please verify the output of pnputil /enum-drivers manually."
}
# Extract only the published name from the previous line.
$driverpubname = $driver.Context.PreContext -split " " | Select-Object -Last 1
$driverorigname = $driver.Line -split " " | Select-Object -Last 1
Write-Host "Will remove $driverorigname ($driverpubname)."
$drivers_to_remove += @($driverpubname)
}
Write-Host "Confirm? [y/N]"
$choice = Read-Host "Choice"
if ($choice -eq "y") {
foreach ($driver in $drivers_to_remove) {
pnputil /delete-driver "$driver" /force
}
}
}
function install_driver {
$driver_folders = @("ApplePrecisionTrackpadUSB", "ApplePrecisionTrackpadBluetooth")
if (!(Test-Path $driver_folders[0]) -or !(Test-Path $driver_folders[1])) {
Write-Host "Error: Missing driver folders."
Write-Host "Make sure you have the folders 'ApplePrecisionTrackpadUSB' and 'ApplePrecisionTrackpadBluetooth' in the same directory as this script."
return
}
foreach ($driver_folder in $driver_folders) {
pnputil /add-driver "$driver_folder/*.inf" /install
}
}
while ($true) {
Write-Host "[1] Remove drivers`n[2] Install drivers`n[3] Exit"
$choice = Read-Host "Choice"
switch ($choice) {
1 { remove_driver }
2 { install_driver }
3 { exit }
default { Write-Host "Invalid choice." }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment