none
Scripting Newbie Question RRS feed

  • Question

  • Hi everyone,
    I am a complete VBS scripting newbie, I am trying to get my head around what different parts of a script are actually doing & why. As I am hoping this will help me to understand what I am actually trying to achieve.  I have attached a script and am hoping someone might give a simple summary of what the script is doing in a step by step manner.

    Thx in advance Pete.

    1 ...... Dim oSystemInfo
    2 ...... Dim oShell, oNetwork
    3 ...... Dim sLogonServer, sSiteName
    4 ...... Set oShell = Wscript.CreateObject(“Wscript.Shell”)
    5 ...... sLogonServer = oShell.ExpandEnvironmentStrings(“%LOGONSERVER%”)
    6 ...... Set oSystemInfo = CreateObject(“ADSystemInfo”)
    7 ...... sSiteName = oSystemInfo.SiteName
    8 ...... On Error Resume Next
    9 ...... Set oNetwork = CreateObject("WScript.Network" )
    10 ...... Select Case sSiteName
    11 ......      Case “Brisbane”
    12 ......             oNetwork.RemovePrinterConnection\\BRS01\Laser1
    13 ......       Case “Darwin”
    14 ......             oNetwork.RemovePrinterConnection\\DAC02\LaserJet
    15 ......       Case “Hobart”
    16 ......              oNetwork.RemovePrinterConnection\\HOSrv\HP2
    17 ......       Case “Melbourne”18......oNetwork.RemovePrinterConnection\\MEG4\LaserJet
    19 ......       Case “Sydney”
    20 ......              oNetwork.RemovePrinterConnection\\SY2\HP03
    21 ...... End Select
    22 ......              oNetwork.RemoveNetworkDrive “L:”, True

    Friday, July 11, 2014 9:57 AM

Answers

  • Hi Pete,

    very well, however, please note that unless you have lots of legacy systems to maintain (and will keep having to do so), you'll be better off learning Powershell instead of VBS:

    1-3: Declare variables (needed to work with them later on)
    4: Get a Wscript.Shell object (useful tool)
    5: Save the Environment Variable "LOGONSERVER" into a script variable so it can be used comfortably
    6: Create a systeminfo object (this will later on reveal the site name)
    7: Store the current site name
    8: If an error occurs, continue with the next element (Otherwise the script would terminate on the first error)
    9: Create a network object (which can be used to Remove Printers as shown later)
    10-21: Depending on what Site you are at, remove the associated printer connection
    22: Remove the network drive with the drive letter "L"

    hope that helped, cheers,
    Fred


    There's no place like 127.0.0.1

    Friday, July 11, 2014 11:44 AM