Code for creating shortcuts using vbs

Time:2021-12-28

During the maintenance of Internet cafes, desktop shortcuts are often sent. What batch processing method can easily send desktop shortcuts? Take the steam distribution of Internet cafes here as an example to give you a reference. If you want to directly copy the following code and change the specific parameters. The code is as follows:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@echo off
:: set the path of the program or file (required)
set Program=D:\Program Files\Microvirt\MEmu\MEmu.exe
 
:: set startup parameters (optional)
set  Arguments=
 
:: set shortcut name (required)
set LnkName=test
 
:: set the working path of the program, generally the program home directory. If this item is left blank, the script will analyze the path by itself
set WorkDir=
 
: set the description of shortcut display (optional)
set Desc=
 
if not defined WorkDir call:GetWorkDir "%Program%"
(echo Set WshShell=CreateObject("WScript.Shell"^)
echo strDesKtop=WshShell.SpecialFolders("DesKtop"^)
echo Set oShellLink=WshShell.CreateShortcut(strDesKtop^&"\%LnkName%.lnk"^)
echo oShellLink.TargetPath="%Program%"
echo oShellLink.Arguments="%Arguments%"
echo oShellLink.WorkingDirectory="%WorkDir%"
echo oShellLink.WindowStyle=1
echo oShellLink.Description="%Desc%"
echo oShellLink.Save)>makelnk.vbs
echo Desktop shortcut created successfully!
makelnk.vbs
del /f /q makelnk.vbs
exit
goto :eof
:GetWorkDir
set WorkDir=%~dp1
set WorkDir=%WorkDir:~,-1%
goto :eof

VBS:

The first is an application example of creating shortcuts on the desktop

?
1
2
3
4
5
6
7
8
9
10
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'special folder 'desktop'
set oShellLink = WshShell.CreateShortcut(strDesktop & "\ calculator.lnk")
oShellLink.TargetPath = "C:\Windows\System32\Calc.exe" : 'target
oShellLink.WindowStyle = 3 :'parameter 1 is activated by default, parameter 3 is activated by maximization, and parameter 7 is minimized
oShellLink.Hotkey = "Ctrl+Alt+C" : 'shortcut key
oShellLink.IconLocation = "C:\Windows\System32\Calc.exe" : 'Icon
oShellLink.Description = "System default calculator" : 'remarks
oShellLink.WorkingDirectory = strDesktop : 'Start position
oShellLink.Save : 'create save shortcut

The second is an application example of creating a shortcut on a custom directory location

?
1
2
3
4
5
6
7
8
9
Set WshShell = WScript.CreateObject("WScript.Shell")
set oShellLink = WshShell.CreateShortcut("C: \ documents and settings \ administrator \ calculator debugging.lnk")
oShellLink.IconLocation = "C:\Documents and Settings\Administrator\Calc.exe" : 'Icon
oShellLink.TargetPath = "C:\Documents and Settings\Administrator\Calc.exe" : 'target
oShellLink.WorkingDirectory = "C:\Documents and Settings\Administrator\" : 'Start position
oShellLink.Hotkey = "Ctrl+Alt+C" : 'shortcut key
oShellLink.WindowStyle = 3 :'operation mode: parameter 1 is activated by default, parameter 3 is activated by maximization, and parameter 7 is minimized
oShellLink.Description = "System default calculator" : 'remarks
oShellLink.Save : 'create save shortcut

Save the following as XXX js

It is also VBS often called in bat

?
1
2
3
4
5
6
7
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shl = WScript.CreateObject("WScript.Shell");
var oUrl = shl.CreateShortcut("C: \ documents and settings \ administrator \ favorites \ \ game menu.lnk");
oUrl.TargetPath = "E:\\nbmsclient\\BarClientView.exe";
oUrl.IconLocation = "E:\\nbmsclient\\BarClientView.exe";
oUrl.WorkingDirectory = "E:\\nbmsclient";
oUrl.Save();

You can add the following to judge the system board:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
set oShellLink = WshShell.CreateShortcut(strDesktop & "\ XXX system. LNK")
 
Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")       
If fso.folderExists("C:\\Program Files (x86)") Then 'determine whether it is a 32-bit or 64 bit operating system through the directory
    oShellLink.TargetPath = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 'target
    oShellLink.WorkingDirectory = "C:\Program Files (x86)\Google\Chrome\Application\" 'Start position
Else
    oShellLink.TargetPath = "C:\Program Files\Google\Chrome\Application\chrome.exe"
    oShellLink.WorkingDirectory = "C:\Program Files\Google\Chrome\Application\"    
End If
oShellLink.Arguments = "http://192.168.0.1:8080/xxx/" 'operating parameters
oShellLink.WindowStyle = 1 'parameter 1 is activated by default, parameter 3 is activated by maximization, and parameter 7 is minimized
oShellLink.Hotkey = "" 'shortcut key
oShellLink.IconLocation = "C:\Program Files\ChromeStandaloneSetup\favicon.ico" 'Icon
oShellLink.Description = ""
oShellLink.Save 'create save shortcut

