NapCatQQ/script/napcat.ps1

43 lines
1.3 KiB
PowerShell
Raw Normal View History

2024-04-14 16:09:08 +00:00
function Get-QQpath {
try {
$key = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\QQ"
$uninstallString = $key.UninstallString
return [System.IO.Path]::GetDirectoryName($uninstallString) + "\QQ.exe"
2024-05-17 11:22:36 +00:00
}
catch {
2024-05-13 09:26:22 +00:00
throw "get QQ path error: $_"
2024-04-14 16:09:08 +00:00
}
}
2024-05-17 11:22:36 +00:00
function Select-QQPath {
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$dialogTitle = "Select QQ.exe"
$filePicker = New-Object System.Windows.Forms.OpenFileDialog
$filePicker.Title = $dialogTitle
$filePicker.Filter = "Executable Files (*.exe)|*.exe|All Files (*.*)|*.*"
$filePicker.FilterIndex = 1
$null = $filePicker.ShowDialog()
if (-not ($filePicker.FileName)) {
throw "User did not select an .exe file."
}
return $filePicker.FileName
}
2024-04-14 16:09:08 +00:00
$params = $args -join " "
2024-05-13 09:26:22 +00:00
Try {
$QQpath = Get-QQpath
2024-05-17 11:22:36 +00:00
}
Catch {
$QQpath = Select-QQPath
2024-05-13 09:26:22 +00:00
}
if (!(Test-Path $QQpath)) {
throw "provided QQ path is invalid: $QQpath"
}
2024-04-14 16:09:08 +00:00
$Bootfile = Join-Path $PSScriptRoot "napcat.cjs"
$env:ELECTRON_RUN_AS_NODE = 1
2024-05-13 09:26:22 +00:00
$commandInfo = Get-Command $QQpath -ErrorAction Stop
Start-Process powershell -ArgumentList "-noexit", "-noprofile", "-command &{& '$($commandInfo.Path)' $Bootfile $params}"