Solved

Network Login script advice

Posted on 2008-10-15
10
189 Views
Last Modified: 2010-04-21
Hello,

Id like to create a network login script but would like some help on what the best method is. Is using VBS or using a batch file the best/most reliable method?

Many users already have manually mapped network drives and printers, so i need a script that can remove that particular mapped drive if it already exsists, so if the user currently has Letter O mapped to fileserver\users\bob and i need it changed to O fileserver2\everyone for example the script will do this.

If possible an example would be really helpful to map drives and printers, different users need different mapped drives and printers.

We are using Small business server 2003
0
Comment
Question by:kevin1983
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 5

Accepted Solution

by:
mredfelix earned 150 total points
ID: 22719303
Hi it depends on all your level of coding. Vb will give you a nice graphicall interface like a splash screen while the commandline is simpler and less complicated to implement but you can do all you need to from a bat.

here is a good website for you to look at vb login script

http://www.computerperformance.co.uk/Logon/
0
 
LVL 3

Assisted Solution

by:Angelized
Angelized earned 150 total points
ID: 22719334
I would go also to VBS and ADSI, you will be able to dynamically add and remove Mapping for users.
by using also function like the one attach, you will be able to map and unmap drives.


Function MapDrive(strDrive, strPath, boolPersistent, strUser, strPassword)
   Set objNetwork = CreateObject("WScript.Network")
   If IsDriveMapped(strDrive) Then objNetwork.RemoveNetworkDrive strDrive
   On Error Resume Next
   If StrUser = "" Then 
      objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent
   Else   
      objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent, strUser, strPassword
   End If
   MapDrive = Err.Number
   Err.Clear
   
End Function
 
Function IsDriveMapped(strDrive)
    IsDriveMapped = False
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")
    For Each objItem In colItems
        If InStr(UCase(strDrive), objItem.Name) > 0 Then IsDriveMapped = True
    Next
End Function
 
Function UnMapDrive(strDrive)
   On Error Resume Next
   Set objNetwork = CreateObject("WScript.Network")
   If IsDriveMapped(strDrive) Then objNetwork.RemoveNetworkDrive strDrive
   If Err.Number = 0 Then
     UnMapDrive = True
   Else
     Err.Clear
     objNetwork.RemoveNetworkDrive strDrive, True
     If Err.Number = 0 Then
        UnMapDrive = True
      Else
          UnMapDrive = False
      End If
   End If
End Function

Open in new window

0
 

Author Comment

by:kevin1983
ID: 22719449
mredfelix: that site seems helpful

Angelized: would you be able to add a few comments so that i can understand the code better?, i can see the general idea of what this is doing, do you advise running one big script similar to this for all users? as i can see you have the line If StrUser = "" Then do you do a line for each user such as If StrUser = "bob" Then ..... If StrUser = "jane" Then?

Persume i need to add some code such as strDrive = "D:" strPath = "\\Fileserver\users"?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:kevin1983
ID: 22719520
Angelized: Somthing similar to below?
'VARIABLES
dim struser
 
strDrive = "O:"
strPath = "\\Fileserver\Users"
strPassword = "password"
 
 
Function MapDrive(strDrive, strPath, boolPersistent, strUser, strPassword)
   Set objNetwork = CreateObject("WScript.Network")
   If IsDriveMapped(strDrive) Then objNetwork.RemoveNetworkDrive strDrive
   On Error Resume Next
   If StrUser = "" Then 
      objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent
   Else   
      objNetwork.MapNetworkDrive strDrive, strPath, boolPersistent, strUser, strPassword
   End If
   MapDrive = Err.Number
   Err.Clear
   
End Function
 
Function IsDriveMapped(strDrive)
    IsDriveMapped = False
    On Error Resume Next
 
'guess below lines are excuted on local computer, can you explain whats the below lines do?
 
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")
    For Each objItem In colItems
        If InStr(UCase(strDrive), objItem.Name) > 0 Then IsDriveMapped = True
    Next
End Function
 
Function UnMapDrive(strDrive)
   On Error Resume Next
   Set objNetwork = CreateObject("WScript.Network")
   If IsDriveMapped(strDrive) Then objNetwork.RemoveNetworkDrive strDrive
   If Err.Number = 0 Then
     UnMapDrive = True
   Else
     Err.Clear
     objNetwork.RemoveNetworkDrive strDrive, True
     If Err.Number = 0 Then
        UnMapDrive = True
      Else
          UnMapDrive = False
      End If
   End If
End Function

Open in new window

0
 
LVL 3

Expert Comment

by:Angelized
ID: 22719530
Correct !
you can use the following syntax
MapDrive "L:","\\YOURSERVER\YOURSHARE",False,"", ""


0
 
LVL 5

Expert Comment

by:mredfelix
ID: 22719565
try just mapping one drive first..start basic and build from there rather than test everything at once......You can place this in the \\server\netlogon and run it from there on your machine.
Option Explicit
Dim objNetwork 
Dim strDriveLetter, strRemotePath
strDriveLetter = "J:" 
strRemotePath = "\\Servername\sharename" 
 
' Purpose of script to create a network object. (objNetwork)
' Then to apply the MapNetworkDrive method.  Result J: drive
Set objNetwork = CreateObject("WScript.Network") 
 
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath 
WScript.Quit

Open in new window

0
 

Author Comment

by:kevin1983
ID: 22719678
mredfelix: i created that script and it works ok

Angelized: not sure where you mean use this, not sure about some of the code, a few comments would help, do you mean
If StrUser = "Bob" Then
      objNetwork.MapNetworkDrive MapDrive "L:","\\YOURSERVER\YOURSHARE",False,"", "", boolPersistent
   Else  
?
Im guessting this code whenrun on the local computer finds the user thats loged into the network from Active directory and mappes a drive if that particular user is logged in?
0
 
LVL 3

Expert Comment

by:Angelized
ID: 22724766
no need of
If StrUser = "Bob" Then
    MapDrive "L:","\\YOURSERVER\YOURSHARE",False,"", "",
end if
0
 
LVL 5

Expert Comment

by:mredfelix
ID: 22731207
well you want to test it removes the drive so add

objNetwork.RemoveNetworkDrive strDriveLetter

and printers etc use the site i gave you and build it up. the only way your learn is by making mistakes.
0
 

Author Closing Comment

by:kevin1983
ID: 31506240
Ok thanks both for your help, i felt i had to split the points between you as both gave some good comments.

good point mredfelix
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Six Sigma Control Plans
Progress

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question