Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Logon Script

Status
Not open for further replies.

kylecarpenter

Technical User
Jan 23, 2011
3
US
I created a logon script, I have added everything except one mapdrive function. I want the computer to map the username of the user and put that in place of what the last folder is called. the folder is \\Kay-Seemusicser\(username)

Thanks

Code:
'--------------------------------------------------------------------
'Description	VBS Login Script for Kay-See Music
'
'Design			Script can be set up to map network drives
'               and printers using the IsMember("Group Name")
'               function to determine group membership.  Script
'               will also map drives and printers using the
'               MapDrive() and MapPrinter() functions alone.
'               A summary of network connections is displayed
'               using the DisplayResources() function.
'               8/19/04     Created
'				8/23/04		Added Primary Group Membership check to map "W" drive
'				8/30/04		Added Operating System Check
'							Added prompt/install for SMS Client
'				3/15/05		Added check to see if connect via RAS
'				4/4/05		Added browser pop-up notification of script actions
'				3/13/08		Removed SMS client install, disable RAS checks
'--------------------------------------------------------------------
'declare global variables here										'
'--------------------------------------------------------------------

Option Explicit
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002

Dim oShell, oNet, oFSO, oWshNetwork, oGroupDict, oCheckOS, oOS, strOS
Dim sTitle, NErr, MSIE, sWidth, sHeight, strHomeDrive, strHomeDir
Dim objFile, oFile
'--------------------------------------------------------------------
'Objects go here													'
'--------------------------------------------------------------------

Set oShell = CreateObject("Wscript.Shell")
Set oNet   = CreateObject("Wscript.Network")
Set oFSO   = CreateObject("Scripting.FileSystemObject")
Set MSIE = CreateObject("InternetExplorer.Application")

'--------------------------------------------------------------------
'Setup IE for Logon Script display                                  '
'-------------------------------------------------------------------'

NErr = 0
sTitle = "Processing Logon Script, please wait..."

SetupMSIE  'Call to the function listed later in script

MSIE.Document.Write "<HTML><TITLE>" & sTitle & "</TITLE><BODY bgcolor=#ffffff><FONT FACE=ARIAL>" 
MSIE.Document.Write "<B>DO NOT CLOSE THIS WINDOW!</B><BR>"
MSIE.Document.Write "<B>It will close automatically upon completion of script processing.</B><BR><BR>"
If Hour(Now) < 12 Then
	MSIE.Document.Write "<B>Good Morning, " & oNet.UserName & "</B><BR><BR>" 
	ElseIf Hour(Now) < 18 Then
	MSIE.Document.Write "<B>Good Afternoon, " & oNet.UserName & "</B><BR><BR>" 
	Else
	MSIE.Document.Write "<B>Good Evening, " & oNet.UserName & "</B><BR><BR>" 
End If 
	
	MSIE.Document.Write "<HR>"

If oNet.UserName = LCase("kayseemusic.telos") Then
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
End if
'--------------------------------------------------------------------
'all mapping and stuff is done from here							'
'--------------------------------------------------------------------

MSIE.Document.Write "<BR>Mapping network drives, please wait....."
If IsMember("kaysee NCC") Or IsMember("133 CF NCC ADMINISTRATORS") Then
	MapDrive "q:", "\\Kay-Seemusicser", "\users"
    	MapDrive "v:", "\\Kay-Seemusicser", "\bncc$"
	MapDrive "u:", "\\Kay-Seemusicser", "\csa"
	MapDrive "p:", "\\Kay-Seemusicser", "\p_drive"
	MapDrive "l:", "\\Kay-Seemusicser", "\CD_Serv"
	MapDrive "m:", "\\Kay-Seemusicser", "\mail"
'	MapDrive "z:", "\\Kay-Seemusicser", "\dmo"
ElseIf IsMember("kaysee TESTERS") Then
        MapDrive "t:", "\\Kay-Seemusicser", "\E-EXAM$"
Else
	MapDrive "S:", "\\Kay-Seemusicser", "\Shared"
	MapDrive "P:", "\\Kay-Seemusicser", "\Public"
	MapDrive "I:", "\\Kay-Seemusicser", "\Intranet"
	MapDrive "Z:", "\\Kay-Seemusicser", "\scripts"
	
End If
If IsMember("kaysee SENIOR STAFF") Then
	MapDrive "v:", "\\Kay-Seemusicser", "\units$"
	End If
If IsMember("kaysee GMIS") Then
	MapDrive "s:", "\\Kay-Seemusicser", "\gmis"
	End If
If IsMember("kaysee PUBLIC AFFAIRS") Then
	MapDrive "T:", "\\Kay-Seemusicser", "\PA_Data"
	End If
If PrimaryGroup=("kaysee COMMUNICATIONS") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\comm"
	ElseIf PrimaryGroup=("kaysee WEATHERFLIGHT") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\208wf"
