Solved

Network Login script advice

Posted on 2008-10-15
10
180 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
  • 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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This is an explanation of a simple data model to help parse a JSON feed
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now