39 lines
1.6 KiB
PowerShell
39 lines
1.6 KiB
PowerShell
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
|
|
if ($isAdmin) {
|
|
pyinstaller --onefile CountFolderFiles.py
|
|
cd dist
|
|
$directoryPath = "C:\Program Files\Python311\Scripts\"
|
|
if (Test-Path $directoryPath -PathType Container) {
|
|
|
|
# Add CountFolderFiles.exe to Python Scripts
|
|
Copy-Item -Path .\CountFolderFiles.exe -Destination 'C:\Program Files\Python311\Scripts\' -Force
|
|
|
|
|
|
|
|
# Get the name of the SendTo folder for the user of the current directory. (can't use %appdata% since we are logged in as admin)
|
|
$directoryPath = $PWD.Path
|
|
$separator = "\"
|
|
$parts = $directoryPath.Split('\')
|
|
$extractedString = $parts[0..2] -join $separator
|
|
$SendToPath = $extractedString + "\AppData\Roaming\Microsoft\Windows\SendTo\CountFolderFiles.lnk"
|
|
|
|
|
|
# Add a shortcut to C:\Program Files\Python311\Scripts\CountFolderFiles.exe in SendTo folder
|
|
$SourceExe = "C:\Program Files\Python311\Scripts\CountFolderFiles.exe"
|
|
$DestinationPath = $SendToPath
|
|
|
|
$WshShell = New-Object -ComObject WScript.Shell
|
|
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
|
|
$Shortcut.TargetPath = $SourceExe
|
|
$Shortcut.Save()
|
|
|
|
Read-Host -Prompt "Done, Press enter to exit."
|
|
} else {
|
|
Read-Host -Prompt "The Python311 directory does not exist. Please install manually (read the powershell commands) or use Python 3.11."
|
|
}
|
|
}
|
|
else {
|
|
Read-Host -Prompt "Please run this script as admin."
|
|
}
|