Page 1 of 1 1
Topic Options
#203257 - 2011-10-14 12:39 PM SetDefaultPrinter function on windows 7 x64...working???
asco Offline
Fresh Scripter

Registered: 2007-10-25
Posts: 25
hi all... im trying to use SetDefaultPrinter funtion... but i cant seam to get it to work. i know i must use the "printer name" and not the share name like in addprinter. The script runs and returns no error, but the default printer is not set.

her is my code:

 Code:
If AddPrinterConnection ("\\unysdc01\unysp01") = 0
   ? "Added printer connection Sort/Hvid. EDB Rum. Skovallen. Canon"
   If SetDefaultPrinter ("\\unysdc01\Sort/Hvid. EDB Rum. Skovallen. Canon") = 0
      ? "Set default printer to Sort/Hvid. EDB Rum. Skovallen. Canon"
   Endif

Endif


any ideers? pls?


Edited by Mart (2011-10-16 11:55 AM)
Edit Reason: Please use code tags when posting code.

Top
#203258 - 2011-10-14 03:01 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: asco]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
I'm just sitting here running through all my customers and cannot think if any of them have used the setdefaultprinter in the logon script since Win7x64, so unfortunately, I can't say I've tested this or not.

There is another option if you want to give it a try, which does allow you to use the share name. I have not tested this with win7 so please let me know your results if you go this route.

SetAsDefaultPrinter - http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=187517#Post187517

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

The rest of the UDFs are here -
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=7&page=1


Top
#203259 - 2011-10-14 03:38 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
My results on Win7 x64, worked on both SetDefaultPrinter and SetAsDefaultPrinter.

Maybe you have a misspelled printer name?

Top
#203260 - 2011-10-14 03:42 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Or maybe its this...

 Code:
If SetDefaultPrinter ("\\unysdc01\Sort/Hvid. EDB Rum. Skovallen. Canon") = 0


change to:
 Code:
If SetDefaultPrinter ("Sort/Hvid. EDB Rum. Skovallen. Canon") = 0

Top
#203261 - 2011-10-14 08:29 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
I can also confirm that SetDefaultPrinter() works on win7x64.
Top
#203262 - 2011-10-14 08:51 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
I use it in my login script and it works on all platforms that I've used, from W2K to Win7, 32 & 64 bit.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#203263 - 2011-10-14 11:48 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: asco]
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Try catching the error your setdefaultprinter() function returns and report back ;\)
_________________________



Top
#203275 - 2011-10-16 05:29 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Jochen]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I vote for Allen's solution!
does that count?
_________________________
!

download KiXnet

Top
#203302 - 2011-10-21 11:17 AM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Lonkero]
asco Offline
Fresh Scripter

Registered: 2007-10-25
Posts: 25
can someone of you post you code... i cant seam to get to work in any way!
Top
#203303 - 2011-10-21 11:27 AM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: asco]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This works just fine for me.
It assumes that the printer name and the share name are the same.

 Code:
Break on

$printer = "\\server\printer1"

$rc = AddPrinterConnection($printer)
?"Errors while adding printer:"
? @ERROR
? @SERROR
?
$rc = SetDefaultPrinter($printer)
? "Errors while setting default printer:"
? @ERROR
? @SERROR

sleep 5
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#203311 - 2011-10-21 06:01 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
My guess is that the weird printer name (probably the '/') is causing problems. Try changing the printer name to something simpler and see if it works.

I take it back, I tested with a local printer named the same as you specified and it worked fine. Problem must be elsewhere.


Edited by ShaneEP (2011-10-21 06:08 PM)

Top
#203314 - 2011-10-22 01:29 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: ShaneEP]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
hmm... wonder if this has something to do with security context...

have you tried running the script manually?
_________________________
!

download KiXnet

Top
#207667 - 2013-09-01 03:31 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: Mart]
InforMed Offline
Fresh Scripter

Registered: 2006-03-23
Posts: 5
Loc: UK
Old thread but we've recently moved from Citrix XenApp v5 (running on Windows 2003) to XenApp v6.5 (running on Windows 2008 R2 x64). We have *exactly* the same problem. The SetDefaultPrinter returns a result of 0 but the default printer doesn't actually change.

Script reduced to a single line:

"Result=" SetDefaultPrinter("Mac02 - Olivetti MF350")

Returns "Result=0". Change the printer name to something invalid and you get "Result=2" so one has the printer name right.

I wonder if SetDefaultPrinter is changing the registry and isn't changing the right key re: syswow64 etc?

Cheers, Rob.

Top
#207668 - 2013-09-01 03:52 PM Re: SetDefaultPrinter function on windows 7 x64...working??? [Re: InforMed]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4567
Loc: USA
Is the script a traditional logon script or GPO Startup Script?
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 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.068 seconds in which 0.025 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