Question

VBS Script help filterning users by security group and default gatweyway logon script

Asked by: tetran_au

Hi Guys i a absolute noobie when it comes to vb scripting.  It is a complete new language to me. However i have a requirement to create a logon script.   I have basically gotten the beginnings of it down packed where it will map drives according AD security group membership.

What i need help on is the next stage of this. Below is the things i would like this script to also do.

1) display a text box showing progress of logon script
2) have the display box close automatically if logon script runs successfuly
3) have the display box stay open with error message if logon script fails
4) As an extra to checking the security group membership I would like it to also then check the default gateway.  If the user is in teh correct group and the default gateway matches the ip for the site then it will map the drives.  If the default gateway is incorrect then the user will get a message stating you are not currently at your home site so network drives will not be mapped.

I am googling everywhere and looking for templates.  I have managed to get a complete re write of this script working that maps according to default gateway "OR" by security group membership.  The problem is that because i dont know this language well i am stuck with using templates found online and then i have issues with variables etc.

I have not even tried to create the display box yet because that is another hurdle on its own.  Can anyone please advise where i will be able to find some templates that will meet the above requirements or at least some webpages that will go through more and details how to complete this.

Thanks in advance.

P.S. If you are feeling generous please have a stab at it yourself but if not any information will be deeply appreciated.

ON ERROR RESUME NEXT
 
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
 
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
 
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
 
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
 
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "J:", True, True
WSHNetwork.RemoveNetworkDrive "M:", True, True
WSHNetwork.RemoveNetworkDrive "N:", True, True
WSHNetwork.RemoveNetworkDrive "O:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "Q:", True, True
WSHNetwork.RemoveNetworkDrive "S:", True, True
WSHNetwork.RemoveNetworkDrive "T:", True, True
WSHNetwork.RemoveNetworkDrive "U:", True, True
 
'Give the PC time to do the disconnect, wait 200 milliseconds
wscript.sleep 200
 
'Map drives needed by all
WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
 
 
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
    Select Case UCase(GroupObj.Name)
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
    'Note the use of all upper case letters as mentioned above.
    'Note also that the groups must be Global Groups.
 
        Case "Group1"
            WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
 
        Case "Group2"
            WSHNetwork.MapNetworkDrive "h:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "j:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "n:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "o:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "p:", "\\Server\share",True
     
      End Select
Next
 
'Quit the Script
wscript.quit

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-10 at 16:37:44ID24723235
Tags

VB Scripting

,

VBS Scripting

,

Logon Scripts

,

Default gateway

,

security group

Topics

Shell Scripting

,

VB Script

,

Visual Basic Programming

Participating Experts
1
Points
500
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Webpage
    How do I put a Webpage in my form?
  2. Accessing a webpage from VB
    Hi, I want to access a webpage via HTTP and HTTPS from a VB application. Any ideas as to how should I go about it ? Where can I get some sample code ? Thanks a ton ! Parag.
  3. Open mozilla webpage in VB
    Gents I have a problem I am struggling to create a kiosk style webpage within mozzilla I have script that does this but it opens up 2 windows which i have been informed is not possible to close easily. What I thougth would answer my problems is create the same webpage but ...
  4. Deeply rooted spyware - WinFixer
    I have a client who has some deeply rooted spyware. I cannot clear it with Norton, ewido, spybot or ad-aware. My last resort is to rebuild the system. Will L2MFIX do it? Attached are the logs from L2MFIX and HIJACK THIS. THe rebuild is scheduled for tomorrow morning at 1...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: tetran_auPosted on 2009-09-10 at 18:41:46ID: 25306103

hey guys i found this and did a bit extra but i keep getting a bunch of errors

Can you help me identify what i am missing or doing incorrectly

ON ERROR RESUME NEXT
 
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Dim objWMIService, colItems, objItem, objFSO, objLogFile, objNetwork, objDrives, DiskDrive, wshell, objCheckDrives
Dim strCurrentUser, strCorrectUser, strCorrectUserLength, strUserLength, strLogFolderPath, strLogFilePath, strDiskDriveCheck
Dim strDriveLetter, strHDriveFree, strGDriveFree, strPDriveFree, WSHProcess, strLogonServer, strUserDN
Dim strLDriveSuccess, strMDriveSuccess, strSDriveSuccess, strTDriveSuccess, DiskDriveCheck, strDriveLetterCheck, strGroup
Dim objConnection, objCommand, objUser, objRecordSet, cMemberOf, objGroup, objGroupName, objGroupShort
Dim strSupervisor, strComputer, objReg, strKeyPath, strCurrentIP, strAddress
Dim objItem2, colItems2
 
 
 
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:\\127.0.0.1\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set colItems2 = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
Set IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE")
 
