一、示例為創建記事本的快捷方式到桌面
set path=%WINDIR%\notepad.exe
set topath="%USERPROFILE%\桌面\記事本.url"
echo [InternetShortcut] >> %topath%
echo URL="%path%" >> %topath%
echo IconIndex=0 >> %topath%
echo IconFile=%path% >> %topath%
二、利用批處理創建桌面快捷方式
goto :eof
Rem 以下為VbScript腳本
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'特殊文件夾“桌面”
Rem 在桌面創建一個記事本快捷方式
set oShellLink = WshShell.CreateShortcut(strDesktop & "\記事本.lnk")
oShellLink.TargetPath = "notepad.exe" : '目標
oShellLink.WindowStyle = 3 :'參數1默認窗口激活,參數3最大化激活,參數7最小化
oShellLink.Hotkey = "Ctrl+Alt+e" : '快捷鍵
oShellLink.Ic : '圖標
oShellLink.Description = "記事本快捷方式" : '備注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '創建保存快捷方式
Rem 在桌面創建一個 騰訊QQ 2007
set oShellLink = WshShell.CreateShortcut(strDesktop & "\騰訊QQ 2007 .lnk")
oShellLink.TargetPath = "D:\Tencent\QQ\QQ.exe" : '目標
oShellLink.WindowStyle = 3 :'參數1默認窗口激活,參數3最大化激活,參數7最小化
oShellLink.Hotkey = "Ctrl+Alt+q" : '快捷鍵
oShellLink.Ic : '圖標
oShellLink.Description = "騰訊QQ 2007" : '備注
oShellLink.WorkingDirectory = strDesktop : '起始位置
oShellLink.Save : '創建保存快捷方式
Rem 在桌面創建一個“微軟中國”的Url快捷方式
set oUrlLink = WshShell.CreateShortcut(strDesktop & "\百度搜索.url")
oUrlLink.TargetPath = "http://www.baidu.com/"
oUrlLink.Save
三、批處理桌面創建快捷方式
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 & "\學習天地.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
五、在桌面上創建某網站的快捷方式
@echo off
set lnkdir="%USERPROFILE%\桌面"
echo [InternetShortcut] >%lnkdir%\沖浪奧運專題.url
echo [InternetShortcut] >%lnkdir%\沖浪奧運頻道.url
echo URL="http://www.cctvolympics.com" >>%lnkdir%\沖浪奧運專題.url
echo URL="http://www.fm73.com/dianshi/001/cctv5.htm" >>%lnkdir%\沖浪奧運頻道.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"
)
開始沒仔細看.后來試了一下,原來是利用了file(本地文件傳輸協議),但有個缺點,ie會把文件加載到ie緩存文件夾中執行,所以當為需要多個文件才能執行的綠色文件創建快捷方式時,運行會出錯.
在來看看我的那個(不是我寫的,在知道上看到的,分析后改的)
又改了,可以將任意文件拖放到該文件上,即可自動創建快捷方式,不需更改代碼.
這個代碼應該是里利用winrar的自解壓功能,具體也沒研究出來,貼上用到的rar命令行參數說明
@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.
:: 當使用命令 'a','u','f','m' 將處理在所有子目錄中以及當前工作目
:: 錄的中的文件。
:: 當使用命令 x,e,t,p,v,l,c,cf 或 s 將處理在子目錄以及當前工
:: 作目錄中所有壓縮文件。
:: -ep1 從文件名中刪除底層目錄。不存儲在命令行中輸入的路徑。
:: 例子:
:: tmp 目錄中的所有文件和目錄都將被添加到壓縮文件'test'中,但是被壓
:: 縮文件名路徑不包含'tmp\'
:: rar a -ep1 -r test tmp\*
:: 這等價於下列命令:
:: cd tmp
:: rar a -r ..\test
:: cd ..
::-m1 最快 使用最快方式(低壓縮)
:: -sfx[名稱]
:: 創建自解壓壓縮文件。如果建立新壓縮文件時使用此開關,自解壓文件(使
:: 用 default.sfx 模塊或在開關中指定)將被創建。在 Windows 版本中,
:: default.sfx 應該在 rar.exe 所在的目錄中,在 Unix 中 - 在用戶的 home
:: 目錄中。在/usr/lib 或 /usr/local/lib 中。
:: 例子:
:: rar a -sfxwincon.sfx myinst
:: 使用 wincon.sfx 自解壓模塊創建自解壓(SFX)壓縮文件。
:: -z[f] 從文件<f>中讀取壓縮文件注釋。如果你需要指定注釋文本文件的字符
:: 集使用 -sc 開關。如果 <f> 沒有指定, 注釋從標准輸入設備讀取。
