以下是一个使用NSIS脚本的例子,该脚本支持Windows 11及更高版本,并将指定程序固定到任务栏上:

!include "MUI2.nsh"
!include "WinVer.nsh"

Name "固定程序到任务栏"
Outfile "MyInstaller.exe"

Function .onInit
    ${If} ${AtLeastWin11}
        MessageBox MB_OK "您的操作系统支持固定程序到任务栏。"
    ${Else}
        MessageBox MB_ICONSTOP "您的操作系统不支持固定程序到任务栏。"
        Quit
    ${EndIf}
FunctionEnd

Page Components
Page InstFiles

Section
    SetOutPath "$INSTDIR"
    File "YourProgram.exe" ; 替换为您要固定的程序的路径

    ; 创建快捷方式到开始菜单
    CreateShortcut "$SMPrograms\YourProgram.lnk" "$INSTDIR\YourProgram.exe" "" "$INSTDIR\YourProgram.exe" 0

    ; 获取Shell对象
    System::Call "shell32::SHGetDesktopFolder(t .r0)"
    
    ; 获取任务栏对象
    System::Call "shell32::IShellWindows::FindWindowSW(i 0, i 0, t .r1, i 0x00000002, *i r2)"
    
    ; 获取任务栏窗口
    System::Call "user32::GetWindow(i r1, i 5) i.r1"
    
    ; 创建ShellLink对象
    System::Call "ole32::CoCreateInstance(g '000214F9-0000-0000-C000-000000000046', i r0, i 0, g '00000000-0000-0000-C000-000000000046', *i .r3) i.r4"
    
    ; 获取ShellLink对象的IPersistFile接口
    System::Call "ole32::IPersistFile::QueryInterface(i r3, g '0000010b-0000-0000-C000-000000000046', *i .r5) i.r6"
    
    ; 设置快捷方式路径
    System::Call "ole32::IPersistFile::Load(t '$SMPrograms\YourProgram.lnk', i 0) i.r7"
    
    ; 获取快捷方式ShellLink对象
    System::Call "shell32::IShellLinkA::QueryInterface(i r7, g '000214ee-0000-0000-C000-000000000046', *i .r8) i.r9"
    
    ; 将快捷方式固定到任务栏
    System::Call "shell32::ITaskbarList::AddTab(i r2, i r1) i.r10"
    
    ; 释放对象引用
    System::Call "ole32::IPersistFile::Release(i r6)"
    System::Call "shell32::IShellLinkA::Release(i r9)"
    System::Call "shell32::IShellWindows::Release(i r2)"
SectionEnd

请确保将YourProgram.exe替换为您要固定到任务栏的程序的路径

写一个 nsis脚本要求支持windows11及更高版本将指定程序固定到任务栏上。

原文地址: http://www.cveoy.top/t/topic/idNM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录