Support with parameters

?
1
2
3
4
5
6
7
8
9
10
11
set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") 'get desktop path
set oShellLink = WshShell.CreateShortcut(strDesktop & "\ Tencent QQ. LNK")   'the full path to which the shortcut will be saved
oShellLink.TargetPath = "http://www.hao123.com/" 'target 'in shortcut
oShellLink.Arguments = "/ Parameter1 / parameter2"    '' operation parameters of "target". If there are no parameters, directly = ""
oShellLink.WindowStyle = 1   'run as' in shortcut
oShellLink.Hotkey = "Ctrl+Alt+e"   'shortcut key in shortcut
oShellLink.IconLocation = "C:\Program Files\Tencent\qq.exe, 0"   'icon for shortcut
oShellLink.Description = "Tencent QQ"   'notes in shortcut
oShellLink.WorkingDirectory = "C:\Program Files\Tencent"   'Start position in shortcut
oShellLink.Save 'create a shortcut using the above settings

The following is the supplement of other netizens

Detailed description of creating shortcuts with vbs

Save the following as XXX VBS

The first is an application example of creating shortcuts on the desktop

?
1
2
3
4
5
6
7
8
9
10
Set WshShell = WScript.CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") :'special folder 'desktop'
set oShellLink = WshShell.CreateShortcut(strDesktop & "\ calculator.lnk")
oShellLink.TargetPath = "C:\Windows\System32\Calc.exe" : 'target
oShellLink.WindowStyle = 3 :'parameter 1 is activated by default, parameter 3 is activated by maximization, and parameter 7 is minimized
oShellLink.Hotkey = "Ctrl+Alt+C" : 'shortcut key
oShellLink.IconLocation = "C:\Windows\System32\Calc.exe" : 'Icon
oShellLink.Description = "System default calculator" : 'remarks
oShellLink.WorkingDirectory = strDesktop : 'Start position
oShellLink.Save : 'create save shortcut

The second is an application example of creating a shortcut on a custom directory location

?
1
2
3
4
5
6
7
8
9
Set WshShell = WScript.CreateObject("WScript.Shell")
set oShellLink = WshShell.CreateShortcut("C: \ documents and settings \ administrator \ calculator debugging.lnk")
oShellLink.IconLocation = "C:\Documents and Settings\Administrator\Calc.exe" : 'Icon
oShellLink.TargetPath = "C:\Documents and Settings\Administrator\Calc.exe" : 'target
oShellLink.WorkingDirectory = "C:\Documents and Settings\Administrator\" : 'Start position
oShellLink.Hotkey = "Ctrl+Alt+C" : 'shortcut key
oShellLink.WindowStyle = 3 :'operation mode: parameter 1 is activated by default, parameter 3 is activated by maximization, and parameter 7 is minimized
oShellLink.Description = "System default calculator" : 'remarks
oShellLink.Save : 'create save shortcut

Save the following as XXX js

The third is an application example of creating shortcuts with JS classes in a custom directory location

?
1
2
3
4
5
6
7
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shl = WScript.CreateObject("WScript.Shell");
var oUrl = shl.CreateShortcut("C: \ documents and settings \ administrator \ favorites \ \ game menu.lnk");
oUrl.TargetPath = "E:\\nbmsclient\\BarClientView.exe";
oUrl.IconLocation = "E:\\nbmsclient\\BarClientView.exe";
oUrl.WorkingDirectory = "E:\\nbmsclient";
oUrl.Save();

From the comparison between VBS and JS scripts above, we can find that they have something in common. At the beginning, such scripts should declare the following contents and what program to parse and run. After declaration, the next step is the specific steps

See how to call VBS in bat.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@echo off
Title developer desktop shortcut creation tool!
 
>nul 2>&1 REG.exe query "HKU\S-1-5-19" || (
    ECHO SET UAC = CreateObject^("Shell.Application"^) > "%TEMP%\Getadmin.vbs"
    ECHO UAC.ShellExecute "%~f0", "%1", "", "runas", 1 >> "%TEMP%\Getadmin.vbs"
    "%TEMP%\Getadmin.vbs"
    DEL /f /q "%TEMP%\Getadmin.vbs" 2>nul
    Exit /b
)
set jb51name=Ditto3.lnk
set jb51path=%~dp0
set jb51exec=%~dp0Ditto.exe
 
mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\%jb51name%""):b.TargetPath=""%jb51exec%"":b.WorkingDirectory=""%jb51path%"":b.Save:close")

This is the end of this article about the code of creating shortcuts with VBS. For more information about creating shortcuts with VBS, please search the previous articles of developeppaper or continue to browse the relevant articles below. I hope you will support developeppaper in the future!

Recommended Today

Hive Foundation

1、 Hive basic concepts Hive is a data warehouse tool based on Hadoop. It can map structured data files into a table and provide SQL like query functions. The essence is:Convert HQL into MapReduce program flow chart Architecture Principle Architecture diagram User interface (client):cli (hive shell), jdbc/odbc (Java access hive), webui (browser access hive) Metadata: […]