ElseIf PrimaryGroup=("kaysee 210EIS") Then
	oNet.RemoveNetworkDrive "u:", True, True
	MapDrive "u:", "\\Kay-Seemusicser", "\data"
	MapDrive "w:", "\\Kay-Seemusicser", "\210EIS"
	MapDrive "y:", "\\Kay-Seemusicser", "\csa"
ElseIf PrimaryGroup=("kaysee MEDS") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\aeromeds"
ElseIf PrimaryGroup=("kaysee CIVILENGR") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\ce"
ElseIf PrimaryGroup=("kaysee FINANCE") Then
	MapDrive "z:", "\\Kay-Seemusicser", "\dmo"
    MapDrive "w:", "\\Kay-Seemusicser", "\finance"
ElseIf PrimaryGroup=("kaysee FSS") Or PrimaryGroup=("kaysee PERSONNEL") or PrimaryGroup=("kaysee SERVICES")Then
	MapDrive "w:", "\\Kay-Seemusicser", "\fss"
ElseIf PrimaryGroup=("kaysee fuels") Then
	MapDrive "f:", "\\Kay-Seemusicser", "\fuels"
	MapDrive "w:", "\\Kay-Seemusicser", "\supply"
Elseif PrimaryGroup=("kaysee maint") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\maint"
ElseIf PrimaryGroup=("kaysee MEDICAL") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\medical"
ElseIf PrimaryGroup=("kaysee OPERATIONS") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\ops"
	MapDrive "v:", "\\Kay-Seemusicser", "\pfps_maps"
ElseIf PrimaryGroup=("kaysee SUPPORT GROUP") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\msg"
ElseIf PrimaryGroup=("kaysee SECURITY") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\sp"
ElseIf PrimaryGroup=("kaysee SUPPLY") or PrimaryGroup=("kaysee tech") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\supply"
Elseif PrimaryGroup=("kaysee hq") Then
	MapDrive "w:", "\\Kay-Seemusicser", "\inc"
Else
End If

MSIE.Document.Write "<BR><BR>Network drives have been mapped"

'--------------------------------------------------------------------
'Function calls														'
'Used to perform various other actions required by the script		'
'or to retrieve information need for the script to process correctly'
'--------------------------------------------------------------------

CheckOS() 'Place functions that you don't want to apply to servers, after this function call.

If lcase(oNet.UserName) = "flight.planning" Then
	oFile = "\\133aw-nm-01\flightplaninfo$\" & oNet.ComputerName & ".txt"
		If oFSO.FileExists(oFile) Then
			Set objFile = oFSO.OpenTextFile(oFile, ForAppending, True)
			objFile.WriteLine(Now() & vbcrlf)
			objFile.Close
		Else
			Set objFile = oFSO.CreateTextFile(oFile, False)
			objFile.WriteLine(Now() & vbcrlf)
			objFile.Close
		End If
	Else
End If
'--------------------------------------------------------------------
'This part finishes writing the script display	 					'
'and displays if there were any errors during processing			'
'--------------------------------------------------------------------

If NErr = 0 Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
Else
	MSIE.Document.Write "<BR><BR>There were errors while running the script."
	MSIE.Document.Write "<BR>Closing in 10 seconds..."
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 10000
	MSIE.Quit
End If

'this is the end of the function calls

'--------------------------------------------------------------------
'Checks to see if user is using dial-up connection					'
'Commented out until ready for production							'
'--------------------------------------------------------------------
'Function RunResults(cmdline)
	
'	Dim sTemp, sTempFile, fFile
	
	'Const OpenAsDefault = -2
	'Const FailIfNotExist = 0
	'Const ForReading = 1

		'sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")

		'sTempFile = sTemp & "\runresult.tmp"

		'oShell.Run "%comspec% /c " & cmdline & ">" & sTempFile, 0, True

	'Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsDefault)
		'RunResults = fFile.ReadAll
'End Function

'--------------------------------------------------------------------
'find out what groups the user belongs too							'
'--------------------------------------------------------------------

Function IsMember(sGroup)
    Dim sAdsPath, oUser, oGroup

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

        sAdsPath  = oNet.UserDomain & "/" & oNet.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(UCase(sGroup)))

End Function

'-----------------------------------------------------------------------------'
' Connect to the WinNT: provider and ask it for the user's group memberships. '
' For each group, get the RID and compare it against the users PrimaryGroupID.'
'-----------------------------------------------------------------------------'

Function PrimaryGroup
   Dim objUser
   Dim Group, aGroup, PrimaryGroupRID
   Set objUser = GetObject("WinNT://" & oNet.UserDomain & "/" & oNet.UserName & ",user")
   PrimaryGroupRID = objUser.Get("PrimaryGroupID")
   For Each Group in objUser.Groups
      aGroup = Group.Name
      If Rid(aGroup) = PrimaryGroupRID Then
         PrimaryGroup = UCase (aGroup)
         Exit Function
      End If
  Next
   Set objUser = Nothing
