Page 1 of 1 1
Topic Options
#153516 - 2005-12-16 09:05 AM SetDefaultPrinter, cannot get it to work =\
J4zen Offline
Fresh Scripter

Registered: 2005-12-09
Posts: 12
Hey,

i did my best reading the manual over and over again ( Command Reference ), even copying the entire code hoping it'd work.. but it never did

Code:

if $sDefaultPrinter<>""
? "Bezig met printer: "+$sDefaultPrinter+ ", als Standaard in te stellen."
If SetDefaultPrinter($sDefaultPrinter) = 0
? $sDefaultPrinter+" is als standaard ingesteld."
else
? $sDefaultPrinter+" kon niet als standaard ingesteld worden."
endif
else
? "Geen standaard printer opgegeven, windows zal er automatisch een aanwijzen."
endif


this will ALWAYS return that the printer couldn't be set to default for some weird reason.
I am totally lost, where on EARTH did i go wrong?

Thanks !
-Jeroen

Top
#153517 - 2005-12-16 10:15 AM Re: SetDefaultPrinter, cannot get it to work =\
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Well I can't really read your code that much as it's not in English and unfortunately I only read/write English.

That aside, it looks like you have a variable assigned to something that is not shown here.

The SetDefaultPrinter is a Function which takes parameters to make it work.

Remember that PRINTER NAME and SHARE NAME can be different. The SetDefaultPrinter wants the PRINTER NAME, but if you created the printer with the AddPrinterConnection, you must include both the servername and the sharename.

SetDefaultPrinter('\\Server\sharename')

You can use a variable to prevent the return code from being seen on the console and you can output the error-code if wanted to verify

$RC=SetDefaultPrinter('\\Server\sharename')
'Setting Printer Default: ' + @SERROR ?
 

Top
#153518 - 2005-12-16 10:34 AM Re: SetDefaultPrinter, cannot get it to work =\
J4zen Offline
Fresh Scripter

Registered: 2005-12-09
Posts: 12
Ill post my entire code to clearify the mather

Code:

;#############################################################################
;Script geschreven door Jeroen van Vierzen
;Installeerd printers vanaf netwerk drive en kan deze als standaard instellen.
;#############################################################################

Dim $PrinterName[]

$IniFile=@ScriptDir+"\setup.ini"

$PrinterName = ReadProfileString($IniFile, "Printer", "Printer Naam")
$sDefaultPrinter = ReadProfileString($IniFile, "Printer", "Standaard Printer")
$ServerName = ReadProfileString($IniFile, "Printer", "Server")


$PrinterName=Split($PrinterName,",")

For Each $i In $PrinterName

