|
|
|||||||
I've been messing with modifying the syntax on the script from Howard below, but can't seem to get it right - I keep getting "The network path not found" errors. Any assistance is greatly appreciated. What I have in my AD environment is the following: Printers (over 100 with similar format Q-???): Q-ACCT Q-MIS Q-Research Print Server: (only one PS in environment now - so not reflected in group names in AD) MRH-01 AD Group Names containing computer accounts: Q-ACCT Printer Q-MIS Printer Howard's script: ---------------------------- You will need to create a group for each printer you want to map. For example, if your printer is named " laserjet1" on the server named " server1" then create a group called " prt_server1~laserjet1" . Place the computers that should map this printer into the group. code:----------------$usr = GetObject(" WinNT://" + @domain + " /" + @wksta + " $$" ) |
||||||||
|
|
|||||||
code:compares a four-character string on the left side to a fice-character string on the right side.left($GrpName, 4) = " prt_" |
||||||||
|
|
|||||||
Thanks, sealeopard. I have that info. I am just having trouble modifying the syntax to fit my environment for printer names and group names. I was hoping for a little help in modifying that bit. |
||||||||
|
|
|||||||
A four-character string can never equal a five-charactcer string, thus your IF statement will alwasy evaluate to FALSE! I also think that the other spaces in the first line of code are incorrect, too. |
||||||||
|
|
|||||||
When you use Howard's script you have to obay to the naming convention he has set for the groupnames. Using Howard's script, a printergroup must start with the letters: PRT_ You have only one printserver now, BUT if you don't include the servername in the groupname now, You could get into serious trouble, when you add another printserver to the domain, so a good advice is to use Howard's script as is. To make the script work, asuming the name of the printserver is: MRH-01, you should rename the group: Q-ACCT Printer To: PRT_MRH-01~Q-ACCT And rename the group: Q-MIS Printer To: PRT_MRH-01~Q-MIS Also, You have a lot of spaces in your strings, that should not be there, ie. " /" is not the same as "/" AND, the one Sealeopard pointed out: " prt_" is not the same as "prt_" (" prt_" is five long) After renaming the groups, you should use this (Cleaned up for spaces) script: code:-Erik |
||||||||
|
|
|||||||
Thanks, everyone for your replies. Alas, I do not want to change my naming scheme to be similar to PRT_MRH-01~Q-ACCT. I don't like the way it appears in AD. I prefer the group names of Q-Acct Printer as my group name, but can add the print server name to the beginning. I want to strip off the last 8 characters of the group name, get the printer name, and add it to the printserver. I did notice the extra spaces and had already cleaned them up. I just wanted to modify the script to work with my naming scheme. So current: Printers (over 100 with similar format Q-???): Q-ACCT Q-MIS Q-Research Print Server MRH-01 To account for Print Server change, AD Group Names containing computer accounts (Print Server at beginning): MRH-01_Q-ACCT Printer MRH-01_Q-MIS Printer I'll try to modify, but know it is wrong. Trying to get from the right side of the name is tougher than getting from the beginning as the length changes. Maybe I will have to call the groups Printer MRH-01_Q-MIS instead. code:$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$") [ 08. October 2003, 23:02: Message edited by: tjcarst ] |
||||||||
|
|
|||||||
Use SPLIT to plit up your names as you like or upgrade to KiXtart v4.22RC1 which now supports negative numbers in LEFT and RIGHT. |
||||||||
|
|
|||||||
Thanks for the info, sealeopard. I will wait for final 4.22 - I don't like running anything that is RC on my network. There are just too many variables to worry about. Win9x, NT4, 2000, XP, Terminal Server, Citrix Metaframe, RAS, VPN, etc. I'll work on this some more, it isn't currently running yet and I have no error, so need to turn the error reporting to screen. Printer Name: Q-MIS Print Server Name: MRH-01 Computer Group Name: Printer_MRH-01_Q-MIS (I wish I could leave a space between Printer and MRH-01_Q-MIS, but thought maybe that is why my script was failing.) code:$WS = GetObject("WinNT://" + @domain + "/" + @wksta + "$$")if @error |
||||||||
|
|
|||||||
I eventually want to get it to the point that it does not run on a server and Win95 (setdefaltprinter and addprinter do not run). I also want it to check the current state of the printer and map if not map, and set default if already mapped. Do nothing if mapped and default. So, using the previous posted script that I still am working on: code:;********** Prevent script from running on servers and Win95 ********* [ 09. October 2003, 05:07: Message edited by: tjcarst ] |
||||||||
|
|
|||||||
See also the OSID() - Identifies operating system, service pack level, and OS kernel UDF for OS and role differentiation code:$os=osid() |
||||||||
|
|
|||||||
Thanks, Jens. I discovered that just after posting. I'll give it a try. |
||||||||
|
|
|||||||
I have the script adding printers, but it isn't using the PriMapState correctly. It adds three printers if they don't exist, but adds one all of the time, not trying to add the other two. I would like to use @primarygroup to use to set default printer, but am not sure how to modify this. I am at the point where I think an INI file may have been simpler. I already have capture INI files to a network drive so that I could determine which groups to put the computers into. Any ideas on using @primarygroup with PriMapState.udf to set default printer? |
||||||||
|
|
|||||||
wonder... code:in english:If not instr(@producttype,'Workstation') and not -if not workstation quit -if not professional quit -if not 95 quit thus, this will only run on: windows 95 professional workstation or did I miss something? [ 10. October 2003, 00:04: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
No, you didn't miss anything. I've since changed it as sealeopard suggested to use OSID.UDF. But, I found a mistake in my code that was causing the one printer to repeatedly add. Now the script is adding the printers correctly based on computer group membership. However, many computers have more than one printer, and I am having trouble setting the default one. The script uses computer group membership, and @primarygroup uses user group membership. If I could use the computer group membership and read the primary group of the computer to set the printer, I'd have things working. I am beginning to think I should have done this using an .ini file. I have the files for all pc's already, I collected the currently installed printers and the default printer for each workstation+username combo. I could probably, after weeks of messing with the script, read the ini file and write the new printers to the pc's if they did not already exist. Until just recently, I've never messed with Kix, and have no programming background beyond basic batch files, ini files, registry hacks, and a little html code. Nothing along the logic of programming. So, I am struggling and often do things that make no sense to you guys, rightly so. I find it fascinating and continue to mess with it at home during non-work hours so I don't catch hell, but can't help but try to get this to work. I'm persistent and stubborn, so eventually, I'll get it. You guys have been wonderful with your patience and assistance. I apologize for asking what must be obvious to the experienced Kix programmer. Currently I have the following script that adds the printers, but haven't figured out how to set default based on computer primary group membership: Printer: Q-MIS Server: MRH-01 Group: Printer_MRH-01_Q-MIS code:edited to correct codecall @ScriptDir+'\PriMapState.udf' [ 10. October 2003, 03:26: Message edited by: tjcarst ] |
||||||||
|
|
|||||||
well, you have 2 ways. either create a computer-printer-map-groups or start using that ini-file |
||||||||
|
|
|||||||
I'd better start on the ini file. Here's what I have pilfered from others here at this site (Thanks!). Currently I am just reading the printers and creating the ini file. Before posting, I uncommented the part that writes the printers, mainly to let you know I had some code already, but wasn't brave enought to start using. I didn't want you to spend time trying to help me out with code you've probably already posted here. If you have any suggestions on the script, they are valued. Thanks. Current Printersetup.ini file [Printers] 1=\\mrh1\q-mis2 2=\\mrh-01\q-mis2-color 3=\\mrh-01\q-mis2 Default=\\mrh-01\q-mis2 Current Script that writes Printersetup.ini code:;********** Prevent logon script on server ********* [ 10. October 2003, 03:41: Message edited by: tjcarst ] |
||||||||
|
|
|||||||
See the UDF Forum under UnmapPrinters() - Removes mapped printers not listed in an .INI file for an example .INI file for printer mappings. |
||||||||
|
|
|||||||
Thanks, sealeopard. This ini file has more info than what I need. Currently, when a user logs in, a subdirectory is created (if it does not exist) in the format of @wsksta+@userid and then writes the current and default printers. I have over 1200 users and most have logged on and created these files. Over 100 printers. I have only 550 pcs, so I may consolidate the folders by eliminating the usernames and having all users use just the folder name of the computer. There are some users that don't want to use the same printers, which is why I set it up for each user and workstation. Some users/pc's only have one printer, others have over a dozen. Very messy. Creating a more complex ini may make sense had I not already created the simple ones. Maybe I am misunderstanding your suggestion? Is it not okay to use the script and existing ini format? Or am I asking for trouble down the road? Thanks for your patience. I know I am testing it. |
||||||||
|
|
|||||||
The disadvantage of your .INI file structure is that you are wasting the section name on something unnecessary. By utilizing the section name as the first differentiator, you need to read less information in the long run. you will first need to figure out the mapping logic, whether ti's based on the printer, group memebrship, username, and so on. Please outline the way you decide printer mappings in detail, and I might be able to provide you with an optimized .INI file. |
||||||||
|
|
|||||||
Thanks, sealeopard. I want to map the printers based on group membership of the COMPUTER, but cannot figure out how to set the default printer based on the computer due to the RID/SID number and not name that is generated by @primarygroup. What will work, is generating an ini file for the computer when a user logs on and recording the current and default printers. If the printers are not on the pc, install them based on the ini file that exists. It would be even grander if I could add printers in this manner, but currently, if I delete a printer from my pc and logon, it just updates the ini file with the shorter list of printers. It only creates the printers if I delete all of them. It would be nice to also create a log file that generates a time stamp with the current printers and the username that created the timestamp. I need to exclude terminal server users and servers from running this script, I have this part figured out. tjcarst |
||||||||
|
|
|||||||
This kix script generates a log file, but I do not like that it generates the name of the printer as installed on the pc and not the actual \\server\share name. I could probably change this using the ini file. </font><blockquote><font size="1" face="Verdana, Helvetica, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">break on ;********** Prevent logon script on server ********* call @ScriptDir+'\osid.udf' $os=osid() if $os[2]<>'Workstation' exit 0 endif ;********** Beginning of printer info gathering script ********* $PrtLog="\\ps-01\Prtlog$" $PrtLog=$PrtLog+"\@wksta"+"_"+"@userid" ;$PrtLog=$PrtLog+"\@wksta" if 0=exist($PrtLog) MD $PrtLog endif $PrtLog=$Prtlog+"\default.log" call "@scriptdir\getdefaultprinter.udf" $rc=Get_Default_printer() $rc=WriteLog2($PrtLog,Get_Default_Printer(),1) ;if (RedirectOutput("$PrtLog",1) = 0) ;endif ;-------------------------------------------------------------------------------;FUNCTION WriteLog2() ; ;AUTHOR Howard A. Bullock (hbullock@tycoelectronics.com) ; ;ACTION Generic logging facility for scripts. Appends log entry to a file with an ; optional TimeStamp. ; ;SYNTAX WriteLog2($File, $text, [0|1]) ; ;PARAMETERS $File (Required) - String value ; $text (Required) - String value ; $TimeStamp (Optional) Default(0) no TimeStamp (1 or 0) ; ; ;REMARKS This function writes (appends) an optionally time stamped log entry to the file ; defined in function. This function searches for the first unused file handle, ; open the file, and write the entry. The file handle is then closed. When the ; function is unable to perform its it write the error is displayed in a message box. ; ;RETURNS Nothing ; ;DEPENDENCIES None ; ;EXAMPLES WriteLog2("junk.txt","This is a test") ; WriteLog2("junk.txt","This is a test",0) ; WriteLog2("junk.txt","This is a test",1) ; Function WriteLog2($File, $Text, optional $TimeStamp) dim $RC, $File, $text, $FH, $TimeStamp $FH=1 $RC=Open ($FH, $File, 5) while $RC = -3 $FH=$FH +1 $RC=Open ($FH, $File, 5) Loop Select Case $RC=0 if ($TimeStamp=1) $TimeStamp = @Date + " " + @Time + " - " else $TimeStamp = "" endif $RC=Writeline ($FH, $TimeStamp + $Text + @CRLF) $RC=Close ($FH) Case $RC=-2 $text = "WriteLog2: Invalid file handle ($FH) specified when trying to Open $File." $RC=MessageBox ($text,"Script Error",48) Case $RC=-1 $text = "WriteLog2: Invalid file name ($File) specified for log file." $RC=MessageBox ($text,"Script Error",48) Case $RC=>0 $text = "System Error($RC) while attempting to open log file ($File)." $RC=MessageBox ($text,"Script Error",48) Endselect EndFunction[/code]</blockquote><font size="2" face="Verdana, Helvetica, sans-serif">sample contents of default.log ------------------------- 2003/09/24 10:05:43 - Q-MIS2 IP,winspool,Ne01: 2003/09/24 10:11:09 - NONE 2003/09/24 10:13:02 - Fax,winspool,Ne00: -------------------------- |
||||||||
|
|
|||||||
I have the part figured out that generates the log and records time, userid and printer. |
||||||||
|
|
|||||||
I would also like to record if there is a local printer in the ini file. Sometimes we have local deskjets on lpt1, but the primary printer is a network laser. Other times it is th deskjet that is the default. I'd like to record both and set correct printer. I'd prefer that the ini file is used for all printer add/deletes. If we wanted to delete a printer, do it in the ini file, not on the pc. Here's the current printsetup.kix that generates my existing ini file. code:Results of printsetup.kix;********** Prevent logon script on server ********* [Printers] 1=\\mrh-01\q-mis1 2=\\mrh-01\q-mis2 Default=\\mrh-01\q-mis2 [ 12. October 2003, 21:01: Message edited by: tjcarst ] |
||||||||
|
|
|||||||
sealeopard - I have a post going here where Howard is providing assistance on this issue. http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=14&t=001201#000022 I just posted this idea - what do you think? I'll test my script and post for you in a bit: Okay, this may be extra work creating groups, but it may be the easiest way to set the primary printer when there are multiple printers installed. Create a group specifically for a default printer group. Like DefPrinter_MRH-01_Q-MIS2 and put pcs in this group to get default/only printer of Q-MIS2. Create another group Printer_MRH-01_Q-MIS2 for users that have this additional printer. Use the SetDefaultPrinter in the script to set default printer if group name starts with DefPrinter. tjcarst |
||||||||
|
|
|||||||
Okay here's the script. It seems to do what I need. I have to create a group for the default printer and a group for secondary printers, but it works, even if a little cumbersome. tjcarst code:;http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=1;t=007920 |