Announcement

Collapse
No announcement yet.

Local office printer mapping using VBS

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Local office printer mapping using VBS

    Hello


    I have the task of adding a new function in my current login scripts.
    We are a global company and have offices everywhere around the globe.

    I have no issue creating printer mappings with VBS login scripts

    What I would like to do is the following

    If a user from the Australian Office heads over to our US office I want there computer to map the local network printers in that office. And Visa Vera.
    So what ever office a traveling user goes to, the local office printer/s will map via the vbs login script.

    Here is a copy of the current login script that is used for our tech support staff.

    Can some one let know how I can do this
    I have been told it is possible.


    I dont want to base it on OU. I just want the script to map the printers in the office they are currently in as the user/s moves all the time and always need support and help to map the printers in the office they are currently in (Could be any office in the world)

    Any help would be great.


    '************************************************* *********************************
    ' Set Environment Variables
    '************************************************* ********************************
    Set WSHNetwork = WScript.CreateObject("WScript.Network")
    Set WSHShell = WScript.CreateObject("WScript.Shell")

    On Error Resume Next

    Domain = WSHNetwork.UserDomain
    UserName = ""

    While UserName = ""
    UserName = WSHNetwork.UserName
    MyGroups = GetGroups(Domain, UserName)
    Wend

    '************************************************* ********************************
    ' Main Process:
    '************************************************* ********************************
    GrpMeb UserName
    ShowBox

    Wscript.Quit

    '************************************************* ********************************
    'Function: GetGroups
    '************************************************* ********************************
    Function GetGroups(Domain, UserName)
    Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
    GetGroups=""
    For Each objGroup In objUser.Groups
    GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
    Next
    End Function

    '************************************************* *******************************
    'Function: InGroup
    '************************************************* *******************************
    Function InGroup(strGroup)
    InGroup=False
    If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
    InGroup=True
    End If
    End Function

    '************************************************* ********************************
    ' MapDrives Subroutine
    '************************************************* ********************************
    Sub MapDrive(sDrive,sShare)
    On Error Resume Next
    WSHNetwork.RemoveNetworkDrive sDrive
    Err.Clear
    WSHNetwork.MapNetworkDrive sDrive,sShare
    End Sub

    '************************************************* *******************************
    'Map Drives:
    '************************************************* *******************************
    Sub GrpMeb(UNAME)
    MapDrive "Q:", "\\anvil\pcgeneral"
    MapDrive "T:", "\\anvil\software"
    MapDrive "K:", "\\anvil\backoffice"
    MapDrive "W:", "\\anvil\dealing"
    MapDrive "Y:", "\\anvil\asxnotices"
    MapDrive "Z:", "\\anvil\publications"
    MapDrive "O:", "\\anvil\tca"
    MapDrive "J:", "\\tongs.itga.com.au\dealtech"
    MapDrive "U:", "\\carlmore.itga.com.au\quant"
    MapDrive "X:", "\\carlmore.itga.com.au\research"
    WSHNetwork.AddWindowsPrinterConnection "\\asa-dc02-mel\ApeosPort-II C3300 Black & White"
    WSHNetwork.AddWindowsPrinterConnection "\\asa-dc02-mel\Thomson Wing"
    WSHNetwork.AddWindowsPrinterConnection "\\asa-dc02-mel\melbourne colour"
    WSHNetwork.AddWindowsPrinterConnection "\\asa-dc02-mel\Melbourne General"
    On Error Resume Next
    WSHNetwork.RemoveNetworkDrive "P:"
    Err.Clear
    strCmd = "net.exe use P: /home >null"
    WshShell.Run strCmd, 0
    strCmd = "net.exe time asa-dc02-mel /set /yes >null"
    WshShell.Run strCmd, 0
    End Sub
    '
    '************************************************* *******************************
    'Display Dialog:
    '************************************************* *******************************
    Sub ShowBox
    strMsgtxt = "You are mounted to the following drive letters and mapped to printers:" & vbNewLine
    strMsgtxt = strMsgtxt & "Q: = \\anvil\pcgeneral" & vbNewLine
    strMsgtxt = strMsgtxt & "T: = \\anvil\software" & vbNewLine
    strMsgtxt = strMsgtxt & "K: = \\anvil\backoffice" & vbNewLine
    strMsgtxt = strMsgtxt & "W: = \\anvil\dealing" & vbNewLine
    strMsgtxt = strMsgtxt & "Y: = \\anvil\asxnotices" & vbNewLine
    strMsgtxt = strMsgtxt & "Z: = \\anvil\publications" & vbNewLine
    strMsgtxt = strMsgtxt & "O: = \\anvil\tca" & vbNewLine
    strMsgtxt = strMsgtxt & "J: = \\tongs.itga.com.au\dealtech" & vbNewLine
    strMsgtxt = strMsgtxt & "U: = \\carlmore.itga.com.au\quant" & vbNewLine
    strMsgtxt = strMsgtxt & "X: = \\carlmore.itga.com.au\research" & vbNewLine
    strMsgtxt = strMsgtxt & "You are mapped to the following printers:" & vbNewLine
    strMsgtxt = strMsgtxt & "\\asa-dc02-mel\ApeosPort-II C3300 Black & White" & vbNewLine
    strMsgtxt = strMsgtxt & "\\asa-dc02-mel\Thomson Wing" & vbNewLine
    strMsgtxt = strMsgtxt & "\\asa-dc02-mel\melbourne colour" & vbNewLine
    strMsgtxt = strMsgtxt & "\\asa-dc02-mel\Melbourne General" & vbNewLine
    strMsgtxt = strMsgtxt & "P: = Home Drive" & vbNewLine
    msgbox = WshShell.Popup(strMsgtxt, 2, "Logon Script", 0)
    End Sub
    Last edited by mgiannelis; 16th May 2008, 04:33.

  • #2
    Re: Local office printer mapping using VBS

    look here

    http://forums.petri.com/showthread.php?t=7759
    Any advice is given in good faith and without warranty.
    Please give reputation points where appropriate.

    Comment

    Working...
    X