#153516 - 2005-12-16 09:05 AM
SetDefaultPrinter, cannot get it to work =\
|
J4zen
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
|
|
|
|
#153518 - 2005-12-16 10:34 AM
Re: SetDefaultPrinter, cannot get it to work =\
|
J4zen
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
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
|
|
|
|
#153521 - 2005-12-16 10:58 AM
Re: SetDefaultPrinter, cannot get it to work =\
|
NTDOC
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
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
|
|
|
|
#153525 - 2005-12-16 01:54 PM
Re: SetDefaultPrinter, cannot get it to work =\
|
J4zen
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 857 anonymous users online.
|
|
|