? "Bezig te verbinden met printer "+$i+" op "+$ServerName+"."
if AddPrinterConnection("\\"+$ServerName+"\"+$i) = 0
? "Verbinding gemaakt met printer "+$i+"."
else
? "Verbinding met printer "+$i+" is mislukt."
endif

next

$sDefaultPrinter= "\\"+ $ServerName+"\"+$sDefaultPrinter

if $sDefaultPrinter<>"\\\"
? "Bezig met printer: "+$sDefaultPrinter+ ", als Standaard in te stellen."
If SetDefaultPrinter($sDefaultPrinter) = 0
? $sDefaultPrinter+" is als standaard ingesteld."
else
? $sDefaultPrinter+" kon niet als standaard ingesteld worden."
endif
else
? "Geen standaard printer opgegeven, windows zal er automatisch een aanwijzen."
endif



The dutch debugs are just messages saying "Printer $Printer Set to default" etc.


Edited by J4zen (2005-12-16 10:40 AM)

Top
#153519 - 2005-12-16 10:42 AM Re: SetDefaultPrinter, cannot get it to work =\
J4zen Offline
Fresh Scripter

Registered: 2005-12-09
Posts: 12
Aahhh wait ! Hurray .

i was using the Share name in stead of the actual name of the printer,
Thanks a lot for the fast reply!

Top
#153520 - 2005-12-16 10:54 AM Re: SetDefaultPrinter, cannot get it to work =\
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Doc , you can't read Dutch? Shame on you
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#153521 - 2005-12-16 10:58 AM Re: SetDefaultPrinter, cannot get it to work =\
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Dutch eh!... Wasn't sure, was going to say German but didn't want to upset anyone

Glad he got it going none the less.
 

Top
#153522 - 2005-12-16 11:57 AM Re: SetDefaultPrinter, cannot get it to work =\
J4zen Offline
Fresh Scripter

Registered: 2005-12-09
Posts: 12
bringing me to the next problem =\..

\\server01\applic\Iconen\docent,%USERPROFILE%\Bureaublad\

Does Kix change %USERPROFILE% or %USERNAME% to the actual username or location?
for some weird reason, when i read this string from an ini file it won't actually copy it to that directory =\.

Code:

[Bestanden]
Inifile:
1=\\server01\applic\Iconen\docent,%USERPROFILE%\Bureaublad\



actual code:
Code:

$IniFile=@ScriptDir+"\Setup.ini"
$Amount_of_Files = ReadProfileString($IniFile,"Kopie","Aantal Bestanden")

Open (3 , "C:\KixLOG.TXT", 5)
WriteLine( 3 , "Script sessie gestart op " +@DATE+ " om " + @TIME + @CRLF )
WriteLine( 3 , "----------------------------" + @CRLF)
Close(3)

for $i=1 to $Amount_of_Files
$Current = $i
$Current = ReadProfileString($IniFile,"Bestanden",$i)
$File_Array = Split($Current,",")
if $File_Array[0] = ""
GOTO "EndFunc"
else
? "Bezig met kopieren van "+$File_Array[0]+" naar "+$File_Array[1]
Copy $File_Array[0] $File_Array[1]
if @error
? "Fout opgetreden bij het kopieren van "+$File_Array[0]+" naar "+$File_Array[1]
$Error_Count = $Error_Count+1
if Open( 3 , "C:\KixLOG.TXT", 5 ) = 0
WriteLine( 3 , "Fout bij kopieren van bestand: " + $File_Array[0] + " naar "+ $File_Array[1]+"."+ @CRLF)
$NoErr = 0
Close(3)

else
BEEP
$NoErr = 1
endif
else

endif
endif

next $i

:EndFunc
if $NoErr = 1
if $Error_Count <> 0
? "Er zijn "+$Error_Count+" fout(en) opgetreden, helaas kon er geen logbestand aangemaakt worden."+@CRLF
else
? "Opdracht uitgevoerd."
endif

else
if $Error_Count <> 0
? "Er zijn "+$Error_Count+" fouten opgetreden, "+@CRLF+"voor meer informatie kunt u het logbestand raadplegen op: C:\KixLOG.TXT" +@CRLF
Open(3, "C:\KixLOG.TXT", 5)
WriteLine( 3 , "----------------------------" + @CRLF)
else
? "Opdracht uigevoerd."+@CRLF
Open(3, "C:\KixLOG.TXT", 5)
WriteLine( 3 , "Succesvol uitgevoerd" + @CRLF)
WriteLine( 3 , "----------------------------" + @CRLF)
endif
endif




for some weird reason it doesnt change the %USERNAME% to the actual username..
also i noticed you dont have a Replace function in Kixscript ( or i totally read over it.. in that case i apologise ! ).

i was going to solve this by searching for the string %USERNAME% and replacing that with @USERID.. which should have done the trick ( if the problem actually is where i think it is ).


PS:
AmountOfFiles is just a variable defining how many files or directories are to be copied it is defined properly in the ini file, so no problems there.


thanks again for your support so far!


Edited by J4zen (2005-12-16 11:59 AM)

Top
#153523 - 2005-12-16 12:05 PM Re: SetDefaultPrinter, cannot get it to work =\
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Not exactly sure what you're doing but try using double %%USERPROFILE%% and see if it works.
Top
#153524 - 2005-12-16 12:09 PM Re: SetDefaultPrinter, cannot get it to work =\
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Quote:

Remember that PRINTER NAME and SHARE NAME can be different. The SetDefaultPrinter wants the PRINTER NAME, but if you created the printer with the AddPrinterConnection, you must include both the servername and the sharename.

SetDefaultPrinter('\\Server\sharename')

You can use a variable to prevent the return code from being seen on the console and you can output the error-code if wanted to verify

$RC=SetDefaultPrinter('\\Server\sharename')
'Setting Printer Default: ' + @SERROR ?
 




no.
this is exactly what it is not.
it's the PRINTERNAME!

$RC=SetDefaultPrinter('\\Server\PRINTERNAME')

btw doc, you copied these lines from some doc, right?
I mean, it must be.
you a veteran, you wouldn't go this far out there without support of written word...


Edited by Jooel (2005-12-16 12:36 PM)
_________________________
!

download KiXnet

Top
#153525 - 2005-12-16 01:54 PM Re: SetDefaultPrinter, cannot get it to work =\
J4zen Offline
Fresh Scripter

Registered: 2005-12-09
Posts: 12
What i'm doing in this script is copying heaps of files to a new directory,
First it checks how many files need to be copied, then it loops trough them one by one splitting source and destination by ","..

this really isnt the point tho :P the thing that mathers is that it somehow doesnt understand how translate %USERNAME% to the users actual username. it DOES work if i specify the path manually so the copy command is working as it should.

Top
#153526 - 2005-12-16 02:09 PM Re: SetDefaultPrinter, cannot get it to work =\
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
to translate the env var to it's content, use expandEnvironmentVars()

for usage and stuff, see manual.
_________________________
!

download KiXnet

Top
#153527 - 2005-12-16 08:16 PM Re: SetDefaultPrinter, cannot get it to work =\
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Yep, copied from the 4.51 CHM file from ScriptLogic.

Was going to say PRINTERNAME, but the manual said SHARENAME when the connection was created with the AddPrinterConnection function so I gave that as example.

Regardless, seems he got it working which is what he wanted.

I haven't added a printer or set a default printer in a LONG time now via script so didn't have solid recent experience to contradict.

Top
#153528 - 2005-12-16 10:21 PM Re: SetDefaultPrinter, cannot get it to work =\
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no doc, manual says printername.
chm is not manual.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.094 seconds in which 0.051 seconds were spent on a total of 12 queries. Zlib compression enabled.

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