KixLearner
(Fresh Scripter)
2006-09-26 11:42 AM
Printer Check Logon Script

Hi,

I am very new to Kix scripts and just wondered if it was possible to have a script that can run on logon and check what printers are mapped on the PC and then export that information to a text file?

Any help would be greatly appreciated.

Many Thanks,

Ben


Witto
(MM club member)
2006-09-26 11:45 AM
Re: Printer Check Logon Script

There is PrinterList, EnumPrinterConnections and EnumPrinterConnections2 in the UDF library. Would they be of any help?

KixLearner
(Fresh Scripter)
2006-09-26 11:48 AM
Re: Printer Check Logon Script

Sounds promising. As I am new to this site could you point me in the right direction please?

Witto
(MM club member)
2006-09-26 11:51 AM
Re: Printer Check Logon Script

http://www.kixtart.org/ubbthreads/ubbthreads.php?Cat=0
Click "UDF Library"
Click "Search" (on top)
Type in some search words and change options if needed
Click "Submit"


KixLearner
(Fresh Scripter)
2006-09-26 12:11 PM
Re: Printer Check Logon Script

Thanks for that, much appreciated.

Does this one:

http://www.kixtart.org/ubbthreads/showfl...true#Post137527

Export the results to a text file anywhere? Sorry if its a stupid question or obvious answer


LonkeroAdministrator
(KiX Master Guru)
2006-09-26 12:22 PM
Re: Printer Check Logon Script

no, udf's are user defined functions.
they work just as kixtart functions (at least theoretically)...
as example, open() is a function.
it does not export anything to file, it just opens the file.

same goes with that udf.
it returns you the list of printers and if you want to place the data to a file, write couple of lines of script with open(), writeline() and close() to do the actual exporting.


KixLearner
(Fresh Scripter)
2006-09-26 12:37 PM
Re: Printer Check Logon Script

OK thanks for the info. I will post a new topic asking how to create, open, import the variable details and close a text file as I dont want this one to go off topice.

Many thanks for your help


Witto
(MM club member)
2006-09-26 03:22 PM
Re: Printer Check Logon Script

Code:

If NOT @LOGONMODE
Break On
Else
Break Off
EndIf
Dim $RC
$RC = SetOption("Explicit","On")
$RC = SetOption("NoVarsInStrings","On")
$RC = SetOption("NoMacrosInStrings","On")
$RC = SetOption("WrapAtEOL","On")

Dim $aPrinters, $Printer, $Handle1, $File1
$aPrinters = EnumPrinterConnections2()
$Handle1 = FreeFileHandle()
$File1 = @SCRIPTDIR + "\" + Left(@SCRIPTNAME,Len(@SCRIPTNAME)-4) + ".txt"
If Open($Handle1,$File1,5) = 0
For Each $Printer in $aPrinters
$RC = WriteLine($Handle1,$Printer + @CRLF)
Next
$RC = Close($Handle1)
Else
? "Error opening or creating file: " + $File1
? "Error " + @ERROR + ": " + @SERROR
EndIf



KixLearner
(Fresh Scripter)
2006-09-26 03:28 PM
Re: Printer Check Logon Script

Cool thanks for the code. I ran that and it just created an empty text file yet I have 2 mapped network printers. Any ideas?

I do appreciate all your help with this.


Les
(KiX Master)
2006-09-26 03:31 PM
Re: Printer Check Logon Script

Did you copy/paste the UDF into the test script?

Witto
(MM club member)
2006-09-26 03:38 PM
Re: Printer Check Logon Script

You could also include the UDF and store it in a different file
Code:

Include = "\\Servername\Sharename\EnumPrinterConnections2.udf"



KixLearner
(Fresh Scripter)
2006-09-26 03:45 PM
Re: Printer Check Logon Script

I was being a muppet and forgot to link in the UDF bit. Works like a treat now - thank you VERY much for all your help!

KixLearner
(Fresh Scripter)
2006-09-26 03:47 PM
Re: Printer Check Logon Script

One last and very cheeky question, is there a way to make the exported text file the same name as the PC name? ie PC Name = ID1234 would create ID1234.txt

????


LonkeroAdministrator
(KiX Master Guru)
2006-09-26 04:09 PM
Re: Printer Check Logon Script

yes, use the @wksta macro.