Skip to content

设置非关机参数无法退出窗口 #16

@nuoyis

Description

@nuoyis

我的系统是win11 25h2, 在执行完毕后等待几分钟窗口仍未关闭
1Image
因为我的电脑是挂着程序和代码的,设置关机需要重新打开很多软件,之前自己写的powershell也是休眠。目前也为该exe程序写了个搭配使用的powershell补充了缺失的部分
powershell 兼容代码如下

# UTF-8 控制台 & 日志准备
chcp 65001

# 静音防止吵到室友(家人)
# https://blog.csdn.net/HoKis/article/details/143923391
$code = @'
[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
'@
Add-Type -Namespace Windows -MemberDefinition $code -Name 'Windows'
[System.IntPtr]$wi = [Windows.Windows]::GetForegroundWindow()
$WM_APPCOMMAND = 0x319
$APPCOMMAND_VOLUME_DOWN = 0x090000
$APPCOMMAND_VOLUME_UP = 0x0a0000
$APPCOMMAND_VOLUME_MUTE = 0x80000
$ret=[Windows.Windows]::SendMessageW($wi,$WM_APPCOMMAND,$wi,$APPCOMMAND_VOLUME_UP)
$ret=[Windows.Windows]::SendMessageW($wi,$WM_APPCOMMAND,$wi,$APPCOMMAND_VOLUME_MUTE)

# 激活屏幕
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait("{SCROLLLOCK}")
Start-Sleep -Milliseconds 100
[System.Windows.Forms.SendKeys]::SendWait("{SCROLLLOCK}")

# 关闭代理(例如clash之类导致游戏被代理加载卡顿) 借鉴https://www.bilibili.com/video/BV186T7zeEby
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyEnable -Value 0

# DNS缓存刷新
ipconfig /flushdns

# 启动新找到的OneDragon ScriptChainer 一键启动软件
Start-Process -FilePath "F:\OneDragon ScriptChainer\OneDragon ScriptChainer Runner.exe" -NoNewWindow -Wait
# 加入关机参数
# Start-Process -FilePath "F:\OneDragon ScriptChainer\OneDragon ScriptChainer Runner.exe" -ArgumentList "--shutdown" -NoNewWindow -Wait

# 休眠状态(关机把上面注释的地方取消注释,将前面相同的无注释地方注释)
Write-Log "执行完毕,60秒后准备进入休眠..."
Start-Sleep -Seconds 60
rundll32.exe powrprof.dll,SetSuspendState Sleep

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions