Page 1 of 1 1
Topic Options
#205987 - 2012-10-11 03:39 PM Windows 7 addprinterconnection also setting default?
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
Hello,

Just starting to test out the use of "ADDPRINTERCONNECTION" for the first time. What I'm seeing is on the windows 7 computers, while the printer connection is adding successfully, it's also setting the printer as the default. It's hard to search on these forums / the internet for people with similar issues because pretty much all of the results are people WANTING to set the default printer, where as I do not want to. Any ideas? tia

p.s. The same script running on windows xp works as expected. It just adds the additional connection and doesn't change the original default printer (what we want).

Top
#205990 - 2012-10-11 03:53 PM Re: Windows 7 addprinterconnection also setting default? [Re: syntax53]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
This is the first I have heard of this. However, if the user had no printers, and you add a printer, then I would expect it to be the default. Can you post your script?
Top
#205991 - 2012-10-11 04:09 PM Re: Windows 7 addprinterconnection also setting default? [Re: Allen]
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
 Code:
ADDPRINTERCONNECTION ("\\hi2\hifacultycopier")
ADDPRINTERCONNECTION ("\\hi2\hiofficecopier")


That's it. Of course I have other stuff that I run, but as a test I made a script that is that and only that. Now I will say that while I haven't been able to replicate the problem on XP at all (it always works as expected on XP), it DOES work as expected on my own machine Windows 7 machine (UAC off though) (adds the printer without changing the default). However, on 2 different clients that I've tested so far (both Windows 7 pro 64-bit with UAC turned ON, both same model computer built from same image, but in different domains) it changes the default.

And actually I just noticed while I was typing this that the default was changed to the faculty copier, which is the first line in the script. So that's weird. I'll play around with the order and see if there is any difference.


Edited by syntax53 (2012-10-11 04:10 PM)

Top
#205993 - 2012-10-11 04:19 PM Re: Windows 7 addprinterconnection also setting default? [Re: syntax53]
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
So I modified the script to this:

 Code:
;FROM http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=118766
function GetDefaultPrinter()
    $GetDefaultPrinter = join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction

$a = GetDefaultPrinter

$r1 = ADDPRINTERCONNECTION ("\\hi2\hifacultycopier")

$b = GetDefaultPrinter

$r2 = ADDPRINTERCONNECTION ("\\hi2\hiofficecopier")

$c = GetDefaultPrinter

OPEN (1, '%USERPROFILE%' + '\test.txt', 5)
WRITELINE (1, $a + @CRLF)
WRITELINE (1, $r1 + @CRLF)
WRITELINE (1, $b + @CRLF)
WRITELINE (1, $r2 + @CRLF)
WRITELINE (1, $c + @CRLF)
CLOSE (1)


And this is the output:

 Code:
RM 206 Mono
0\\hi2\HI Faculty Copier
0\\hi2\HI Faculty Copier


Yet if I run the same exact script on my machine:

 Code:
Technology Color
0Technology Color
0Technology Color



EDIT: Switching the order switches which one gets set to the default. So whichever the first one is is getting set as the default. So it seems to me that for whatever reason maybe it doesn't think a default printer is set and is therefor setting it?

EDIT2: same result if I run the script from a command line (instead of via logon script)


Edited by syntax53 (2012-10-11 04:27 PM)

Top
#205994 - 2012-10-11 04:24 PM Re: Windows 7 addprinterconnection also setting default? [Re: syntax53]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Try this just to see if what you think is happening, is really happening.

 Code:
if ADDPRINTERCONNECTION("\\hi2\hifacultycopier")=0
  "Printer Added"
else
  "Printer Not Added - " + @serror
endif


I know nothing about your environment, but keep in mind that you have to have both the 32 and 64 bit printer drivers installed on your printer server, and those drivers have to be identical in name and version.

Top
#205995 - 2012-10-11 04:30 PM Re: Windows 7 addprinterconnection also setting default? [Re: Allen]
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
 Originally Posted By: Allen
I know nothing about your environment, but keep in mind that you have to have both the 32 and 64 bit printer drivers installed on your printer server, and those drivers have to be identical in name and version.

I know the script is adding the printers and the drivers and I'm sure the driver (64bit) is on the server. These clients never had these printers (network copiers) that I'm adding, nor any other printer of the same model and I'm removing the printers after the script runs every time while testing it.

Top
#205996 - 2012-10-11 04:34 PM Re: Windows 7 addprinterconnection also setting default? [Re: syntax53]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Had the same issue.

