Solved

VBScript Logon Script and Arrays

Posted on 2013-05-30
3
333 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 46

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

624 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