用批处理在桌面上创建快捷方式

本文介绍了一个用于安装汽车玻璃升降器耐久性测试系统的批处理脚本。该脚本能够根据不同的系统版本和语言环境创建桌面快捷方式,并实现自动化安装流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

echo. 正在创建快捷方式...
set desktop=
:: 桌面路径
call :__CreateDesktopPath

:: 快捷方式一
call :__StringCat %desktop% "\汽车玻璃升降器耐久性测试系统.lnk"
set target=%result%
call :__StringCat %installPath% "\WindowLiftDurabilityTest.exe"
set srcFile=%result%
call :__StringCat %srcFile% ",0"
set icon=%result%
call :__CreateShort %srcFile% %target% %icon% %installPath%
echo. 安装完成, 按回车键结束... & pause > nul
goto __success

:: 判断语言环境
:__Locale
    set SystemLocale=
    ver|find /i "Version">nul
    if %errorlevel% equ 0 (set SystemLocale=EN_US&goto:eof) else set SystemLocale=ZH_CN&goto:eof

:: 判断系统版本
:__Version
    set SystemVersion=
    ver|findstr "5\.[0-9]\.[0-9][0-9]*">nul&&(set SystemVersion=WIN_XP&goto:eof)
    ver|findstr "6\.[0-9]\.[0-9][0-9]*">nul&&(set SystemVersion=WIN_VISTA_7&goto:eof)

:: 根据不同系统版本、不同语言环境生成“桌面”的绝对路径
:__CreateDesktopPath
    set en_desktop="\DESKTOP"
    set cn_desktop="\桌面"
    call :__Locale
    call :__Version
    
    if %SystemLocale%==EN_US (call :__Compound %en_desktop%&goto:eof)
    
    if %SystemVersion%==WIN_XP (
        if %SystemLocale%==EN_US (
                call :__Compound %en_desktop% & goto :eof
            ) else (
                call :__Compound %cn_desktop% & goto :eof
        )
    ) else (
        call :__Compound %en_desktop% & goto :eof
    )

:: 字符串合成
:__Compound
    call :__StringCat "%USERPROFILE%" %1
    set desktop=%result%
    goto :eof

:: 字符串连接 会自动去掉最外层的双引号后连接
:__StringCat
    set result=
    set result=%~1%~2
    set result="%result%"
    goto :eof

:__CreateShort
    set vbsStr="Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(""%~2""):b.TargetPath=""%~1"":b.WorkingDirectory=""%~4"":b.IconLocation=""%~3"":b.Save:close"
    mshta VBScript:Execute(%vbsStr%)
    goto :eof


:__success
    set installPath=
    set result=
    set SystemVersion=
    set desktop=
    set SystemLocale=
    set en_desktop=
    set cn_desktop=
    set vbsStr=


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值