Solved

VBScript Logon Script and Arrays

Posted on 2013-05-30
3
328 Views
Last Modified: 2013-06-04
I have a VB Logon script that uses arrays extensively. It works well, no complaints, but I would like to streamline it somewhat. I was thinking that if I could streamline even part of the array dictionary entries/comparison, and put it in a function, it could save many pages of code. Here is where you come in;

I will post here a part of my script that uses the dictionary. Bear in mind I destroy the dictionary and rebuild it in my script over and over.  Here is a code snippet;

'Operations Group
cName = Array("M5621","M5630","M5640","M5650"_
,"M4526","M5663","M5143","M5124","M5660"_
,"M5437","M4417")

For Each strName In cName
   oNamesDic.Add strName, "" 
Next

If oNamesDic.Exists(strComputer) Then
    MapPrinter Pserver, "\My_copier_printer"
      MapPrinter Pserver, "\my_color_printer"
      MapPrinter Pserver, "\My_Backup_Printer"
    oNet.SetDefaultPrinter Pserver & "\My_copier_Printer"
End If
ClearArray()

I fill the array with computer names from a group of computers, then compare it to the current computer name. If there is a match, I deliver the printer set, if not, I destroy the array (in Cleararray()) and I proceed to fill a new dictionary with more names to compare.

I literally have 5 pages of script that do exactly this, except the number and names of the machines change and of course, the printer delivery. You can see a small function routine could radically change the size of the script Anything you can come up with would be a blessing to me. I appreciate all you could do to steer me in the right direction. Perhaps a better idea than what I am doing? I do have to check 1200 computers and over 200 groups (not AD groups). Each group is checked in this manner.
0
Comment
Question by:Akish1960
3 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 250 total points
ID: 39210549
Rather than destroy/create the dictionary object, use the dictionary .REMOVEALL method.

I would get as much of the hard coded names out of your script and into a file/database.  Your script would read the data from the external file/database and do the necessary processing.  If the data changes, you only need to change the external file/database, leaving the script untouched.
0
 
LVL 32

Assisted Solution

by:Robberbaron (robr)
Robberbaron (robr) earned 250 total points
ID: 39212239
may not suit your org, but I think would it be better to arrange the lists by computer, followed by the groups they are in  (rather than groups with computers.)

this is because the login script only applies to a computer, so once you find it in the list (a file) then you already know what groups to apply and then the mapping of printers is by group.


eg prtgrouplist.txt
M5621=Floor2,Admin3
M5630=Admin3,Floor4

'script to process printer assignments

''''''''''''''''''''''''''''''''''
' Constants for opening files
''''''''''''''''''''''''''''''''''
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8

'--- set up files & log ---------
const ScrFldr="\\MYDOMAIN\NETLOGON\scripts\"       'std source location available before logon complete
const grouplist = "prtgrouplist.txt"
	'eg prtgrouplist.txt
	'M5621=Floor2,Admin3
	'M5630=Admin3,Floor4
	
	Set fso = CreateObject("Scripting.FileSystemObject")  
	Set oNet = CreateObject("WScript.Network")
	
	' get computer list
dim strComputer
	
	if not fso.FileExists(ScrFldr & grouplist) then 
		'TODO write to log file.  must NOT be interactive
		Wscript.quit
	end if
	Set tsgrps = flf.OpenTextFile(ScrFldr & grouplist, OpenFileForReading)

	do while not tsgrps.eof
		sLine = tsGrps.ReadLine
		arry = Split(sLine,"=")
		compid = arry(0)
		if compid = strComputer then
			'get the groups associated with computer
			prtgrouparray = Split(arry(1),",")
			for each prtgroup in prtgrouparray
				AssignPrinters(prtgroup)
			next
		end if
	
	loop
	
	'done
	Wscript.quit
	
	Sub AssignPrinters( prtgroupid)
	
		select case prtgroupid
			case "Floor2"
				 MapPrinter Pserver, "\My_copier_printer"
			case "Admin3"
				 MapPrinter Pserver, "\the_invoice_printer"				
				 MapPrinter Pserver, "\admin_private_printer"
			case else
			
		end select
	
	
	
	end sub
	

Open in new window

0
 

Author Closing Comment

by:Akish1960
ID: 39220193
Thought of putting those computer name in a file, or multiple files. Still might do that, but the script is done, takes 37k and is ove3r 1060 lines. From pages 4 to 17, it is filled with printer definitions as specified above. Maybe ill do a little looking around and figure out how to put these computer names in a database / header and assign the printers based upon what header the computer belongs to. I have no idea how to do that, but will be a goal. Thank you for your input. They have helped me think outside the box.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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