Solved

VBScript Logon Script and Arrays

Posted on 2013-05-30
3
325 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

16 Experts available now in Live!

Get 1:1 Help Now