strComputer = "."
 
 
 
 
 
'Determining username and computer name.
For Each objItem in colItems
	strCurrentUser = objItem.UserName
	strComputer = WSHNetwork.ComputerName
Next
 
For Each objItem2 in colItems2
	For Each strAddress in objItem2.IPAddress
		strCurrentIP = strAddress
	Next
Next
 
 
'Removing the "Domain\" from the username.
strUserLength = len(strCurrentUser)
strCorrectUserLength = cint(strUserLength - 6)
strCorrectUser = Right(strCurrentUser,strCorrectUserLength)
 
 
'Disconnect any drive mappings as needed.
WSHNetwork.RemoveNetworkDrive "H:", True, True
WSHNetwork.RemoveNetworkDrive "G:", True, True
WSHNetwork.RemoveNetworkDrive "P:", True, True
WSHNetwork.RemoveNetworkDrive "M:", True, True
 
 
'Give the PC time to do the disconnect, wait 200 milliseconds
wscript.sleep 200
 
 'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
 
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
Select Case UCase(GroupObj.Name)
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
    'Note the use of all upper case letters as mentioned above.
    'Note also that the groups must be Global Groups.
 
	Case "Share1"
		For Each IPConfig in IPConfigSet
    			If Not IsNull(IPConfig.DefaultIPGateway) Then 
        			For i=LBound(IPConfig.DefaultIPGateway) To UBound(IPConfig.DefaultIPGateway)
           			 	Select Case IPConfig.DefaultIPGateway(i)
                  			Case "10.254.140.254"
                      			MsgBox "Your Gateway is 172.19.204.254"
                      			WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
                  			Case Else
                        		MsgBox "You are not currently at your home site"
           	 			End Select   
           			Next     
				End If	
				
	Case "Share2"
		For Each IPConfig in IPConfigSet
    			If Not IsNull(IPConfig.DefaultIPGateway) Then 
        			For i=LBound(IPConfig.DefaultIPGateway) To UBound(IPConfig.DefaultIPGateway)
           			 	Select Case IPConfig.DefaultIPGateway(i)
                  			Case "172.19.204.254"
                      			MsgBox "Your Gateway is 172.19.204.254"
                      			WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
 
                  			Case Else
                        		MsgBox "You are not currently at your home site"
           	 			End Select   
           			Next     
				End If	
End Select
Next
 
' This section of script will prevent the balloon window
' that appears when printing to a network shared printer
' after XP Service Pack 2 is installed.
'=====================================
 
Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"
 
  
' This section of script will prevent the balloon window
' that appears when printing to a network shared printer
' after XP Service Pack 2 is installed.
'=====================================
 
Path = "HKCU\Printers\Settings\EnableBalloonNotificationsRemote"
WshShell.RegWrite Path, 0 ,"REG_DWORD"
 
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
 
'Quit the Script
wscript.quit
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:

Select allOpen in new window

 

by: RobSampsonPosted on 2009-09-10 at 19:00:26ID: 25306180

Hi there, this should help with steps 1, 2, and 3.  Step 4, however.....I'm not quite sure what you want to do with the default gateway.....but I have added a display of the IP address and gateway for you to look at.

Regards,

Rob.

' First we get the current screen resolution so we can place
' our progress window in the centre
' See: http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0721.mspx
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery _
	("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")
 
For Each objItem in colItems
	intScreenWidth = objItem.PelsWidth
	intScreenHeight = objItem.PelsHeight
Next
 
' Now create our display window and position it in the centre
intWidth = 800
intHeight = 600
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Toolbar = 0
objIE.StatusBar = 0
objIE.AddressBar = 0
objIE.MenuBar = 0
objIE.Width = intWidth
objIE.Height = intHeight
objIE.Resizable = 0
While objIE.ReadyState <> 4
	WScript.Sleep 100
Wend
objIE.Left = (intScreenWidth / 2) - (intWidth / 2)
objIE.Top = (intScreenHeight / 2) - (intHeight / 2)
objIE.Visible = True
 
' Now run your normal code and you can use
' objIE.document.WriteLn "This is my message"
' anywhere in the code to update progress
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", _
                                       wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
