Batch Create Shortcut

Batch, create a shortcut to the file, more convenient it is to call vbs script. Combined for command, you can create a shortcut to batch multiple files. Use function Winrar software, can more easily create self-extracting install the software.

File encoding batch file to ANSI, or GB2312. Otherwise the Chinese will be garbled.

A single file to create a shortcut

If you use the Chrome 75 MyChrome green portability to D: \ programfiles \ Chrome75 folder, the executable file is MyChrome.exe. Create the following MyChrome.exe shortcut and send it to the desktop, creating "Google Browser" in the program group, including MyChrome.exe shortcuts.

@echo off

::如无:快捷文件以.lnk或.url结尾
setlocal EnableDelayedExpansion

cd Chrome75
set WrkDir=%~dp0

set "LinkName=谷歌浏览器.lnk"
set filname=mychrome.exe
set ThePath=%~dp0%mychrome.exe
mshta VBScript:Execute("Set Shell=CreateObject(""WScript.Shell""):Set Link=Shell.CreateShortcut(""!LinkName!""):Link.TargetPath=""!ThePath!"":Link.WorkingDirectory=""!WrkDir!"":Link.Save:close"^)

if exist "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\谷歌浏览器" (
  del /Q "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\谷歌浏览器"
) else (
  mkdir "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\谷歌浏览器"
)

copy /y 谷歌浏览器.lnk "%USERPROFILE%\Desktop\" >nul 2>nul
move /y *.lnk "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\谷歌浏览器\" >nul 2>nul

In the latter due to the self-extracting file, save the batch is named "Chrome self-extracting installation .bat", placed in the directory MyChome.exe located. Click Run will be able to meet the design requirements.

Batch, created directly MyChrome.exe shortcut "Google Browser .lnk" in the current directory. Next, create a program group of the Start menu. Copy the shortcut to the desktop, and then move the shortcut to the program group file folder.

You can also create a shortcut directly on the desktop, and then copy the shortcut to the file in the program group.

setlocal EnableDelayedExpansionThere must be, otherwise it will prompt ".lnk shortcut files ending or .url" error.

Simple way

If you just want to create a desktop shortcut MyChrome.exe, the easiest way is as follows (note that does not require setlocal EnableDelayedExpansion):

@echo off

mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\谷歌浏览器.lnk""):b.TargetPath=""%~dp0MyChrome.exe"":b.WorkingDirectory=""%~dp0"":b.Save:close")

Multiple batch files to create a shortcut

Assume that you want to create a shortcut of the file "Heroes magic awakening" in the. Claim:

  • The desktop is the main program h3era HD.exeshortcut
  • Program Group "magic Awakening" contains shortcuts to the following files:
    • h3era HD.exe
    • h3era_34M HD.exe
    • h3era_43M HD.exe
    • Tools\Mod Manager\mmanager.exe
    • Tools\ERM&ERA帮助宝典v2.0 (测试).chm
    • HD3_Launcher.exe

Magic awakening folder D:\ProgramFiles\gs\Hero3_The_Magic_Awakens\, which is h3era HD.exe(or h3era.exe/ Heroes3.exefile) is located.

The following batch or txt files are saved in the magic of the awakening folder.

MagAwaken.txt

First create a txt file "MagAwaken.txt", reads as follows:

魔力觉醒:h3era HD.exe
魔力觉醒34M:h3era_34M HD.exe
魔力觉醒43M:h3era_43M HD.exe
MOD管理器:Tools\Mod Manager\mmanager.exe
ERM&ERA帮助宝典v2:Tools\ERM&ERA帮助宝典v2.0 (测试).chm
高清补丁:HD3_Launcher.exe

Batch MagAwaken.bat

Batch file MagAwaken.bat, as follows:

@echo off
rem 快捷方式 by [email protected](开心鲨鱼@qq)

color 0a
title “英雄无敌WOG之魔力觉醒” 快捷方式 by [email protected](开心鲨鱼@qq)

cd Hero3_The_Magic_Awakens
set WrkDir=%~dp0

setlocal EnableDelayedExpansion

for /f "delims=: tokens=1,*" %%a in (MagAwaken.txt) do (
  set LinkName=%%a.lnk
  set filname=%%b
  set ThePath=%~dp0%%b
  mshta VBScript:Execute("Set Shell=CreateObject(""WScript.Shell""):Set Link=Shell.CreateShortcut(""!LinkName!""):Link.TargetPath=""!ThePath!"":Link.WorkingDirectory=""!WrkDir!"":Link.Save:close"^)
)

if exist "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\英雄无敌WOG之魔力觉醒" (
  del /Q "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\英雄无敌WOG之魔力觉醒"
) else (
  mkdir "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\英雄无敌WOG之魔力觉醒"
)

copy /y 魔力觉醒.lnk "%USERPROFILE%\Desktop\" >nul 2>nul
move /y *.lnk "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\英雄无敌WOG之魔力觉醒\" >nul 2>nul

Application in Winrar self-extracting file

How to make a self-extracting file with Winrar?

  1. Right folder and select "Add to archive ..."
  2. In the "Compression Options" "General" tab item, check the file "to create self-extracting compressed file format", then "compressed file name" at the extension exe
  3. If no special requirements or configuration, and click OK. Otherwise, see the next step
  4. Switch to the "Advanced" tab, click on the "self-extracting file option ..."
  5. "Advanced SFX options", click "Settings" tab, enter the program after extraction is completed to be run in batch or "unzip or run"
  6. Other Options tab, not be discussed.

The following self-extracting combine to make Chrome instructions.

  • Make sure to start saving files Chrome自解压安装.batin D:\programfiles\Chrome75folders.
  • Into the D:\programfiles\folder, wherein the right Chrome75folder, as shown in the above steps.
  • In the fifth step above, the input is provided Chrome75\Chrome自解压安装.batto.
  • Get self-extracting fileD:\programfiles\Chrome75.exe
  • Test: Double-click Chrome75.exe, point "Extract" (default "destination folder" is D:\), extract the files and get D:\Chrome75, and generate the shortcuts and the program group.

Above Additional information:

  • When extracting, Winrar will enter the specified "Destination Folder", the default here "destination folder" Yes D:\.
  • According to the compression settings, run the file specified. Here is a run Chrome75\Chrome自解压安装.bat. Note that the position is still D:\, did not enter the D:\Chrome75folder. So batch, did not comment out cd Chrome75(does not affect the results of the previous batch)

references

  1. Create a desktop shortcut to the batch file
  2. Create a shortcut to achieve volume batch

Guess you like

Origin www.cnblogs.com/ourweiguan/p/11247528.html