Page 2 of 2 <12
Topic Options
#187029 - 2008-04-17 06:08 PM Re: adding printers [Re: Tony]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
To verify a printer before attempting to install it use the following UDF
http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=84400
_________________________
Today is the tomorrow you worried about yesterday.

Top
#187036 - 2008-04-17 07:14 PM Re: adding printers [Re: Tony]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: Tony

....
So for the line of code, I am verifying if the printer is added successfully? Is this better practice than just puting only?

AddPrinterConnection("\\lnx1\hp4000")

Thanks for so much needed info.
Tt


That depends on what you need/want to know. Just adding the printer without knowing if it was actually added could give you some calls from users that do not have the printer(s) they should have. I would change it to the example below.

 Code:
If AddPrinterConnection("\\lnx1\hp4000") <> 0
	;Do something so an admin knows there are problems
	;with connecting printer x for user y.
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187040 - 2008-04-17 07:39 PM Re: adding printers [Re: Mart]
Tony Offline
Getting the hang of it

Registered: 2001-11-04
Posts: 55
Loc: LA

I am trying to place a printer.bat on the GPO --> User Configuration --> Windows Settings--> Scripts-->Logon (domain\sysvol\domain\policies\9113xxxx\User\Scripts\Logon)

The printer.bat calls login.kix on the netlogon share. How do I specify in the printer.bat to call login.kix

right now i have as follow:


@echo off

\\vmad1\netlogon\kix32 login.kix

exit

Doesn't seem to work.

Any idea?

~tt

Top
#187042 - 2008-04-17 08:02 PM Re: adding printers [Re: Tony]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Just put everything (the bat file, kix or wkix and the kix script) in the netlogon/sysvol folder. If put the logon script in the GPO and reference to the domain and not to a specific DC all should be fine.

You can also put \\domain\somefolders\kix32.exe in the script field and \\domain\somefolders\script.kix in the parameters field. There is no real need for a bat file.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187043 - 2008-04-17 08:14 PM Re: adding printers [Re: Mart]
VTC Offline
Fresh Scripter

Registered: 2008-04-17
Posts: 26
Loc: Alexandria, Virginia


 Code:
If AddPrinterConnection("\\lnx1\hp4000") <> 0
	;Do something so an admin knows there are problems
	;with connecting printer x for user y.
EndIf

[/quote]

Whats the correct return if AddPrintConnection sees that the HP is their. I need the correct syntax to be able to test it.

If AddPrinterConnect('\\server\printer') = 0

Top
#187044 - 2008-04-17 08:18 PM Re: adding printers [Re: VTC]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Like said that only checks if the printer is added properly. To see if the printer exists before trying to add it you could use the UDF Gargoyle linked to.

BTW: please do not use someone else’s topic to ask questions that have nothing to do with the question of the original poster. It would be better to start a new topic.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187045 - 2008-04-17 08:44 PM Re: adding printers [Re: Mart]
VTC Offline
Fresh Scripter

Registered: 2008-04-17
Posts: 26
Loc: Alexandria, Virginia
How does this not have anything to do with the original topic.

Its posted as "Adding Printers" My referenced questions is related to the same idea.

Top
#187048 - 2008-04-17 09:21 PM Re: adding printers [Re: VTC]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The same idea yes but not the same question.
The original question was how to add printers to users when not using user groups. Your question is about how to see if a printer already exists before trying to install it. To prevent all kinds of question going side by side and everybody loosing track of what reply belongs to what question you should start a new topic in the appropriate section (Basic, Advanced, Lounge etc…)

Board etiquette is clearly stated in the top most post in this section of the board. All is explained there.

Basic Scripting » INFO: Moderator's message to new forum users

Now let’s get back to the original question.

Tony, you got something going already or is it still giving you trouble?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187417 - 2008-05-01 07:48 AM Re: adding printers [Re: Mart]
Tony Offline
Getting the hang of it

Registered: 2001-11-04
Posts: 55
Loc: LA
Mart,

I got it to work in the test environment. So sorry for not responding.

