Create shortcuts on desktop with Visual Basic Script
VBScripts can help wherever automated tasks need to be used. Batch files may not always be appropriate, and the use of Group Policy may not always be available, where a Visual Basic Script can do this, for example, to provide shortcuts to applications.
The following VBScript creates a shortcut on the desktop, here for example to open the Windows Calculator.
Insert VBScript lines by Copy Paste into Notepad and save them as create-shortcut.vbs, then douple-click to execute the VBScript will create the shortcut on desktop.
VBScript create-shortcut.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'VBScript tocreated shortcut
ConststrProgramTitle="Shortcut to Calculator"
ConststrProgram="%SystemRoot%\System32\calc.exe"
ConststrWorkDir="%USERPROFILE%"
Dim objShortcut,objShell
Set objShell=WScript.CreateObject("Wscript.Shell")
strLPath=objShell.SpecialFolders("Desktop")
Set objShortcut=objShell.CreateShortcut(strLPath&"\" & strProgramTitle & ".lnk")
objShortcut.TargetPath=strProgram
objShortcut.WorkingDirectory=strWorkDir
objShortcut.Description=strProgramTitle
objShortcut.Save
WScript.Quit
Now double-clicking the shortcut on the desktop opens the Windows Calculator. This VBScript can be started with cscript from the command prompt or from a batch.
Command Prompt
1
2
C:\>cscript//Nologo //B create-shortcut.vbs
Last but not least, enjoy to edit the Const lines in the script to use any other applications.
PowerShell scripts can be used to create network drives to Windows network shares on servers or NAS devices. Where batch processing is not the right choice, or where Group Policy is not possible, a PowerShell script can perform this task, for example, when running login scripts with remote clients via VPN, or clients that are not members of the AD domain.
PS-Script for Network Drive Mapping
This PowerShell Script example netdrive.ps1, creates the Windows network mapping to drive Z: for a specific user, whereby you can log on as a different user than you are authenticated with on the client.
Add-Content$LogFile-Value"No credentials were given, network mapping canceled."
}
The corresponding Windows network share is defined in line 7 at $sharePath, and the drive is assigned in line 8 at $mapDrive, adjusting the respective placeholder between the quotation marks. If further network shares are to be mapped, in the if loop copy lines 7 – 11 for the next network share using the variables $sharePath1 and $mapDrive1.
Windows PowerShell Credentials
Run PowerShell Script from Batch
If a batch is already in place, for example netlogon.bat, then execute netdrive.ps1 out from a batch file as follows:
Mapping Windows Network Drive using Visual Basic Script
VBScript can be used to connect network drives to Windows shares on servers or NAS devices. In situations where batch processing is not the right choice, or group policy is not the application you want, a Visual Basic Script can meet the requirement, for example, to apply login scripts to VPN Remote Clients who are not members of the AD domain.
Microsoft VBScript contains object classes, methods (functions / procedures) and value structures. Our MapNetworkDrive object is used as a method here. The method or verb in turn manipulates values.
Any object can be used, the object objNetwork is defined here, script developers like to stick to patterns and their variables. A prefix of str indicates a string value, while the obj prefix indicates an object. After WScript has created our objNetwork, it can be edited using the MapNetworkDrive method.
VBScript for Network drive Mapping
The following VBScript netdrive.vbs as an example, assign the network mapping to drive Z: for a specific user; the login can be performed as a different user than the one with whom you have authenticated yourself on the client.
VBScript: netdrive.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Option Explicit
Dim objNetwork,strDriveLetter,strRemotePath,strUser,strPassword,strProfile,WshShell
The corresponding variable assigned line 6 – 9 in which the placeholder is defined between quotation marks.
Assign VBScript values to variables
For strDriveLetter choose a desired network drive letter.
For strRemotePath add the UNC path to the network share.
For strUser add the user name. If this is a member of an AD domain, the domain prefix must be given, using like domain\user.
For strPassword add the users password.
Run VBScript WSH from batch
If a batch is already used, for example netlogon.bat, then from the batch file the VBScript netdrive.vbs is executed as follows:
Command Prompt
1
2
start/wait""cscript//Nologo netdrive.vbs
If you do not want to output Visual Basic Console Screen during execution, use option /B to start the application without opening a new window.
Command Prompt
1
2
start/B/wait""cscript//Nologo netdrive.vbs
After successfully logging in, the network drive for the Windows network share is created and then opened in Explorer.
UNBLOG verwendet Cookies, um Dein Online-Erlebnis zu verbessern. Mit "ACCEPT" gibst Du Deine Zustimmung zur Nutzung dieser Website und unseren Datenschutzbestimmungen, oder wähle Cookie settings.
Diese Website verwendet Cookies, um Ihre Erfahrung zu verbessern, während Sie durch die Website navigieren. Von diesen werden die Cookies, die nach Bedarf kategorisiert werden, in Ihrem Browser gespeichert, da sie für das Funktionieren der grundlegenden Funktionen der Website wesentlich sind. Wir verwenden auch Cookies von Drittanbietern, mit denen wir analysieren und verstehen können, wie Sie diese Website nutzen. Diese Cookies werden nur mit Ihrer Zustimmung in Ihrem Browser gespeichert. Sie haben auch die Möglichkeit, diese Cookies zu deaktivieren. Das Deaktivieren einiger dieser Cookies kann sich jedoch auf Ihre Browser-Erfahrung auswirken.
Notwendige Cookies sind unbedingt erforderlich, damit die Website ordnungsgemäß funktioniert. Diese Kategorie enthält nur Cookies, die grundlegende Funktionen und Sicherheitsmerkmale der Website gewährleisten. Diese Cookies speichern keine persönlichen Informationen.
Alle Cookies, die für die Funktion der Website möglicherweise nicht besonders erforderlich sind und speziell zur Erfassung personenbezogener Daten des Benutzers über Analysen, Anzeigen und andere eingebettete Inhalte verwendet werden, werden als nicht erforderliche Cookies bezeichnet. Es ist obligatorisch, die Zustimmung des Benutzers einzuholen, bevor diese Cookies auf Ihrer Website ausgeführt werden.