怎么用.bat来创建快捷方式?

要把某个文件夹创建快捷方式到指定的一个位置。

今天小凡将教你bat创建快捷方式,首选是告诉大家bat自己无法创建lnk快捷方式,但你可以创建url快捷方式,让我们学习下一个bat创建快捷方式。

  一、 简洁的方法

  先通过Windows为相应的程序创建一个快捷方式,再将系统自动生成的快捷方式名修改一下,也就是把快捷方式名中的空格删除。然后可以建立一个批处理文件,使用move命令或copy命令即可完成。比如需要为C盘tv目录下的vnc.exe在桌面是创建快捷方式,可先通过Windows系统为该程序创建一个快捷方式vnc.lnk,然后建立个bat文件,在文件中编写如下命令:

  cd %userprofile%\桌面

  copy c: v nc.lnk

  或者输入以下命令:

  cd %userprofile%\桌面

  move c: v nc.lnk

  或者:

  copy QQ2010.lnk "%userprofile%\桌面\QQ2010.lnk"

  二、稍微复杂点的办法

  直接建立一个批处理文件,在其中输入以下命令(依然以“为C盘tv目录下的vnc.exe在桌面是创建快捷方式”为例):

  set path=c: v nc.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 ;

  }
温馨提示:答案为网友推荐,仅供参考
相似回答