For Each objItem In colItems
   strCaption =  objItem.Caption
   strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
   strIPAddress = Join(objItem.IPAddress, ",")
   If strDefaultIPGateway <> "" And strIPAddress <> "0.0.0.0" Then
       objIE.Document.WriteLn "<BR>Your IP Address: " & strIPAddress & "<BR>Your gateway: " & strDefaultIPGateway & "<BR>"
   End If
Next
 
objIE.Document.WriteLn "<BR><BR>Running logon scripts. Please wait..." & "<BR>"
 
On Error Resume Next
 
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
 
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
 
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
 
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
 
boolErrorEncountered = False
 
objIE.Document.WriteLn "<BR>" & "Removing currently mapped network drives..."
'Disconnect any drive mappings as needed.
If objFSO.DriveExists("H:") = True Then WSHNetwork.RemoveNetworkDrive "H:", True, True
If objFSO.DriveExists("J:") = True Then WSHNetwork.RemoveNetworkDrive "J:", True, True
If objFSO.DriveExists("M:") = True Then WSHNetwork.RemoveNetworkDrive "M:", True, True
If objFSO.DriveExists("N:") = True Then WSHNetwork.RemoveNetworkDrive "N:", True, True
If objFSO.DriveExists("O:") = True Then WSHNetwork.RemoveNetworkDrive "O:", True, True
If objFSO.DriveExists("P:") = True Then WSHNetwork.RemoveNetworkDrive "P:", True, True
If objFSO.DriveExists("Q:") = True Then WSHNetwork.RemoveNetworkDrive "Q:", True, True
If objFSO.DriveExists("S:") = True Then WSHNetwork.RemoveNetworkDrive "S:", True, True
If objFSO.DriveExists("T:") = True Then WSHNetwork.RemoveNetworkDrive "T:", True, True
If objFSO.DriveExists("U:") = True Then WSHNetwork.RemoveNetworkDrive "U:", True, True
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error removing one or more network drives."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If
	
'Give the PC time to do the disconnect, wait 200 milliseconds
WScript.sleep 200
 
'Map drives needed by all
objIE.Document.WriteLn "<BR>" & "Mapping shared drive S:"
WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error mapping to S: Drive."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If 
 
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
objIE.Document.WriteLn "<BR>" & "Mapping group specific drives..."
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
    Select Case UCase(GroupObj.Name)
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
    'Note the use of all upper case letters as mentioned above.
    'Note also that the groups must be Global Groups.
 
        Case "Group1"
            WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
 
        Case "Group2"
            WSHNetwork.MapNetworkDrive "h:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "j:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "n:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "o:", "\\Server\share",True
            WSHNetwork.MapNetworkDrive "p:", "\\Server\share",True
     
      End Select
Next
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error mapping one or more group specific drives."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If 
 
If boolErrorEncountered = False Then
	objIE.Document.WriteLn "<BR><BR>" & "Logon script complete. This window will close in three seconds."
	WScript.Sleep 3000
	objIE.Quit
	Set objIE = Nothing
Else
	objIE.Document.WriteLn "<BR><BR>" & "Errors were encounterd. Please leave this window open and notify your system administrator."
End If
 
wscript.quit

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:

Select allOpen in new window

 

by: tetran_auPosted on 2009-09-10 at 19:20:25ID: 25306251

Thanks for that, i will review this shortly and get back t o you very soon.

In regards to number 4

The reason why i want to also check the gateway on top of the security group is alot of our staff spend alot of time on the road and travelling between sites.  As alot of our satelites have very slow links we dont want these users to be mapping drives across the wan.  

Thats why we want to make sure that the network drives only map if they part of the appropriate security group, and there current default network gateway is that off there home site and not a roaming office.


But thanks for the work and help so far.  I will let you know how it goes.

 

by: RobSampsonPosted on 2009-09-10 at 19:26:37ID: 25306278

OK, that sounds logical. After your testing, please provide an example of a client IP Address that a staff member may have from the WAN, and the gateway.  I think maybe what could do is just check the gateway against a list of valid LAN gateways....or check the client IP against a list of valid subnets....

Regards,

Rob.

 

by: tetran_auPosted on 2009-09-10 at 20:04:14ID: 25306436

Thank you so much for your help so far. It is looking great.

I was tossing up between filtering by ip address or by gateways.  The problem is there are so many different vlans in this network it would be over kill trying to specify all the different ranges.  Thought it would be easier to just use the gateway simply because i have a list infront of me right now with the 32 or so gateway addresses.

