怎样用批处理命令把可执行文件制作成一个快捷键放到桌面上

如题所述

用下面的代码保存为一个BAT文件后, 把需要建桌面快捷方式的文件拖到这个BAT文件上(也就是作为参数 %1), 就可以了
@echo off
echo wscript.echo CreateObject("WScript.Shell").RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\desktop")>t~.vbs
for /f "delims=" %%a in ('cscript //nologo t~.vbs') do set "mydesk=%%a"
(set fnLnk=%~n1.lnk)&(set fnFull=%~f1)
if exist "%mydesk%\%fnLnk%" msg %username% 快捷方式文件 %mydesk%\%fnLnk% 已经存在. 请先删除或重命名此文件再重试.
(set fnFull=%fnFull:\=\\%)
if "%~x1" equ ".exe" (set iconPath=%~f1) else (set iconPath=%SystemRoot%\system32\SHELL32.dll)
(set iconPath=%iconPath:\=\\%)
(set vbsfn=%HomeDrive%\scuttemp.vbs)
echo Set WshShell = Wscript.CreateObject("Wscript.Shell")>%vbsfn%
echo ' 创建一个快捷方式对象,其在桌面上设置相同的名字>>%vbsfn%
echo strDesktop = WshShell.SpecialFolders("Desktop")>>%vbsfn%
echo Set oShellLink = WshShell.CreateShortcut(strDesktop ^& "\\%fnLnk%")>>%vbsfn%
echo ' 设置快捷方式的执行路径>>%vbsfn%
echo oShellLink.TargetPath = "%fnFull%">>%vbsfn%
echo oShellLink.WindowStyle = 1 ' 运行方式>>%vbsfn%
echo oShellLink.Hotkey = "" ' 设置快捷方式的快捷键>>%vbsfn%
echo oShellLink.IconLocation = "%iconPath%" ' 设置快捷方式的图标路径>>%vbsfn%
echo oShellLink.Description = "%~f1" ' 设置快捷方式的描述>>%vbsfn%
echo oShellLink.WorkingDirectory = "%~dp1" ' 起始位置>>%vbsfn%
echo oShellLink.Save>>%vbsfn%
cscript //nologo %vbsfn%
pause>nul
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答