|
|
本帖最后由 qq8899399 于 2026-6-14 14:28 编辑
原理 静默(不弹窗)
使用conhost.exe控制台静默启动powershell进行注册表修改
conhost.exe --headless "powershell.exe ... -Command ..."
conhost.exe:Windows 控制台窗口宿主,负责管理命令行窗口。
--headless:非标准参数(常见于某些系统工具或内部调用),含义是不创建可见的控制台窗口,使后续进程在后台运行。
powershell.exe:PowerShell 命令行外壳,执行具体逻辑。
其余参数控制 PowerShell 的窗口行为及执行命令。
"C:\windows\System32\conhost.exe" --headless "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle Hidden -NoProfile -NonInteractive -Command "Set-ItemProperty -Path 'Registry::HKCU\Control Panel\NotifyIconSettings\*' -Name 'IsPromoted' -Value 0"
"C:\windows\System32\conhost.exe" --headless "C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle Hidden -NoProfile -NonInteractive -Command "Set-ItemProperty -Path 'Registry::HKCU\Control Panel\NotifyIconSettings\*' -Name 'IsPromoted' -Value 1"
使用计划任务方式
静默运行,当前用户登录后延迟3秒钟后运行,每两分钟循环运行一次
- @echo off
- if /i "%UserName%" == "SYSTEM" (Goto GotAdmin) else (reg query "HKLM\SYSTEM\ControlSet001\Control\MiniNT" 1>nul 2>nul&&Goto GotAdmin)
- :BatchGotAdmin
- Set _Args=&Set Args=%*
- if `%1` neq `` Set "_Args=%Args:"=""%"
- if exist %WinDir%\System32\fltMC.exe fltMC 1>nul 2>nul||(echo CreateObject^("Shell.Application"^).ShellExecute "cmd.exe","/c """"%~f0"" %_Args%""",,"runas",1 >"%TEMP%\getAdmin.vbs"&(CScript 1>nul 2>nul&&CScript //nologo "%TEMP%\getAdmin.vbs" 1>nul 2>nul||"%TEMP%\getAdmin.vbs" 2>nul)&del /f /q "%TEMP%\getAdmin.vbs" 2>nul&Exit /b)
- :GotAdmin
- Pushd "%CD%"&cd /d "%~dp0"
- REM 设置计划任务(将在当前用户登录时延迟3秒启动和每2分钟运行一次)
- powershell -ExecutionPolicy Bypass -NoProfile -Command ^
- "$TaskPath = '\';" ^
- "$TaskName = 'Win11显示任务栏所有图标';" ^
- "$exePath = '\"%windir%\System32\conhost.exe\"';" ^
- "$argument = '--headless %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -NoProfile -NonInteractive -Command \"Set-ItemProperty -Path ''Registry::HKCU\Control Panel\NotifyIconSettings\*'' -Name ''IsPromoted'' -Value 1\"';" ^
- "$action = @();" ^
- "$action += New-ScheduledTaskAction -Execute $exePath -Argument $argument;" ^
- "$trigger = @();" ^
- "$trigger += New-ScheduledTaskTrigger -AtLogOn -User \"%USERNAME%\";" ^
- "$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 0;" ^
- "Register-ScheduledTask -TaskPath $TaskPath -TaskName $TaskName -Action $action -Trigger $trigger -Settings $settings -RunLevel Highest -Force;" ^
- "$service = New-Object -ComObject Schedule.Service;" ^
- "$service.Connect();" ^
- "$comFolder = $service.GetFolder($TaskPath);" ^
- "$comTask = $comFolder.GetTask($TaskName);" ^
- "$comTaskDef = $comTask.Definition;" ^
- "$comTaskDef.Triggers[1].Repetition.Interval = 'PT2M';" ^
- "$comTaskDef.Triggers[1].Delay = 'PT3S';" ^
- "$comFolder.RegisterTaskDefinition($TaskName, $comTaskDef, 6, $null, $null, $null);"
复制代码
|
|