Anyways here is a example to have what i am talking about

Each site has a security group similare to SG-SITENAME-ALLUSERS

so Basically we want the following


Site1-Sydney  Security group - SG-Sydney-ALLUSERS    Subnet-10.0.0.1  SydUser1

Site2-Queenslad  Security Group - SG-Queensland-ALLUSERS  Subnet-10.0.1.1

Site3-Melbourne Security Group - SG-melbourne-ALLUSERS Subnet 10.0.2.1

For exampe i want to to be able to look at the username of the user in this case syduser1 and currently it is detecting and mapping the drives because he is a member of sg-sydney-allusers group.
After this i want it to be able to check its gateway and say ok your a member of sg-sydney-allusers now whats ur default gateway.  Ok checked that gateway is known as the one for sydney here is your drives. It will then continue as normal and clsoe itself off. If that mates sence

I also want it to do for example sydney user syduse1 travels to melbourne.  It checks the security group and sees ok your a member of sg-sydney-allusers group.  It will then check the default gateway and notice its ip address is NOT 10.0.0.1 so it will prompt a message like "You are not at your home site so your network drives will not be mapped". This will error out and have the user close the window manually.

Let me know if you need any more information





 





 

by: RobSampsonPosted on 2009-09-10 at 22:42:58ID: 25306915

OK, that makes sense....By your examples, I take it you're Australian....I'm in Melbourne myself....

So what I've done is create a dictionary object called objGateways that you can populate with your gateway sitenames and gateway address.

Then in each Case statement, you specity strSiteName for it to look up objGateways for the matching IP.  It will then check the client gateway against this one.

Regards,

Rob.

' First we get the current screen resolution so we can place
' our progress window in the centre
' See: http://www.microsoft.com/technet/scriptcenter/resources/qanda/jul05/hey0721.mspx
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colItems = objWMIService.ExecQuery _
	("Select PelsWidth,PelsHeight From Win32_DisplayConfiguration")
 
For Each objItem in colItems
	intScreenWidth = objItem.PelsWidth
	intScreenHeight = objItem.PelsHeight
Next
 
' Now create our display window and position it in the centre
intWidth = 800
intHeight = 600
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "about:blank"
objIE.Toolbar = 0
objIE.StatusBar = 0
objIE.AddressBar = 0
objIE.MenuBar = 0
objIE.Width = intWidth
objIE.Height = intHeight
objIE.Resizable = 0
While objIE.ReadyState <> 4
	WScript.Sleep 100
Wend
objIE.Left = (intScreenWidth / 2) - (intWidth / 2)
objIE.Top = (intScreenHeight / 2) - (intHeight / 2)
objIE.Visible = True
 
' Set up a dictionary object for the sites and their gateways
Set objGateways = CreateObject("Scripting.Dictionary")
objGateways.Add LCase("sydney"), "10.0.0.1"
objGateways.Add LCase("queensland"), "10.0.1.1"
objGateways.Add LCase("melbourne"), "10.0.2.1"
 
' Now run your normal code and you can use
' objIE.document.WriteLn "This is my message"
' anywhere in the code to update progress
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
 
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True", "WQL", _
                                       wbemFlagReturnImmediately + wbemFlagForwardOnly)
 
For Each objItem In colItems
   strCaption =  objItem.Caption
   strDefaultIPGateway = Join(objItem.DefaultIPGateway, ",")
   strIPAddress = Join(objItem.IPAddress, ",")
   If strDefaultIPGateway <> "" And strIPAddress <> "0.0.0.0" Then
       objIE.Document.WriteLn "<BR>Your IP Address: " & strIPAddress & "<BR>Your gateway: " & strDefaultIPGateway & "<BR>"
   End If
Next
 
objIE.Document.WriteLn "<BR><BR>Running logon scripts. Please wait..." & "<BR>"
 
On Error Resume Next
 
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
 
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
 
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
 
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
 
boolErrorEncountered = False
 