See: http://www.kixtart.org/forums/ubbthreads...true#Post198009

Fixed it by adding printers, check if the correct printer is default and setting it as default if it is not default yet/anymore.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#205997 - 2012-10-11 04:48 PM Re: Windows 7 addprinterconnection also setting default? [Re: Mart]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
http://windows.microsoft.com/is-IS/windo...-work-or-school

http://social.technet.microsoft.com/Foru...3-8dda96dcdded/

just some thoughts.
_________________________
!

download KiXnet

Top
#205998 - 2012-10-11 04:55 PM Re: Windows 7 addprinterconnection also setting default? [Re: Lonkero]
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
So I modified the script to this to fix it:

 Code:
;FROM http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=118766
function GetDefaultPrinter()
    $GetDefaultPrinter = join(split(readvalue("HKEY_USERS\"+@sid+"\Software\Microsoft\Windows NT\CurrentVersion\Windows","Device"),',',1),'')
endfunction

$dp1 = GetDefaultPrinter
$r = ADDPRINTERCONNECTION ("\\hi2\hiofficecopier")
$r = ADDPRINTERCONNECTION ("\\hi2\hifacultycopier")
$dp2 = GetDefaultPrinter
IF NOT $dp1 = $dp2
    $r = SETDEFAULTPRINTER($dp1)
ENDIF


Kind of a hack, but it works.

edit: edited to include UDF for completeness.


Edited by syntax53 (2012-10-12 02:10 PM)

Top
#205999 - 2012-10-11 05:05 PM Re: Windows 7 addprinterconnection also setting default? [Re: Lonkero]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Interesting.... I've never come across this problem. Also interesting is the first link Lonk linked to, talks about clicking on "Manage Default Printers" button. I don't have that button at all on my desktop. Another site suggest disabling the change with reg hack...

writevalue("hkcu\Printers\Defaults","Disabled",1,"REG_DWORD")

http://www.normanbauer.com/2011/03/11/how-to-disable-windows-7s-default-printer-management/

Top
#206000 - 2012-10-11 05:20 PM Re: Windows 7 addprinterconnection also setting default? [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Two generalized and simplified snippet from our logon script. These two sections exist for all our network printers. We have it all AD group based and we have extensive logging in the script. Groups are generalized and the logging has been removed in the examples below. The printer server gets set earlier in the script and (to keep things nice and simple) the printer name and the share name are the same. We use the PriMapState UDF to check if the printer is already installed and if it is already default or not.

Mapping a printer:
 Code:
;Map printer Printer001
;Check group membership.
If InGroup("Printer001-Default") Or InGroup("Printer001-Extra")
	;Set printer name.
	$printer = "\\" + $printerserver + "\Printer001"
	;Check if the printer is already installed.
	If Not PriMapState($printer)
		;Printer is not installed. Add printer.
		;Add entry to text log file
		$rc = AddPrinterConnection($printer)
	EndIf
EndIf


Setting a default printer:
 Code:
;Set default printer Printer001
;Check group membership.
If InGroup("Printer001-Extra")
	$printer = "\\" + $printerserver + "\Printer001"
	;Check if the printer is already set as default.
	If PriMapState($printer) <> "2"
		;Set default printer.
		$rc = SetDefaultPrinter($printer)
	EndIf
EndIf
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#206001 - 2012-10-11 06:03 PM Re: Windows 7 addprinterconnection also setting default? [Re: Mart]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
Allen, I think it is one of them features. I've not seen this before either
_________________________
!

download KiXnet

Top
#206002 - 2012-10-11 07:18 PM Re: Windows 7 addprinterconnection also setting default? [Re: Lonkero]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
What version of Kix are you using? I only ask because wan't there changes to the printer portions in the newest release?

Edited by ShaneEP (2012-10-11 07:18 PM)

Top
#206003 - 2012-10-11 10:06 PM Re: Windows 7 addprinterconnection also setting default? [Re: ShaneEP]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
FYI - Our Universal Login Script evaluates which of several printers could/should be the default, then as printers are mapped, explicitly sets that one as default.

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

Top
#206009 - 2012-10-12 02:14 PM Re: Windows 7 addprinterconnection also setting default? [Re: ShaneEP]
syntax53 Offline
Fresh Scripter

Registered: 2004-11-17
Posts: 33
Loc: Pennsylvania
 Originally Posted By: ShaneEP
What version of Kix are you using? I only ask because wan't there changes to the printer portions in the newest release?


"KiXtart 2010 4.62"

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 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.084 seconds in which 0.03 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