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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation.. And tips for logonscript!

Status
Not open for further replies.

slint

Technical User
Jul 2, 2006
48
SE
I have compiled a script with parts from two diffrent examples from Mark D. MacLachlan and i have been testing it and it works realy good. The script checks two things.. the first it checks is if dhcp address is active and if it is it run another script and quit, if dhcp is not used it checks for logonserver beening used and then run another script and quit.

Why this then...?? Couldent i only used the last part or the first maybee..?? If i use only dhcp check, what if client using static ip?? then script 2 dont run and the user dont get drivemappings. OK if i only use logonserver... What if server1 on location1 has a lot to do or is down then server2 on location2 will answer and then the wrong script will run. So thats why i use both checks..

So whats my question then

I would appriciate if someone could take a look on the code and tell me if something is going to f*ck things upp on the clients because of some varibel. Maybe there is a way to improve the code??



Code:
'==========================================================================
'
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 5/4/2005
' 
'  
'==========================================================================


Option EXPLICIT


'+------------------------------+
'+------------------------------+
	Dim WSHShell, WSHProcess, DomainLogonServer, oReg, strKeyPath, arrSubKeys, subkey, DHCPAddress, ActiveDHCPIPAddress


	On Error Resume Next

	'+---------------------------------------------------------------------+
	'+---------------------------------------------------------------------+
		Const HKEY_LOCAL_MACHINE = &H80000002
		Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
		".\root\default:StdRegProv")
		
		Set WSHShell = CreateObject("Wscript.Shell")
		strKeyPath = "SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\"
		oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
		
		For Each subkey In arrSubKeys
		
		    DHCPAddress = WSHShell.RegRead("HKLM\" & strKeyPath & subkey & "\DhcpIPAddress")
		    If DHCPAddress <> "0.0.0.0" And Left(DHCPAddress,3) <> "169" Then
		        ActiveDHCPIPAddress = DHCPAddress    
		    End If
		Next

		'+-------------------------------------------------------------------+
		'+-------------------------------------------------------------------+

			Select Case Left(ActiveDHCPIPAddress,7)
				'location1
			    Case "176.16."
					Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
					Set oReg = Nothing
					Set WSHShell = Nothing
					WScript.Quit
					
				'location2
			    Case "176.17."
					Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-2.vbs //NoLogo",0, True)
					Set oReg = Nothing
					Set WSHShell = Nothing
					WScript.Quit
					
				'location3
			    Case "176.18."
					Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-3.vbs //NoLogo",0, True)
					Set oReg = Nothing
					Set WSHShell = Nothing
					WScript.Quit
					
				'location4
			    Case "176.19."
					Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-4.vbs //NoLogo",0, True)
					Set oReg = Nothing
					Set WSHShell = Nothing
					WScript.Quit
					
				'location5
			    Case "176.20."
					Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-5.vbs //NoLogo",0, True)
					Set oReg = Nothing
					Set WSHShell = Nothing
					WScript.Quit
					

			
			End Select

'+------------------------------------------------+
'+------------------------------------------------+
	
	'+------------------------------+
	'+------------------------------+
		Set WSHShell = wscript.createObject("wscript.shell")
		Set WSHProcess = WSHShell.Environment("Process")
	
		'+---------------------------------------------+
		'+---------------------------------------------+
			DomainLogonServer = WSHProcess("LogonServer")
			
			'WScript.Echo "Logon server is: "& DomainLogonServer
	
			'+----------------------------------------------------------------+
			'+----------------------------------------------------------------+
				Select Case DomainLogonServer
					'location1
				    Case "\\DC01"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
					Case "\\DC02"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-1.vbs //NoLogo",0, True)
				    
				    'location2
				    Case "\\DC03"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-2.vbs //NoLogo",0, True)
				    
				    'location3
				    Case "\\DC04"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-3.vbs //NoLogo",0, True)
				    
				    'location4
				    Case "\\DC05"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-4.vbs //NoLogo",0, True)
				    
				    'location5
				    Case "\\DC06"
						Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-5.vbs //NoLogo",0, True)
				

				
				End Select
	
		'+---------------------+
		'+---------------------+
		
			Set WSHShell = Nothing
			Set WSHProcess = Nothing
	
	  
	'+---------------------+
	'+---------------------+
		WScript.Quit
 
hi Slint,

I am glad you found one of my FAQs helpful. I think you would benefit by also looking at faq329-5798.

I don't understand why you have one script calling another and why it is even necessary to have multiple scripts. (logonscript1-5) faq329-5798 should help you to understand how you can have a single script support multiple users & groups and situations.

You also don't provide any details of your environment, so I don't know why you have chosen to use DHCP or LogonServer checking. Without an understanding of your environment there is no way to validate if you have made logical choices or not.

Lastly I note that you are calling login scripts directly from the sysvol share. Why? Why are you not applying the scripts via GPO?

At this stage there are more questions than answers as you have not provided enough information to work with.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
The other script i'm calling is FAQ329-5798 (With mod) and why another script. The main reason is because i'm delegating control over diffrent part of the system so the admin in location1 should only be able to mod location1 script and no other. I'm going to use GPO for loginscript but now when i'm testing i use sysvol share.

Enviroment.
User A works att location1 and usaly loggs on there. He has his homefolder and a share for all coworkers in location1. Sometimes UserA moves to location2 and loggs in and he should not get access to his location1 shares bacause of badwidht limits. So when UserA comes to location2 he is going to get another share and only when he is logging in on location2. If he moves to location3 he is going to get location3 share and only that one.

The thing i'm concerned abote is this part
Code:
                'locationX
                Case "176.XX."
                    Call WSHShell.Run("cscript \\domain\sysvol\domain\scripts\LogonScript-X.vbs //NoLogo",0, True)
                    Set oReg = Nothing
                    Set WSHShell = Nothing
                    WScript.Quit

Is it ok to end the script like this and does it leave something running or something...

PS: Scripting is not my major.. :)
 
I think I would go about this differently. I would make the users members of groups that identify their Primary location. I would then compare the primary location to the current IP address and if they don't match then don't map the users folder.

does it leave something running or something...
No, you are clearing the memory and ending the script (which wil also clear the memory).

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top