Does real world pratice checks for existing printers before adding? So far, I am not verifying the existence of the printers and it worked.


Can you assist in this code if you can:

If AddPrinterConnection("\\lnx1\hp4000") <> 0
;Do something so an admin knows there are problems
;with connecting printer x for user y.
EndIf

Are they usually a write to a log file?

TIA,
-tt

Top
#187421 - 2008-05-01 11:12 AM Re: adding printers [Re: Tony]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Checking to see if the pri9nter exists before installing it is a matter of taste. I never do it. At work we have a logon script that deletes all network printers and installs network printers based upon group membership. See below on how to delete all network printers.

There are several UDF's in the UDF section that let you send an e-mail. Writing to a log file is also an option. Writeline is your friend when writing to a log file. Personally I like to use BlatMailer(). Not listed in the UDF section but there are some examples on the board. Today it is a national holiday here but I'll VPN to work and get a copy of the UDF send to my home e-mail or FTP it.

Standby......

 Code:
Break on

;======== Delete all network printers ========
;Delete all mapped network printers
$key = "HKEY_CURRENT_USER\Printers\Connections"
$printers = ArrayEnumKey($key)
For Each $printer in $printers
	$rc = DelKey($key + "\" + $printer)
Next

;=-=-=-=-=- Do not modify anything below this line =-=-=-=-=-
;=-=-=-=-=- below is a UDF and they comes ready made =-=-=-=-=-

;NAME          ArrayEnumKey
;
;ACTION        Creates an array of names of the subkeys contained in a registry key or subkey
;
;AUTHOR        Jens Meyer (sealeopard@usa.net)
;
;VERSION       1.2 (added error codes)
;              1.1
;
;DATE CREATED  2001/12/05
;
;DATE MODIFIED 2003/05/17
;
;KIXTART       4.12+
;
;SYNTAX        ARRAYENUMKEY($subkey)
;
;PARAMETERS    SUBKEY
;              Required string containing the key or subkey for which the subkeys will be enumerated
;
;RETURNS       Array containing the subkeys
;
;REMARKS       none
;
;DEPENDENCIES  none
;
;EXAMPLE       $retcode=arrayenumkey('HKEY_USERS')
;
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000064
;
Function arrayenumkey($regsubkey)
  Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray

  If NOT KeyExist($regsubkey)
    Exit 87
  EndIf

  $subkeycounter=0
  Do
    $currentsubkey=EnumKey($regsubkey,$subkeycounter)
    If NOT @ERROR
      ReDim preserve $subkeyarray[$subkeycounter]
      $subkeyarray[$subkeycounter]=$currentsubkey
      $subkeycounter=$subkeycounter+1
    EndIf
  Until @ERROR

  $arrayenumkey=$subkeyarray
  Exit 0
EndFunction


Edited by Mart (2008-05-01 11:13 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#187422 - 2008-05-01 11:34 AM Re: adding printers [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Here's an example on how to send mail using blat. You should change the senders address and the recipient. Also the mail server should be changed to fit your situation. This script requires blat, you can download it here: http://www.blat.net/. Depending on where you put the blat executable you should also change the path in the $mailerline variable.

Blat is able to send attachments but I left it out in the example. On the blat website there are some examples on how to use blat with kixtart.

 Code:
Break on

$Sender = "sender@@domain.tld"
$Recipients = "recipient@@domain.tld"
$Subject ='"subject"'
$Body='"Messagebody text"'
$Send = BlatMailer($Recipients,$Sender,$Subject,$Body)


Function BlatMailer($Recipient,$Sender,$Subject,$Body)
	Dim $SMTPServer,$MailerLine
	$SMTPServer='IP address or DNS name of you mailserver' 
	$MailerLine='d:\blat.exe -' + ' -to ' + $Recipient + ' -f ' + $Sender + ' -subject ' + $Subject + ' -body ' + $Body + ' -server ' + $SMTPServer + ' -q '
	Shell $MailerLine
EndFunction


The credits for the BlatMailser UDF should go to Doc iirc. Thanks Doc.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 905 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.065 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org