End Function
'------------------------------------------------------'
' Returns the RID, in decimal, of the specified group. '
'------------------------------------------------------'
Function Rid(aGroup)
   Dim objGroup, Sid
   Dim sTmp, x, b
   Set objGroup = GetObject("WinNT://" & oNet.UserDomain & "/" & aGroup & ",group")
   Sid = objGroup.Get("objectSID")
   sTmp = ""
   For x = UBound(Sid) to UBound(Sid)-3 Step -1  ' Process last 4 bytes (the RID)
      b = AscB(MidB(SID, x + 1))                 ' Get a byte
      sTmp = sTmp & Hex(b \ 16) & Hex(b And 15)  ' Convert to Hex
   Next
   Rid = Clng("&H" & sTmp)                       ' Convert hex RID to long decimal
   Set objGroup = Nothing
End Function

'--------------------------------------------------------------------
'map the drives														'
'--------------------------------------------------------------------

Function MapDrive(Drive, FileServer, Share)

	If oFSO.DriveExists(Drive) = True Then
		oNet.RemoveNetworkDrive Drive, True, True
	Else
	End If
	Err.Clear
	If oFSO.DriveExists(FileServer & Share) = True Then
		MSIE.Document.Write "<BR>Mapping " & Drive & " To " & FileServer & Share
        oNet.MapNetworkDrive Drive, FileServer & Share
    Else
        MSIE.Document.Write "<B><BR><FONT COLOR=#FF6666>ERROR! Mapping network drive " & Drive & " to " & FileServer & Share & "</B></FONT>"
        NErr = 1
    End If

End Function

'-----------------------------------------------------------------------------
'Check to see what O/S the computer system is running and installs SMS Client'
'-----------------------------------------------------------------------------

Function CheckOS()

Dim Choice

Set oCheckOS = GetObject("winmgmts:{impersonationLevel=impersonate}").Execquery("Select Caption From win32_operatingsystem")
For Each oOS In oCheckOS
strOS = UCase (oOS.Caption)
Next

If strOS=("MICROSOFT(R) WINDOWS(R) SERVER 2003, STANDARD EDITION") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
ElseIf strOS=("MICROSOFT(R) WINDOWS(R) SERVER 2003, WEB EDITION") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
ElseIf strOS=("MICROSOFT(R) WINDOWS(R) SERVER 2003, ENTERPRISE EDITION") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
Elseif strOS=("MICROSOFT® WINDOWS SERVER® 2008 STANDARD") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
Elseif strOS=("MICROSOFT® WINDOWS SERVER® 2008 DATACENTER") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
Elseif strOS=("MICROSOFT® WINDOWS SERVER® 2008 ENTERPRISE") Then
	MSIE.Document.Write "</Body></HTML>"
	WScript.Sleep 5000
	MSIE.Quit
	WScript.Quit
Else
End If 
End Function

'---------------------------------------------------------------------
'Setup Internet Explorer for displaying information					 '
'---------------------------------------------------------------------
Function SetupMSIE
	MSIE.Navigate "About:Blank"
	MSIE.ToolBar = False
	MSIE.StatusBar = False
	MSIE.Resizable = False
	MSIE.Fullscreen = False
	MSIE.Toolbar = False
	MSIE.Menubar = False
	MSIE.Statusbar = False

	Do
	Loop While MSIE.Busy

	SWidth = MSIE.Document.ParentWindow.Screen.AvailWidth
	SHeight = MSIE.Document.ParentWindow.Screen.AvailHeight
	MSIE.Width = SWidth * .5
	MSIE.Height = SHeight * .85
	MSIE.Left = (SWidth - MSIE.Width)/2
	MSIE.Top = (SHeight - MSIE.Height)/2

	MSIE.Visible = True
End Function
 
your MapDrive function immediately removes the drive letter that you are trying to connect to. i would beg you to reconsider this code. i say this because 99/100 all you are doing is removing a mapped drive to a valid location (i guess i can only say that if your drive mappings are persistent)
anyway, your users will have faster logon times if you dont disconnect an already perfectly well connected drive mapping. 20 seconds * num of users * 365 = quite a few man hours of wasted company time

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
This Code Does work with every other drive map. I need to know how to have it map the username as the last folder in the map. For example "H:\" maps to "\\Kay-Seemusicser\Users\Docs\Kyle.Carpenter" because every user has their own folder. I have never tried to map username for the map drive so any advice would help. I do want to keep everything in this script if possable.
 
Never Mind, I figured it out
Code:
 MapDrive "H:", "\\Kay-seemusicser", "\" & oNet.UserName
thanks anyway appreciate the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top