Create Shortcut using Visual Basic Script

Create shortcut on desktop with Visual Basic Script

Visual Basic Script 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.

create-shortcut.vbs

The following VB-Script creates a shortcut on the desktop, here for example to open the Windows Calculator.

Insert VB-Script lines by  Copy Paste into Notepad and save them as create-shortcut.vbs, then douple-click to execute the VB-Script will create the shortcut on desktop.
' VBScript to created shortcut
Const strProgramTitle = "Shortcut to Calculator"
Const strProgram = "%SystemRoot%\System32\calc.exe"
Const strWorkDir = "%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

  Last but not least, enjoy to edit the Const lines in the script to use any other applications.

Now double-clicking the shortcut on the desktop opens the Windows Calculator.

C:\> cscript //Nologo //B create-shortcut.vbs

This VBScript can be started with cscript from the command prompt or from a batch.

Microsoft Visual Basic Scripting Edition

VBScript (“Microsoft Visual Basic Scripting Edition”) is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment.

VBScript uses the Component Object Model to access elements of the environment within which it is running. For example, the FileSystemObject (FSO) is used to create, read, update and delete files. VBScript has been installed by default in every desktop release of Microsoft Windows since Windows 98. In Windows Server since Windows NT 4.0 Option Pack; and optionally with Windows CE (depending on the device it is installed on).

Microsoft VBScript is a general-purpose, lightweight and active scripting language developed by Microsoft that is modeled on Visual Basic. Nowadays, VBScript is the primary scripting language for Quick Test Professional (QTP), which is a test automation tool. This tutorial will teach you how to use VBScript in your day-to-day life of any Web-based or automation project development.

Network drive mapping from PowerShell Script

Mapping Windows Network Drive using PowerShell

PowerShell scripts can be used to mapping 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.

Network drive mapping from PowerShell Script

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.

$LogFile = "netdrive.log"
Get-Date -Format "MM/dd/yyyy HH:mm" | Out-File $LogFile -Force
Write-Host "`nEnter your network credentials to map network drives or cancel mapping" -ForegroundColor Yellow
$Cred = Get-Credential -Message "Please enter your credentials" -UserName "domain\username"
if ($Cred) {
    $sharePath = "\\server\share"
    $mapDrive = "Z"
    Write-Host "`nMapping network share.." -ForegroundColor White
    Add-Content $LogFile -Value "Mapping drive $mapDrive $sharePath"
    New-PSDrive -Name $mapDrive -Root $sharePath -Persist -Scope Global -PSProvider "FileSystem" -Credential $Cred | Out-File $LogFile -Append
} else {
    Add-Content $LogFile -Value "No credentials were given, network mapping canceled."
}

The corresponding Windows network share is defined in line 6 at $sharePath, and the drive is assigned in line 7 at $mapDrive, change the respective placeholder between the quotation marks. If further network shares are to be mapped, in the if loop copy lines 6 – 10 for the next network share using the variables $sharePath1 and $mapDrive1.

Run the script in the PowerShell with change to directory in which you placed the netdrive.ps1 script file.

.\netdrive.ps1

Replace the placeholders domain\username with the appropriate domain and user, if there is no domain, then just leave it blank.

Windows PowerShell Credentials
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:

start /wait "" powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -File netdrive.ps1

After a successful logon, is it possible to check the network mapping, for this the processes are logged in the file netdrive.log.

Conclusion

In this Tutorial you will learn, how to using PowerShell scripts that can be used to mapping 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.