SBS 2003 VB Scripting - Help Needed!

Discussion in 'Scripting' started by un1c0rn, Mar 10, 2009.

  1. un1c0rn

    un1c0rn Guest

    Hello Gurus,

    I am currently working on a login script for a Small Business Server 2003
    which maps drives and creates different default printers depending on which
    security group the users are in. The drive mapping works ok but the default
    printing assignment has errors when running the vb script. I am sure it is
    something simple that I am missing here but I can't seem to get my head
    around it. Any help would be muchly appreciated.

    Thankyou in Advance.

    My scripting is below:

    Option Explicit



    ' Common Commands - For All Users.

    Dim wshell

    Set wshell = CreateObject("WScript.Shell")

    wshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE

    wshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE

    ' wshell.Run "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER

    set wshell = Nothing



    ' Assign Drive Mappings.

    Dim objNetwork, strRemotePath1, strRemotePath2, strRemotePath3

    Dim strDriveLetter1, strDriveLetter2, strDriveLetter3

    strDriveLetter1 = "K:"

    strDriveLetter2 = "L:"

    strDriveLetter3 = "M:"

    strRemotePath1 = "\\SQLSVR\APPS"

    strRemotePath2 = "\\SQLSVR\DATA"

    strRemotePath3 = "\\SQLSVR\MYOBAE"

    Set objNetwork = WScript.CreateObject("WScript.Network")

    objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

    objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2

    objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3



    ' Assign Default Printer - according to security group membership.

    dim objGroup1, objGroup2, objGroup3, strUserDN, objSysInfo

    Set objGroup1 = GetObject("LDAP://cn=BACK OFFICE TOSHIBA,ou=Security
    Groups,ou=MyBusiness,dc=Domain,dc=local")

    Set objSysInfo = CreateObject("ADSystemInfo")

    strUserDN = objSysInfo.userName

    If (objGroup1.IsMember("LDAP://" & strUserDN) = True) Then

    objNetwork.AddWindowsPrinterConnection "\\sbserver\BACKOFFICE PRINTER"

    objNetwork.SetDefaultPrinter "\\sbserver\BACKOFFICE PRINTER"

    Else

    Set objGroup2 = GetObject("LDAP://cn=FRONT OFFICE TOSHIBA,ou=Security
    Groups,ou=MyBusiness,dc=Domain,dc=local")

    If (objGroup2.IsMember("LDAP://" & strUserDN) = True) Then

    objNetwork.AddWindowsPrinterConnection "\\sbserver\FRONT OFFICE TOSHIBA"

    objNetwork.SetDefaultPrinter "\\sbserver\FRONT OFFICE TOSHIBA"

    Else

    Set objGroup3 = GetObject("LDAP://cn=COLOUR PRINTER,ou=Security
    Groups,ou=MyBusiness,dc=Domain,dc=local")

    If (objGroup3.IsMember("LDAP://" & strUserDN) = True) Then

    objNetwork.AddWindowsPrinterConnection "\\sbserver\COLOUR PRINTER"

    objNetwork.SetDefaultPrinter "\\sbserver\COLOUR PRINTER"

    End If

    End If

    End If

    WScript.Quit

    ' End of VBScript.
     
    un1c0rn, Mar 10, 2009
    #1
    1. Advertisements

  2. {code snipped}

    What error? What line? Trying to find unnamed errors is like trying
    to collect smoke in a bottle.

    Tom Lavedas
    ***********
    http://there.is.no.more/tglbatch/
     
    Richard Mueller [MVP], Mar 10, 2009
    #2
    1. Advertisements

  3. un1c0rn

    Al Dunbar Guest

    {code snipped}

    What error? What line? Trying to find unnamed errors is like trying
    to collect smoke in a bottle.

    ============
    But that can be done. I'd say it is more like trying to collect smoke in a
    cloth bag. ;-)

    /Al
     
    Al Dunbar, Mar 10, 2009
    #3
  4. un1c0rn

    un1c0rn Guest

    Ok I have the error message that occurs when I run the vbs script.

    Error Message:
    Line: 52
    Char: 1
    Error: The filename, directory name, or volume label syntax is incorrect.
    Code: 8007007B
    Source: (null)
     
    un1c0rn, Mar 10, 2009
    #4
  5. un1c0rn

    un1c0rn Guest

    Line: 52
    Char: 1
    Error: The filename, directory name, or volume label syntax is incorrect.
    Code: 8007007B
    Source: (null)

    {code snipped}

    What error? What line? Trying to find unnamed errors is like trying
    to collect smoke in a bottle.

    Tom Lavedas
    ***********
    http://there.is.no.more/tglbatch/
     
    un1c0rn, Mar 10, 2009
    #5
  6. un1c0rn

    Pegasus Guest

    You're still leaving it to respondents to count lines. How about giving us
    the actual line that generates the error?
     
    Pegasus, Mar 10, 2009
    #6
  7. un1c0rn

    un1c0rn Guest

    Windows Script Host
    Script: c:\documents and settings\sysop\desktop\test.vbs
    line: 52
    Char: 1
    Error: The filename, directory name, or volume label syntax is incorrect.
    Code: 8007007b
    Source: (null)
     
    un1c0rn, Mar 11, 2009
    #7
  8. un1c0rn

    un1c0rn Guest

    Windows Script Host
    Script: c:\documents and settings\sysop\desktop\test.vbs
    line: 52
    Char: 1
    Error: The filename, directory name, or volume label syntax is incorrect.
    Code: 8007007b
    Source: (null)
     
    un1c0rn, Mar 11, 2009
    #8
  9. un1c0rn

    Al Dunbar Guest

    Sorry, but we are NOT going to count the lines to figure out which one is
    number 52. Use your text editor to find line 52 in the file you ran when
    you got this error, and cut-and-paste that line into a reply here.

    /Al
     
    Al Dunbar, Mar 15, 2009
    #9
  10. un1c0rn

    un1c0rn Guest

    Thanks for your help/interest but I have worked it out. The following is
    the script I ended up with and works perfectly.

    ' -----------------------------------------------------------------'
    ' Company Login Script
    ' Version 1.0 - 12/03/2009
    ' -----------------------------------------------------------------'


    ' -----------------------------------------------------------------'
    ' Common Commands - For All Users.
    ' -----------------------------------------------------------------'

    ON ERROR RESUME NEXT

    Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj,
    Path, wshell


    Set WSHShell = CreateObject("WScript.Shell")
    Set WSHNetwork = CreateObject("WScript.Network")
    'Automatically grab the user's domain name
    DomainString = Wshnetwork.UserDomain
    'Find the Windows Directory
    WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

    UserString = WSHNetwork.UserName
    Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

    strComputer = WSHNetwork.ComputerName


    ' -----------------------------------------------------------------'
    ' Syncronise Time
    ' -----------------------------------------------------------------'
    wshshell.Run "%COMSPEC% /c net time \\SBSERVER /set /y",0,TRUE


    ' -----------------------------------------------------------------'
    ' Trend Client Install (If not present)
    ' -----------------------------------------------------------------'
    wshshell.Exec "%COMSPEC% \\SBSERVER\Clients\Setup\setup.exe /s SBSERVER"


    ' -----------------------------------------------------------------'
    ' Remove Any Existing Mapped Drives and Printers
    ' -----------------------------------------------------------------'
    wshshell.Run "%COMSPEC% /c net use /delete /y *",0,TRUE

    Set clDrives = WshNetwork.EnumNetworkDrives
    For i = 0 to clDrives.Count -1 Step 2
    WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
    Next

    wscript.sleep 300

    Set WSHPrinters = WSHNetwork.EnumPrinterConnections
    For LOOP_COUNTER = 0 To WSHPrinters.Count - 1 Step 2
    If Left(WSHPrinters.Item(LOOP_COUNTER +1),2) = "\\" Then
    WSHNetwork.RemovePrinterConnection WSHPrinters.Item(LOOP_COUNTER
    +1),True,True
    End If
    Next

    wscript.sleep 300


    ' -----------------------------------------------------------------'
    ' Assign Mapped Drives
    ' -----------------------------------------------------------------'

    WSHNetwork.MapNetworkDrive "H:", "\\sbserver\users\" & UserString,True
    WSHNetwork.MapNetworkDrive "K:", "\\SQLSVR\APPS",True
    WSHNetwork.MapNetworkDrive "L:", "\\SQLSVR\DATA",True
    WSHNetwork.MapNetworkDrive "M:", "\\SQLSVR\MYOBAE",True


    ' -----------------------------------------------------------------'
    ' Assign Default Printer - according to group membership.
    ' -----------------------------------------------------------------'

    For Each GroupObj In UserObj.Groups
    Select Case UCase(GroupObj.Name)
    Case "CTPRINT1"
    WSHNetwork.AddWindowsPrinterConnection "\\sbserver\BACK OFFICE"
    WSHNetwork.SetDefaultPrinter "\\sbserver\BACK OFFICE PRINTER"
    Case "CTPRINT2"
    WSHNetwork.AddWindowsPrinterConnection "\\sbserver\RECEPTION"
    WSHNetwork.SetDefaultPrinter "\\sbserver\RECEPTION"
    Case "CTPRINT3"
    WSHNetwork.AddWindowsPrinterConnection "\\sbserver\HPLaserJ"
    WSHNetwork.SetDefaultPrinter "\\sbserver\HPLaserJ"
    End Select
    Next

    set UserObj = Nothing
    set GroupObj = Nothing
    set WSHNetwork = Nothing
    set DomainString = Nothing
    set WSHSHell = Nothing
    Set WSHPrinters = Nothing

    wscript.quit
     
    un1c0rn, Mar 17, 2009
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.