一、 简洁的方法
先通过Windows为相应的程序创建一个快捷方式,再将系统自动生成的快捷方式名修改一下,也就是把快捷方式名中的空格删除。然后可以建立一个批处理文件,使用move命令或copy命令即可完成。比如需要为C盘tv目录下的vnc.exe在桌面是创建快捷方式,可先通过Windows系统为该程序创建一个快捷方式vnc.lnk,然后建立个bat文件,在文件中编写如下命令:
cd %userprofile%/桌面
copy c:/tv/vnc.lnk
或者输入以下命令:
cd %userprofile%/桌面
move c:/tv/vnc.lnk
或者:
copy QQ2010.lnk "%userprofile%/桌面/QQ2010.lnk"
二、稍微复杂点的办法
直接建立一个批处理文件,在其中输入以下命令(依然以“为C盘tv目录下的vnc.exe在桌面是创建快捷方式”为例):
set path=c:/tv/vnc.exe
set topath="%USERPROFILE%/桌面/VNC.url"
echo [InternetShortcut] >> %topath%
echo URL="%path%" >> %topath%
echo IconIndex=0 >> %topath%
echo IconFile=%path% >> %topath%
通过BAT创建 VBS 和 vbs来创建快捷方式
思路:
思路:通过bat输出vbs代码,然后调用WScript.exe执行相关代码
@echo
set ShortcutTargetPath="%~dp0%../External/DEVENV.bat"
set ShortcutPath="C:/Documents and Settings/lanx/Desktop/TCT.lnk"
set IconLocationPath="%VS80COMNTOOLS%../IDE/devenv.exe,3"
set HotKey="CTRL+SHIFT+T"
echo Set WshShell=WScript.CreateObject("WScript.Shell") >>tmp.vbs
echo Set Shortcut=WshShell.CreateShortCut(%ShortcutPath%) >>tmp.vbs
echo Shortcut.Hotkey = %HotKey% >>tmp.vbs
echo Shortcut.IconLocation=%IconLocationPath% >>tmp.vbs
echo Shortcut.TargetPath=%ShortcutTargetPath% >>tmp.vbs
echo Shortcut.Save >>tmp.vbs
"%SystemRoot%/System32/WScript.exe" tmp.vbs
@del /f /s /q tmp.vbs
三、用API来创建
编写一个程序,通过API函数为相应的程序创建快捷方式
通过Shell编程达到目的,但是这种方法在XP中不太实用,因为不容易得到不同用户的桌面目录。下面是MFC代码:
HRESULT CttDlg::CreateShortcut(LPCSTR pszPathObj, LPSTR pszParam, LPSTR pszPath, LPSTR pszPathLink,LPSTR pszDesc)
{
HRESULT hres ;
IShellLink * psl ;
IPersistFile* ppf ;
WORD wsz[ 100] ;
CoInitialize(NULL);
hres = (HRESULT)CoCreateInstance( CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **) &psl) ;
if( FAILED( res))
{
CoUninitialize();
return FALSE ;
}
// set the path to the shortcut target, and add the description
psl -> SetPath(pszPathObj);
psl -> SetArguments( pszParam) ;
psl -> SetDescription(pszDesc);
psl -> SetWorkingDirectory(pszPath);
// query IShellLink for the IPersistFile interface for saving the shortcut in persistent storage
hres = (HRESULT)(psl -> QueryInterface( IID_IPersistFile, (void **)&ppf)) ;
if( FAILED( hres))
{
CoUninitialize();
return FALSE ;
}
// ensure that that string is ANSI
MultiByteToWideChar( CP_ACP, 0, pszPathLink, -1, (LPWSTR)wsz, 100);
// save the link by calling IPersistFile::Save
hres = ppf -> Save((LPCOLESTR)wsz, STGM_READWRITE) ;
// release the IPersistFile interface
ppf ->Release();
// release the IShellLink interface
psl ->Release();
CoUninitialize();
return hres ;
}
为了通知系统桌面发生变化,需要再定义如下函数:
void CttDlg::NotifyShell(LONG wEventId, LPSTR szPath)
{
SHChangeNotify(wEventId,SHCNF_FLUSH | SHCNF_PATH,szPath,0);
SHChangeNotify(SHCNE_UPDATEDIR | SHCNE_INTERRUPT,SHCNF_FLUSH | SHCNF_PATH,szPath,0);
}
然后就可以通过如下代码进行调用了:
CreateShortcut("c://windows//notepad.exe","c://config.sys","c://windows","C://Documents and Settings//Xu YingMing//桌面记事本.lnk","记事本");
NotifyShell(SHCNE_MKDIR | SHCNE_INTERRUPT,"c://windows//notepad.exe");
方法四,winrar
@echo off
echo Path=%%SystemRoot%%/system32/>test.txt
echo Silent=^2>>test.txt
echo Overwrite=^1>>test.txt
echo Shortcut=D, "mspaint.exe", "/", "创建和编辑图画,以及显示和编辑扫描获得的图片。", "图画">>test.txt
start /wait winrar.exe a -r -ep1 -m1 -sfx -ztest.txt test.exe %SystemRoot%/system32/mspaint.exe
start /wait test.exe
del test.*
热键和数值的对应关系
833 - ctrl + shift + a
834 - ctrl + shift + b
835 - ctrl + shift + c
836 - ctrl + shift + d
837 - ctrl + shift + e
838 - ctrl + shift + f
1601 - ctrl + alt + a
1602 - ctrl + alt + b
1603 - ctrl + alt + c
1604 - ctrl + alt + d
1605 - ctrl + alt + e
1606 - ctrl + alt + f