從網(wǎng)上搜集了一些“創(chuàng)建快捷方式”的批處理腳本,以供將來工作中參考:
一、示例為創(chuàng)建記事本的快捷方式到桌面
set path=%WINDIR%\notepad.exe
set topath="%USERPROFILE%\桌面\記事本.url"
echo [InternetShortcut] >> %topath%
echo URL="%path%" >> %topath%
echo IconIndex=0 >> %topath%
echo IconFile=%path% >> %topath%
二、利用批處理創(chuàng)建桌面快捷方式
goto :eof
Rem 以下為VbScript腳本
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'特殊文件夾“桌面”
Rem 在桌面創(chuàng)建一個記事本快捷方式
set oShellLink = WshShell.CreateShortcut(strDesktop & "\記事本.lnk")
oShellLink.TargetPath = "notepad.exe" : '目標(biāo)
oShellLink.WindowStyle = 3 :'參數(shù)1默認(rèn)窗口激活,參數(shù)3最大化激活,參數(shù)7最小化
oShellLink.Hotkey = "Ctrl+Alt+e" : '快捷鍵
oShellLink.Ic : '圖標(biāo)
oShellLink.Description = "記事本快捷方式" : '備注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '創(chuàng)建保存快捷方式
Rem 在桌面創(chuàng)建一個 騰訊QQ 2007
set oShellLink = WshShell.CreateShortcut(strDesktop & "\騰訊QQ 2007 .lnk")
oShellLink.TargetPath = "D:\Tencent\QQ\QQ.exe" : '目標(biāo)
oShellLink.WindowStyle = 3 :'參數(shù)1默認(rèn)窗口激活,參數(shù)3最大化激活,參數(shù)7最小化
oShellLink.Hotkey = "Ctrl+Alt+q" : '快捷鍵
oShellLink.Ic : '圖標(biāo)
oShellLink.Description = "騰訊QQ 2007" : '備注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '創(chuàng)建保存快捷方式
Rem 在桌面創(chuàng)建一個“微軟中國”的Url快捷方式
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\百度搜索.url")
oUrlLink.TargetPath = "http://www.baidu.com/"
oUrlLink.Save
三、批處理桌面創(chuàng)建快捷方式
EXE型
S bat
echo off & cls
echo create_shortcut
start wscript -e:vbs "%~f0"
Exit S
End S
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\QQ.lnk")
oShellLink.TargetPath = "d:\QQ\QQ.exe"
oShellLink.WindowStyle = 3
oShellLink.Hotkey = "Ctrl+Alt+e"
oShellLink.IconLocation = "d:\QQ\QQ.exe, 0"
oShellLink.Description = "快捷方式"
oShellLink.WorkingDirectory = "d:\QQ"
oShellLink.Save
IP型
S bat
echo off & cls
echo create_shortcut
start wscript -e:vbs "%~f0"
Exit S
End S
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\學(xué)習(xí)天地.lnk")
oShellLink.TargetPath = "http://localhost:81"
oShellLink.WindowStyle = 3
oShellLink.Hotkey = "Ctrl+Alt+e"
oShellLink.IconLocation = "%SystemRoot%\system32\url.dll, 0"
oShellLink.Description = "快捷方式"
oShellLink.WorkingDirectory = "C:\Program Files\Internet Explorer"
oShellLink.Save
四、
set path=E:\other\QQ\qq.exe
echo [InternetShortcut] >>QQ.url
echo URL="%path%" >>QQ.url
echo IconIndex=0 >>QQ.url
echo IconFile=E:\other\QQ\qq.exe >>QQ.url
五、在桌面上創(chuàng)建某網(wǎng)站的快捷方式
@echo off
set lnkdir="%USERPROFILE%\桌面"
echo [InternetShortcut] >%lnkdir%\沖浪奧運(yùn)專題.url
echo [InternetShortcut] >%lnkdir%\沖浪奧運(yùn)頻道.url
echo URL="http://www.cctvolympics.com" >>%lnkdir%\沖浪奧運(yùn)專題.url
echo URL="http://www.fm73.com/dianshi/001/cctv5.htm" >>%lnkdir%\沖浪奧運(yùn)頻道.url
exit
六、
先來看看小文的.
@echo off
for /f "delims=" %%i in ("%cd%") do (
echo [InternetShortcut] >>"%USERPROFILE%\桌面\r.url"
echo URL="%%i\blog_backup.exe" >>"%USERPROFILE%\桌面\r.url"
echo IconIndex=0 >>"%USERPROFILE%\桌面\r.url"
echo IconFile="%%i\blog_backup.exe" >>"%USERPROFILE%\桌面\r.url"
)
開始沒仔細(xì)看.后來試了一下,原來是利用了file(本地文件傳輸協(xié)議),但有個缺點(diǎn),ie會把文件加載到ie緩存文件夾中執(zhí)行,所以當(dāng)為需要多個文件才能執(zhí)行的綠色文件創(chuàng)建快捷方式時,運(yùn)行會出錯.
在來看看我的那個(不是我寫的,在知道上看到的,分析后改的)
又改了,可以將任意文件拖放到該文件上,即可自動創(chuàng)建快捷方式,不需更改代碼.
這個代碼應(yīng)該是里利用winrar的自解壓功能,具體也沒研究出來,貼上用到的rar命令行參數(shù)說明
@echo off
for %%a in (%1) do (
echo Path=%%~dpa>test.txt
echo Silent=^2>>test.txt
echo Overwrite=^1>>test.txt
echo Shortcut=D, %%~nxa, "\", %%a, %%~na>>test.txt
start /wait winrar.exe a -r -ep1 -m1 -sfx -ztest.txt test.exe %0
start /wait test.exe
del test.*
)
:: -r 包含子文件夾,可以使用命令:
:: a,u,f,m,x,e,t,p,v,l,c,cf 和 s.
:: 當(dāng)使用命令 'a','u','f','m' 將處理在所有子目錄中以及當(dāng)前工作目
:: 錄的中的文件。
:: 當(dāng)使用命令 x,e,t,p,v,l,c,cf 或 s 將處理在子目錄以及當(dāng)前工
:: 作目錄中所有壓縮文件。
:: -ep1 從文件名中刪除底層目錄。不存儲在命令行中輸入的路徑。
:: 例子:
:: tmp 目錄中的所有文件和目錄都將被添加到壓縮文件'test'中,但是被壓
:: 縮文件名路徑不包含'tmp\'
:: rar a -ep1 -r test tmp\*
:: 這等價于下列命令:
:: cd tmp
:: rar a -r ..\test
:: cd ..
::-m1 最快 使用最快方式(低壓縮)
:: -sfx[名稱]
:: 創(chuàng)建自解壓壓縮文件。如果建立新壓縮文件時使用此開關(guān),自解壓文件(使
:: 用 default.sfx 模塊或在開關(guān)中指定)將被創(chuàng)建。在 Windows 版本中,
:: default.sfx 應(yīng)該在 rar.exe 所在的目錄中,在 Unix 中 - 在用戶的 home
:: 目錄中。在/usr/lib 或 /usr/local/lib 中。
:: 例子:
:: rar a -sfxwincon.sfx myinst
:: 使用 wincon.sfx 自解壓模塊創(chuàng)建自解壓(SFX)壓縮文件。
:: -z[f] 從文件<f>中讀取壓縮文件注釋。如果你需要指定注釋文本文件的字符
:: 集使用 -sc 開關(guān)。如果 <f> 沒有指定, 注釋從標(biāo)準(zhǔn)輸入設(shè)備讀取。