Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with creating shortcut using VBS  (Read 1173 times)

0 Members and 1 Guest are viewing this topic.

associates

    Topic Starter


    Intermediate
  • I love YaBB 1G - SP1!
    Help with creating shortcut using VBS
    « on: February 06, 2006, 11:40:10 PM »
    Hi,

    I've tried to manage to create a shortcut after mapping the network drive using VBscript. This is my first trial. I was wondering if anyone might be able to help me fix this. Mapping the network drive is working. But when i tried to incorporate the shortcut script into the mapping network drive, that's when it's not working.

    Here is my code.
    Option Explicit
    Dim objNetwork
    Dim strUser, strPassword, strProfile
    Dim strDriveLetter, strRemotePath
    Dim WshShell      ' Object variable
    Dim strTargetPath
    Dim strWorkingDir

    ' Values of variables set for Drive H
    strDriveLetter = "H:"
    strRemotePath = "\\192.168.2.11\netlogon"
    strUser = "myuser"
    strPassword = "mypasswd"
    strProfile = "false"

    ' This section creates a network object. (objNetwork)
    ' Then apply MapNetworkDrive method. Result H: drive
    ' Note, this script features 5 arguments on lines 21/22.
    Set objNetwork = WScript.CreateObject("WScript.Network")

    ' Section which maps two drives, H: and J:
    objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, _
    strProfile, strUser, strPassword

    ' Create new WshShell object, whose CreateShortcut method we need.
    Set WshShell = WScript.CreateObject("WScript.Shell")

    Dim MyShortcut
    Dim MyDesktop
    Dim DesktopPath
    Dim TargetPath

    strTargetPath = "H:\\192.168.2.11\netlogon"
    strWorkingDir = "My Computer"

    DesktopPath = WSHShell.SpecialFolders("Desktop")
    Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\test.lnk")
    MyShortcut.TargetPath = WSHShell.ExpandEnvironmentStrings(strTargetPath)
    MyShortcut.WorkingDirectory = WSHShell.ExpandEnvironmentStrings(strWorkingDir)
    MyShortcut.Save

    YOur help is greatly appreciated. Thank you in advance