analitics

Pages

Wednesday, July 1, 2026

Python 3.10.11 : fix python store bad open with powershell.

Today, this powershell source code will fix the python command when start the windows store.
This is the powershell source code:

# Run first 
# Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

# --- Create Form ---
$form = New-Object System.Windows.Forms.Form
$form.Text = "Python Path Fixer"
$form.Size = New-Object System.Drawing.Size(500, 300)
$form.StartPosition = 'CenterScreen'

# --- Label & Path Input ---
$label = New-Object System.Windows.Forms.Label
$label.Text = "Python Directory:"
$label.Location = New-Object System.Drawing.Point(10, 20)
$label.AutoSize = $true
$form.Controls.Add($label)

$txtPath = New-Object System.Windows.Forms.TextBox
$txtPath.Location = New-Object System.Drawing.Point(10, 45)
$txtPath.Size = New-Object System.Drawing.Size(460, 20)
$txtPath.Text = "C:\PythonInstall" 
$form.Controls.Add($txtPath)

# --- Log Box ---
$txtLog = New-Object System.Windows.Forms.TextBox
$txtLog.Multiline = $true
$txtLog.ScrollBars = 'Vertical'
$txtLog.Location = New-Object System.Drawing.Point(10, 80)
$txtLog.Size = New-Object System.Drawing.Size(460, 130)
$txtLog.ReadOnly = $true
$form.Controls.Add($txtLog)

# --- Fix Button ---
$btnFix = New-Object System.Windows.Forms.Button
$btnFix.Text = "Check and Fix Path"
$btnFix.Location = New-Object System.Drawing.Point(10, 220)
$btnFix.Size = New-Object System.Drawing.Size(460, 30)

$btnFix.Add_Click({
    $pythonFolder = $txtPath.Text
    $pythonExe = Join-Path $pythonFolder "python.exe"
    
    $txtLog.Text = "Checking: $pythonExe`r`n"
    
    if (Test-Path $pythonExe) {
        $txtLog.AppendText("[+] Python found. Updating PATH...`r`n")
        
        $currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
        $pathParts = $currentPath -split ";" | Where-Object { $_ -ne $pythonFolder -and $_ -ne "" }
        $newPath = "$pythonFolder;" + ($pathParts -join ";")
        
        [Environment]::SetEnvironmentVariable("Path", $newPath, "User")
        
        $txtLog.AppendText("[OK] Priority set successfully!`r`nPlease restart your terminal.")
    } else {
        $txtLog.AppendText("[ERROR] python.exe not found in the specified directory!")
    }
})
$form.Controls.Add($btnFix)

[void]$form.ShowDialog()