1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Mapping Drives & Printer

Discussion in 'Networking' started by alanf77, Jul 17, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. alanf77

    alanf77 Thread Starter

    Joined:
    Jul 17, 2006
    Messages:
    1
    Hi guys

    I am looking for some help with mapping network drives, I would like to map network drives for specific departments i.e Account, HR etc.

    The second part of the problem I have over 50 printers spread over a number of building, each floor has it own IP range & subnet. So I am looking to assign a printer depending on where they logon.

    I have no experience with script writing, so I am looking into software that would allow me to perform these functions.

    Another Administrator has recommend that I try a product called Desktop Authority from ScriptLogic www.scriptlogic.com has anyone else tried this software

    Many thanks
    Alan
     
  2. doyle.jack

    doyle.jack

    Joined:
    Feb 24, 2005
    Messages:
    31
    I have used their product extensively. You will be pleased with it. However, keep in mind that it is a commercial product that you will have to buy licenses for.

    You can do exactly what you're talking about.. you can have it map printers and/or drives based on the IP address... or even better, based on the OU that the computer and/or the user are in... group memberships.. whatever.

    They do offer a free trial for any of their products, though and their support personnel are top-notch.

    I highly recommend Desktop Authority.
     
  3. wisdum

    wisdum

    Joined:
    Dec 1, 2005
    Messages:
    131
    I say dont BUY software you dont NEED. If you truelly can not find a way to do it with scripts, then yes, buy the software. I recently had a similar request and found that VBScript is very simple, straightforward, and well documented throughout the internet.

    I have included a script, that I WILL NOT take credit for writing, that does exactly what you want. I am sure if you spent a bit of time you could find a way to (parden the pun) map it to your network. This script will allow you to map printers, and set the default (VERY important, default printer is a user setting, not computer setting!) based on user groups.

    Here you go: (make sure to copy it into a text file and save it with a .vbs extenstion)

    Dim WshNetwork, WshShell
    Dim oDrives, fUser, fOS, fDomain, fUserName, oGroupDict
    Dim arrGroupList, x
    Dim ScriptLogName
    ScriptLogName = "_LoginScript.log"

    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set oDrives = WshNetwork.EnumNetworkDrives
    Set fso = WScript.CreateObject("Scripting.FileSystemObject") 'this allows for the log file
    fTMP = WshShell.ExpandEnvironmentStrings("%TEMP%")
    fComputername = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
    Set inputFile = fso_OpenTextFile(fTMP & "\" & ScriptLogName, 2, True) '"
    inputFile.WriteLine(Now() & ": ###### Start Login Script ######")

    fUser = WshNetwork.UserName
    fDomain = WshNetwork.UserDomain

    'Add Printers with AddPrinter:
    'AddPrinter "\\Server\Printername"
    '
    'Set a default printer with SetPrinterDefault (printer has to exist, or this will not work)
    'SetPrinterDefault "\\Server\Printername"




    '####### Subs 'n Functions Below #######
    '######### DO NOT CHANGE #########

    sub AddPrinter(printerUNC)
    on error resume next
    if (fComputername = "TERMINALSERVER") then
    inputFile.WriteLine(Now() & ": Success: Printer connection skipped because of server " & fComputername)
    else
    WshNetwork.AddWindowsPrinterConnection printerUNC
    If Err.Number = 0 Then
    inputFile.WriteLine(Now() & ": Success: Connect to printer: " & printerUNC)
    else
    inputFile.WriteLine(Now() & ": Failed: Connect to printer: " & printerUNC)
    end if
    end if
    on error goto 0
    end sub

    sub RemovePrinter(printerUNC)
    Set oPrinters = WshNetwork.EnumPrinterConnections
    For i = 0 to oPrinters.Count - 1 Step 2
    if uCase(oPrinters.Item(i+1)) = uCase(printerUNC) then
    on error resume next
    WshNetwork.RemovePrinterConnection printerUNC, true, true
    If Err.Number = 0 Then
    inputFile.WriteLine(Now() & ": Success: Remove printer: " & printerUNC)
    else
    inputFile.WriteLine(Now() & ": Failed: Remove printer: " & printerUNC)
    end if
    on error goto 0
    exit sub
    end if
    Next
    inputFile.WriteLine(Now() & ": Success: Remove printer: " & printerUNC & " (Printer did not exist)" )
    end sub

    sub SetPrinterDefault(printerUNC)
    on error resume next
    if (fComputername = "TERMINALSERVER") then
    inputFile.WriteLine(Now() & ": Success: Printer default skipped because of server " & fComputername)
    else
    WshNetwork.SetDefaultPrinter PrinterUNC
    If Err.Number = 0 Then
    inputFile.WriteLine(Now() & ": Success: Set as Default: " & printerUNC)
    else
    inputFile.WriteLine(Now() & ": Failed: Set as Default: " & printerUNC)
    end if
    end if
    on error goto 0
    end sub

    Function IsMember(sGroup)
    Dim sAdsPath, oUser, oGroup

    If IsEmpty(oGroupDict) Then
    Set oGroupDict = CreateObject("Scripting.Dictionary")
    oGroupDict.CompareMode = vbTextCompare

    sAdsPath = WshNetwork.UserDomain & "/" & WshNetwork.UserName
    Set oUser = GetObject("WinNT://" & sAdsPath & ",user")

    For Each oGroup In oUser.Groups
    oGroupDict.Add oGroup.Name, "-"
    Next
    Set oUser = Nothing
    End If
    IsMember = CBool(oGroupDict.Exists(sGroup))
    if (IsMember) then
    inputFile.WriteLine(Now() & ": Success: User is member of " & sGroup)
    end if

    End Function

    Sub PutEnv(strName, strValue)
    Dim sh, env
    Set sh = CreateObject("WScript.Shell")
    Set env = sh.Environment("USER")
    env(strName) = strValue
    inputFile.WriteLine(Now() & ": Success: Set user variable """ & strName & """ to: """ & strValue & """")
    sh = empty
    env = empty
    End Sub

    Sub DriveMapper(Drive, Share)
    For i = 0 to oDrives.Count -1 Step 2
    if LCase(Drive) = LCase(oDrives.Item(i)) then
    if not LCase(Share) = LCase(oDrives.Item(i+1)) then
    WshNetwork.RemoveNetworkDrive Drive, true, true
    Else
    inputFile.WriteLine(Now() & ": Success: Connect """ & Drive & """ to share """ & Share & """ (previously connected)")
    Exit Sub
    End if
    End if
    Next
    on error resume next
    WshNetwork.MapNetworkDrive Drive, Share
    If Err.Number = 0 Then
    inputFile.WriteLine(Now() & ": Success: Connect """ & Drive & """ to share """ & Share & """")
    else
    inputFile.WriteLine(Now() & ": Failed: Connect """ & Drive & """ to share """ & Share & """")
    end if
    on error goto 0
    End Sub
    sub WriteLog(strEntry)
    inputFile.WriteLine(Now() & ": Log: " & strEntry)
    End Sub



    Good Luck!

    wis
     
  4. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Login Script should suffice.
     
  5. StumpedTechy

    StumpedTechy

    Joined:
    Jul 7, 2004
    Messages:
    7,234
    Also if you want to add the printer based on where they are subnet wise why not have the login script do a check on your machines IP and then assign the printer vrs that subnet it finds it on. I am thinking that modification should work just fine and the fact the login script will always perform this command -

    'Set a default printer with SetPrinterDefault (printer has to exist, or this will not work)
    'SetPrinterDefault "\\Server\Printername"

    Also remember you may want to set this \\Server\Printername as a variable.

    Also you don't have to listen to me but I would recommend learning to script write as it is a vaulable tool and you may want to learn. Theres ALOT that can be done. In all I am just okay when it comes to scripting (I tend to glom on others codes and frankenstein my own functionality) but to tell you some of what I have accomplished with scripting -

    Created a script that parses out all user information from AD for emails and usernames for us to send out email address lists for the employees.
    Created a scipt that was able to deploy to over 200 PC's both a slient software install AND links.
    Created a script that disables our VPN clients on our PCs from loading when in the office because the clients VPN is so dumb it loads all the time even when on our network and isn't needed.
    Created a script that adds a username into administrators group on the PC, starts up remote desktop with the machine name specified for me to remote control in to the PC and then removes the user from the admin group once I log off Remote desktop.
     
  6. wisdum

    wisdum

    Joined:
    Dec 1, 2005
    Messages:
    131
    Stumped,

    That last script:

    Created a script that adds a username into administrators group on the PC, starts up remote desktop with the machine name specified for me to remote control in to the PC and then removes the user from the admin group once I log off Remote desktop.

    That sounds impressive! How did you do that? Do you have that script around still?

    wis
     
  7. StumpedTechy

    StumpedTechy

    Joined:
    Jul 7, 2004
    Messages:
    7,234
    Sure do here it is -

    Code:
    '***************************************************
    'Script Created 9/13/2005 by Eric Theisen
    'This Script when ran will prompt you for 2
    'variables, Computer Name and Domain User. This
    'script will add the input user as Administrator on the
    'machine, open up Remote Desktop Connection to the Machinename
    'specified, and then lastly remove the admin rights.
    'If the user already had admin rights on the machine it will NOT
    'remove them.
    'script.
    'Last Edited : 10/17/2005 by Eric Theisen
    '***************************************************
    strComputer = InputBox("Type in the Computer Name","Computer Name Variable")
    IF strComputer = "" THEN
      WScript.Echo "No Computer Name was given or you clicked Cancel"
      WScript.Quit
    END IF
    strUID = InputBox("Enter Domain User Name", "Domain User Name Variable")
    IF strUID = "" THEN
      WScript.Echo "No Domain User Name was given or you clicked Cancel"
      WScript.Quit
    END IF
    strCmdLine = "mstsc.exe /v:" & strComputer & " /f"
    Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
    Set objUser = GetObject("WinNT://Domain/" & strUID & "")
    On Error Resume Next
    objGroup.Add(objUser.ADsPath)
    If Err.Number <> 0 Then 
    Set WshShell = CreateObject("Wscript.Shell")
    WshShell.Run strCmdLine, , True
    MsgBox "Check to see why this user is an Adminuistator on this machine.
    They will not be removed from the Administrators group by this script.
    This must be done manually"
    Else
    Set WshShell = CreateObject("Wscript.Shell")
    WshShell.Run strCmdLine, , True
    objGroup.Remove(objUser.ADsPath)
    End If

    With this script the only thing you should have to change is the line where - Set objUser = GetObject("WinNT://Domain/" & strUID & "") - Change the Domain to your working Domain name. Also remove the 2 enters on the MsgBox statement (and you can edit that at will as well) this was done to keep the information intact and not cut off.

    As you can see its basic and straight forward but it does the trick. It tries to add a user to the admins group if the user is an admin the script continues but then at the end tells you to see why the user is an admin. Then in both cases it simply runs a shell calling on mstsc.exe /v:" & strComputer & " /f with mstsc being the Remote Desktop Connection exe and the variables afterwards adding the machine name and the /f just forcing the full screen. At the very end uf the user was not an admin to begin with it removes the user from the Admins group.

    Here is how we use it - User calls in with a problem that is profile specific - need to add admin rights to troubleshoot problem - Have user log out and stay at Control Alt del screen - Run script and RDC to machine and log in as the user - Reboot the PC when done.

    When all is said and done the user does not have admin rights, and you have troubleshot the individual user profile problem.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Mapping Drives Printer
  1. KKLC
    Replies:
    1
    Views:
    195
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/483853

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice