Last active
September 24, 2023 22:46
-
-
Save cpuwolf/23d22ac4295a01dfe0958f75553682a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#written by [email protected] 2023 Sep. | |
# | |
# Set-WinUILanguageOverride -Language en-US | |
# pop up msg box for users | |
#$PSScriptRoot | |
# get script path | |
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition | |
Write-Host "script dir=$scriptPath" | |
Add-Type -AssemblyName System.Windows.Forms | |
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) | |
if ($principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { | |
# code here... | |
try { | |
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine | |
} | |
catch { | |
#Do Nothing | |
} | |
$ButtonType = [System.Windows.Forms.MessageBoxButtons]::OK | |
$MessageIcon = [System.Windows.Forms.MessageBoxIcon]::Information | |
# DONT indent $$MessageBody, or else you will get errors | |
$MessageBody = @' | |
1. Plug-out USB cable of QFCU | |
2. Press and hold the SPD/MACH button | |
3. plug-in the USB cable | |
4. monitor QFCU backlight is blinking | |
'@ | |
$MessageTitle = "USB cable" | |
$Result = [System.Windows.Forms.MessageBox]::Show($MessageBody, $MessageTitle, $ButtonType, $MessageIcon) | |
# install new device driver of DFU | |
Write-Host "current path=$(Get-Item .)" | |
Write-Host "work path=$scriptPath" | |
Start-Process -FilePath "$scriptPath\DFU_driver\Win10\dpinst_amd64.exe" -wait | |
# First join the string array from pnputil with newlines and split on the empty lines | |
# that separate each driver. The result is a set of textblocks for per driver from which | |
# we filter out the blocks where the wanted provider is mentioned. | |
$drivers = ((pnputil.exe /enum-drivers) -join [environment]::NewLine -split '(\r?\n){2,}' -ne '' | | |
Where-Object { $_ -match '\bguistdfudev.inf\b' }) | |
Write-Host "$drivers" | |
# Set log file path | |
$logFile = "$env:TEMP\qmdevfwlog.txt" | |
# test if we did find Guillemot drivers | |
if ($drivers) { | |
Out-File -FilePath $logFile | |
# Next replace the (first) colons with equal signs. Convert each block into a Hashtable using | |
# ConvertFrom-StringData and output the value of the property where the actual inf file is stored | |
$drivers | ForEach-Object { | |
$hashvals = ($_ -replace '(?<!:.*):', '=' | ConvertFrom-StringData -ErrorAction SilentlyContinue).Values | |
#Write-Host "$hashvals" | |
$hashvals | ForEach-Object { | |
if ($_ -match "oem.*inf") { | |
$driver = $_ | |
Write-Host "deleting driver using '$driver'" | |
Add-Content -Path $logFile -Value "deleting driver using '$driver'" | |
# Now you can delete the driver | |
# for safety reasons I have commented this out: | |
pnputil.exe /delete-driver $driver /uninstall /force | |
} | |
} | |
} | |
# rename folder | |
if (Test-Path -Path "C:\Program Files (x86)\Guillemot") { | |
Rename-Item -path "C:\Program Files (x86)\Guillemot" -NewName "Guillemot_1" | |
} | |
} | |
else { | |
Write-Host 'No Guillemot drivers found' | |
Add-Content -Path $logFile -Value 'No Guillemot drivers found' | |
} | |
# check driver wether is installed | |
$drivers = ((pnputil.exe /enum-drivers) -join [environment]::NewLine -split '(\r?\n){2,}' -ne '' | | |
Where-Object { $_ -match '\bsttube.inf\b' }) | |
#Write-Host "$drivers" | |
$devicess = ((pnputil.exe /enum-devices) -join [environment]::NewLine -split '(\r?\n){2,}' -ne '' | | |
Where-Object { $_ -match '\bDFU\b' }) | |
#Write-Host "$devicess" | |
# test if we did find STM DFU drivers | |
if ($devicess -And $drivers) { | |
[bool] $devdead = $false | |
# Disconnected? | |
$devicess | ForEach-Object { | |
$sStringToConvert = $_ -replace '\\', '\\' | |
$hashvals = ($sStringToConvert -replace '(?<!:.*):', '=' | ConvertFrom-StringData -ErrorAction SilentlyContinue).Values | |
#Write-Host "$hashvals" | |
$hashvals | ForEach-Object { | |
if ($_ -match "Disconnected") { | |
$devdead = $true | |
Write-Host "$_" | |
} | |
elseif ($_ -match "oem.*inf") { | |
$driveroem1 = $_ | |
Write-Host "$driveroem1" | |
} | |
} | |
} | |
# oem*.inf | |
$drivers | ForEach-Object { | |
$sStringToConvert = $_ -replace '\\', '\\' | |
$hashvals = ($sStringToConvert -replace '(?<!:.*):', '=' | ConvertFrom-StringData -ErrorAction SilentlyContinue).Values | |
#Write-Host "$hashvals" | |
$hashvals | ForEach-Object { | |
if ($_ -match "oem.*inf") { | |
$driveroem2 = $_ | |
Write-Host "$driveroem2" | |
} | |
} | |
} | |
if ($driveroem1 -eq $driveroem2) { | |
Write-Host 'DFU driver is found' | |
if (-Not $devdead) { | |
$devdfu = $_ | |
Write-Host "deleting device DFU is active" | |
Add-Content -Path $logFile -Value "deleting device DFU is active" | |
# Now you can delete the devdfu | |
Start-Process -FilePath "$scriptPath\QFCUfw230814\QFCU_FWUpdate.bat" -WorkingDirectory "$scriptPath\QFCUfw230814" -wait | |
# remove DFU driver | |
Start-Process -WorkingDirectory "$scriptPath\DFU_driver\Win10" -FilePath "$scriptPath\DFU_driver\Win10\dpinst_amd64.exe" -ArgumentList @('/u', 'STtube.inf', '/s') -wait | |
} | |
else { | |
Write-Host '' | |
Write-Host '===> DFU device is Disconnected' | |
} | |
} | |
else { | |
Write-Host '' | |
Write-Host 'DFU driver installation failed' | |
} | |
} | |
else { | |
Write-Host '' | |
Write-Host 'DFU driver installation is failed, try again' | |
} | |
# rename folder | |
if (Test-Path -Path "C:\Program Files (x86)\Guillemot_1") { | |
Rename-Item -path "C:\Program Files (x86)\Guillemot_1" -NewName "Guillemot" | |
} | |
pause | |
} | |
else { | |
Write-Host "NON admin script path=$(Get-Location)$('\')$($MyInvocation.MyCommand.Name)" | |
Write-Host "NON admin work path=$(Get-Item .)" | |
Start-Process -WorkingDirectory "$scriptPath" -FilePath "powershell" -ArgumentList "$('-File ""')$(Get-Location)$('\')$($MyInvocation.MyCommand.Name)$('""')" -Verb runAs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This power shell script aims to detect Guillemot drivers and remove the drivers.
this script is not required to run as administrator, because this script will prompt itself