Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write code for VBS to create shortcuts

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article focuses on "how to write VBS to create shortcuts code", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write the code for creating shortcuts in VBS.

The code is as follows:

@ echo off:: sets the path to the program or file (required) set Program=D:\ Program Files\ Microvirt\ MEmu\ MEmu.exe:: sets startup parameters (optional) set Arguments=:: sets shortcut name (required) set LnkName=test:: sets the working path of the program, usually the home directory of the program, if left blank The script will analyze the description of the path set WorkDir=:: settings 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=1echo oShellLink.Description= "% Desc%" Echo oShellLink.Save) > makelnk.vbsecho desktop shortcut created successfully! Makelnk.vbsdel / f / q makelnk.vbsexitgoto: eof:GetWorkDirset WorkDir=%~dp1set WorkDir=%WorkDir:~,-1%goto: eof

_ VBS:

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

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 default window activation, parameter 3 maximum activation Parameter 7 minimize 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 a save shortcut

The second is an application example of creating shortcuts in custom directory locations

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\": 'starting position oShellLink.Hotkey = "Ctrl+Alt+C": 'Shortcut oShellLink.WindowStyle = 3: 'operation mode Parameter 1 default window activation, parameter 3 maximize activation, parameter 7 minimizes oShellLink.Description = "system default calculator": 'remarks oShellLink.Save:' create a save shortcut

Save the following as XXX.js

It is also the vbs that is often called in bat

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 ()

Can be added to judge the system board:

Set WshShell = WScript.CreateObject ("WScript.Shell") strDesktop = WshShell.SpecialFolders ("Desktop") set oShellLink = WshShell.CreateShortcut (strDesktop & "\ xxx system .lnk") Dim fsoSet fso=CreateObject ("Scripting.FileSystemObject") If fso.folderExists ("C:\\ Program Files (x86)") Then 'determines whether it is a 32-bit or 64-bit operating system oShellLink.TargetPath = "C:\ Program Files (x86)\ Google\ Chrome\ Application\ chrome" by directory .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 IfoShellLink.Arguments = "http://192.168.0.1:8080/xxx/" 'Operation Parameter oShellLink.WindowStyle = 1' Parameter 1 default window Activation Parameter 3 maximizes activation, parameter 7 minimizes oShellLink.Hotkey = "" 'shortcut key oShellLink.IconLocation = "C:\ Program Files\ ChromeStandaloneSetup\ favicon.ico"' icon oShellLink.Description = "" oShellLink.Save "to create a save shortcut

With parameters are supported

Set WshShell = WScript.CreateObject ("WScript.Shell") strDesktop = WshShell.SpecialFolders ("Desktop") 'get the desktop path set oShellLink = WshShell.CreateShortcut (strDesktop & "\ Tencent QQ.lnk")' the full path to be saved by the shortcut oShellLink.TargetPath = "target" oShellLink.Arguments = "/ parameter 1 / parameter 2"'"target" in the shortcut. If there are no parameters, Direct = "oShellLink.WindowStyle = 1 'shortcut" operation mode oShellLink.Hotkey = "Ctrl+Alt+e"' shortcut oShellLink.IconLocation = "C:\ Program Files\ Tencent\ qq.exe 0 "'shortcut icon oShellLink.Description =" Tencent QQ "shortcut" remarks "oShellLink.WorkingDirectory =" C:\ Program Files\ Tencent "in the shortcut" start position "oShellLink.Save' use the above settings to create the shortcut

Here are some additions from 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

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 default window activation, parameter 3 maximum activation Parameter 7 minimize 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 a save shortcut

The second is an application example of creating shortcuts in custom directory locations

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\": 'starting position oShellLink.Hotkey = "Ctrl+Alt+C": 'Shortcut oShellLink.WindowStyle = 3: 'operation mode Parameter 1 default window activation, parameter 3 maximize activation, parameter 7 minimizes oShellLink.Description = "system default calculator": 'remarks oShellLink.Save:' create a save shortcut

Save the following as XXX.js

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

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 of the above VBS and JS scripts, we can find that there is something in common. At the beginning of this kind of script, you have to declare what the following program is going to run, declare it, and then come to the concrete steps.

See how to call vbs in bat

@ echo offtitle Desktop Shortcut creation tool! > nul 2 > & 1 REG.exe query "HKU\ Smuri 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.lnkset jb51path=%~dp0set jb51exec=%~dp0Ditto.exemshta _ VBScript:Execute ("Set a=CreateObject (" WScript.Shell "): Set b=a.CreateShortcut (" Desktop ") &"\% jb51name% "): b.TargetPath="% jb51exec% ": b.WorkingDirectory="% jb51path" % "": b.Save:close ") so far I believe that you have a deeper understanding of "how to write VBS code to create shortcuts", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report