Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WMIC installation #127

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions Install-WMIC.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
$ErrorActionPreference = "Stop"

function Repair-WMIC {
try {
$wmicPath = Join-Path $env:SystemRoot "System32\wbem\wmic.exe"

if (Test-Path $wmicPath) {
Write-Host "WMIC is already installed."
return $true
}

Write-Host "WMIC.exe is missing. Attempting system repair..."

# Try DISM repair first
Write-Host "Running DISM repair..."
$dismResult = Start-Process -FilePath "DISM.exe" -ArgumentList "/Online", "/Cleanup-Image", "/RestoreHealth" -Wait -NoNewWindow -PassThru

if ($dismResult.ExitCode -ne 0) {
Write-Host "DISM repair failed with exit code: $($dismResult.ExitCode)"
return $false
}

# Then run SFC
Write-Host "Running System File Checker..."
$sfcResult = Start-Process -FilePath "sfc.exe" -ArgumentList "/scannow" -Wait -NoNewWindow -PassThru

if ($sfcResult.ExitCode -ne 0) {
Write-Host "SFC repair failed with exit code: $($sfcResult.ExitCode)"
return $false
}

# Check if wmic.exe exists after repairs
if (Test-Path $wmicPath) {
Write-Host "WMIC has been restored successfully."
return $true
} else {
Write-Host "WMIC could not be restored."

# Additional WMI repository reset as last resort
Write-Host "Attempting WMI repository reset..."
Stop-Service Winmgmt -Force
Remove-Item -Path "$env:SystemRoot\System32\wbem\repository" -Recurse -Force -ErrorAction SilentlyContinue
Start-Service Winmgmt

# Final check
if (Test-Path $wmicPath) {
Write-Host "WMIC has been restored after WMI repository reset."
return $true
}
return $false
}
}
catch {
$errorMessage = $_.Exception.Message
Write-Host ("Error during WMIC repair: {0}" -f $errorMessage)
return $false
}
}

$result = Repair-WMIC
if (-not $result) {
Write-Host "WMIC repair failed. Consider using PowerShell alternatives like Get-CimInstance."
Write-Host "Example: Instead of 'wmic computersystem get model'"
Write-Host "Use: Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Model"
exit 1
}
exit 0
7 changes: 5 additions & 2 deletions a11y_for_windows.iss
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
[Files]
Source: "Oobee-win32-x64\*"; DestDir: "\\?\{app}\Oobee Frontend"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\a\Oobee Backend\*"; DestDir: "\\?\{app}\Oobee Backend"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "Install-WMIC.ps1"; DestDir: "\\?\{app}"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{autoprograms}\Oobee Desktop"; Filename: "C:\Program Files\Oobee Desktop\Oobee Frontend\Oobee.exe"
Name: "{autodesktop}\Oobee Desktop"; Filename: "C:\Program Files\Oobee Desktop\Oobee Frontend\Oobee.exe"; Tasks: desktopicon

; [Run]
[Run]
; Filename: "C:\Program Files\Oobee\Oobee Frontend\Oobee.exe"; Description: "{cm:LaunchProgram,Oobee Desktop}"; Flags: nowait postinstall skipifsilent
; Add WMIC installation before running your application
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -File ""C:\Program Files\Oobee Desktop\Install-WMIC.ps1"""; Description: "{cm:LaunchProgram,Install required Windows features}"; Flags: postinstall waituntilterminated

[UninstallDelete]
Type: filesandordirs; Name: "C:\Program Files\Oobee\Oobee Frontend"
Type: filesandordirs; Name: "C:\Program Files\Oobee\Oobee Backend"

[InstallDelete]
Type: filesandordirs; Name: "C:\Program Files\Oobee\Oobee Frontend"
Type: filesandordirs; Name: "C:\Program Files\Oobee\Oobee Backend"
Type: filesandordirs; Name: "C:\Program Files\Oobee\Oobee Backend"