objIE.Document.WriteLn "<BR>" & "Removing currently mapped network drives..."
'Disconnect any drive mappings as needed.
If objFSO.DriveExists("H:") = True Then WSHNetwork.RemoveNetworkDrive "H:", True, True
If objFSO.DriveExists("J:") = True Then WSHNetwork.RemoveNetworkDrive "J:", True, True
If objFSO.DriveExists("M:") = True Then WSHNetwork.RemoveNetworkDrive "M:", True, True
If objFSO.DriveExists("N:") = True Then WSHNetwork.RemoveNetworkDrive "N:", True, True
If objFSO.DriveExists("O:") = True Then WSHNetwork.RemoveNetworkDrive "O:", True, True
If objFSO.DriveExists("P:") = True Then WSHNetwork.RemoveNetworkDrive "P:", True, True
If objFSO.DriveExists("Q:") = True Then WSHNetwork.RemoveNetworkDrive "Q:", True, True
If objFSO.DriveExists("S:") = True Then WSHNetwork.RemoveNetworkDrive "S:", True, True
If objFSO.DriveExists("T:") = True Then WSHNetwork.RemoveNetworkDrive "T:", True, True
If objFSO.DriveExists("U:") = True Then WSHNetwork.RemoveNetworkDrive "U:", True, True
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error removing one or more network drives."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If
	
'Give the PC time to do the disconnect, wait 200 milliseconds
WScript.sleep 200
 
'Map drives needed by all
objIE.Document.WriteLn "<BR>" & "Mapping shared drive S:"
WSHNetwork.MapNetworkDrive "S:", "\\Server\share",True
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error mapping to S: Drive."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If 
 
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
objIE.Document.WriteLn "<BR>" & "Mapping group specific drives..."
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
    Select Case UCase(GroupObj.Name)
    'Check for group memberships and take needed action
    'In this example below, ADMIN and WORKERB are groups.
    'Note the use of all upper case letters as mentioned above.
    'Note also that the groups must be Global Groups.
 
        Case UCase("SG-Sydney-ALLUSERS")
        	strSiteName = LCase("Sydney")
        	strSiteGateway = objGateways(strSiteName)
        	If strDefaultIPGateway = strSiteGateway Then
            	WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
            Else
            	objIE.Document.WriteLn "<BR>" & "You are not at your home site so your network drives will not be mapped."
            	boolErrorEncountered = True
            End If
 
        Case UCase("SG-Queensland-ALLUSERS")
        	strSiteName = LCase("Queensland")
        	strSiteGateway = objGateways(strSiteName)
        	If strDefaultIPGateway = strSiteGateway Then
	            WSHNetwork.MapNetworkDrive "h:", "\\Server\share",True
	            WSHNetwork.MapNetworkDrive "j:", "\\Server\share",True
	            WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
	            WSHNetwork.MapNetworkDrive "n:", "\\Server\share",True
	            WSHNetwork.MapNetworkDrive "o:", "\\Server\share",True
	            WSHNetwork.MapNetworkDrive "p:", "\\Server\share",True
            Else
            	objIE.Document.WriteLn "<BR>" & "You are not at your home site so your network drives will not be mapped."
            	boolErrorEncountered = True
            End If
            
		Case UCase("SG-Melbourne-ALLUSERS")
        	strSiteName = LCase("Melbourne")
        	strSiteGateway = objGateways(strSiteName)
        	If strDefaultIPGateway = strSiteGateway Then
				WSHNetwork.MapNetworkDrive "m:", "\\Server\share",True
            Else
            	objIE.Document.WriteLn "<BR>" & "You are not at your home site so your network drives will not be mapped."
            	boolErrorEncountered = True
            End If
 
      End Select
Next
If Err.Number <> 0 Then
	boolErrorEncountered = True
	objIE.Document.WriteLn "<BR>" & "There was an error mapping one or more group specific drives."
	objIE.Document.WriteLn "<BR>" & Err.Number & ": " & Err.Description
	Err.Clear
End If 
 
If boolErrorEncountered = False Then
	objIE.Document.WriteLn "<BR><BR>" & "Logon script complete. This window will close in three seconds."
	WScript.Sleep 3000
	objIE.Quit
	Set objIE = Nothing
Else
	objIE.Document.WriteLn "<BR><BR>" & "Errors were encounterd. Please leave this window open and notify your system administrator."
End If
 
wscript.quit

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:

Select allOpen in new window

 

by: tetran_auPosted on 2009-09-13 at 16:28:40ID: 31627377

Thank you very much for your assistance,. This is exactly what i am looking for.

Thanks for all the little notes in the script as well , it really helps me understand how everything fits in.

Your a legend ;)

 

by: RobSampsonPosted on 2009-09-13 at 16:37:35ID: 25322302

No problem. Thanks for the grade.  If you need anything else explained, let me know.  I usually neglect to comment the code.....bad practice I know.....but I usually don't have a lot of time.

Regards,

Rob.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...