• 微软原版系统

  • 一键重装系统

  • 纯净系统

  • 在线技术客服

魔法猪系统重装大师 一键在线制作启动 U 盘 PE 系统 用一键重装的魔法拯救失去灵魂的系统
当前位置:首页 > 教程 > 电脑教程

用bat创建的快捷方式

时间:2015年04月02日 15:40:18    来源:魔法猪系统重装大师官网    人气:17835

 首选BAT是无法自已创建 LNK的快捷方式的, URL的快捷方式可以创建

一、 简洁的方法

先通过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");

              以上三种方法皆可实现目的,但是前两种相对简单,而第三种方法就要复杂的多。


 

用,bat,创建,的,快捷方式,首选,BAT,是,无法,
栏目:电脑教程 阅读:1000 2023/12/27
Win7教程 更多>>
U盘教程 更多>>
Win10教程 更多>>
魔法猪学院 更多>>

Copyright © 2015-2023 魔法猪 魔法猪系统重装大师

本站发布的系统仅为个人学习测试使用,请在下载后24小时内删除,不得用于任何商业用途,否则后果自负,请支持购买微软正版软件。

在线客服 查看微信 返回顶部