Page 1 of 1 1
Topic Options
#123033 - 2004-07-15 05:49 PM Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Hi All

Within my Master Login Script I set local printer as default if found, but for some reason it is not working when loggin on, works fine if I run script after I logon,

Looks like Windows will set the default printer if one is not set after a ammount of idle time, the question is can you set a local printer to be default ???

Here is the code:

Code:

$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_Printer",,48)

? 'Local Printer List'
$x = 0
For Each $objItem in $colItems
? 'Printer Number: '+$x
? 'Printer PortName: '+$objItem.PortName

If $objItem.PortName = "LPT1:"
SetDefaultPrinter ($ObjItem.Name)
? 'Error: '+@ERROR
$DefaultPtr = "Set"
EndIf
$x = $x + 1
Next




Top
#123034 - 2004-07-15 07:15 PM Re: Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Ok I have done quite abit of testing, if I run my script at logon it fails to make the local printer called "Printer1" default.

I have evan tried ruuning a exe file called from the login script with a 20 second delay and it still don;t work.

But if I run the script by hand, it sets the default printer. Same script just running at different time.

I can see the seconds counting down on my delay script so I know that the login script part is running.

Any Ideas.

Rich

Top
#123035 - 2004-07-15 07:22 PM Re: Set Local Printer As Default
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Quote:

Any Ideas.



Besides pushing that portion of the script to RunOnce? No.

Sound like a load order issue.
http://luna.scriptlogic.com/support/kb/displayarticle.asp?UID=66&Str=
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#123036 - 2004-07-15 07:40 PM Re: Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Ok I have worked it out, M$ are crap .

No really if I run a login script that maps some network printers and sets a network printer as defualt. Works Fine.

If I map some network printers and set a network printer as default then set local printer as default. Don't Work.

If I map network printers, sleep for 30 seconds and them map the local printers. It Works.

??? Sorry Users no Local Default Printers. .

Thanks

Top
#123037 - 2004-07-15 08:22 PM Re: Set Local Printer As Default
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
As I'm sure you're aware supporting a LOCAL printer for one person is NOT cost effective at all. Unless a user has some very confidential data they print regularly we do not allow local printers. All printers are made Networked printers. In fact we typically will even make the "secured" printer Networked and control access to it.

In the long run it makes mangement much easier then when supported as a stand alone printer.

Top
#123038 - 2004-07-15 10:03 PM Re: Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
That is what we do, but we have just purshased a Pharmacy system, and they want a couple of local printers if the network fails.

And we have some HP G85's which don't like being connected to a Jetdirect.

Thanks

Top
#123039 - 2004-07-28 02:54 PM Re: Set Local Printer As Default
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Found the script useful, I have some usb printers, so changed it to reflect this. I also have a shared printer off my server which is a usb, so needed to set default printer to the first one detected.

I have one question, I would like to detect when the printer is active (Not greyed out) before setting to default. I have a number of laptops that connect to the network that may have numerious local printers setup.

How would this be detected?
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#123040 - 2004-07-28 02:59 PM Re: Set Local Printer As Default
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
With WMI.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#123041 - 2004-07-29 01:22 PM Re: Set Local Printer As Default
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
I'm a complete novice when it comes to wmi, found this code snippet:

Code:
  strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
Wscript.Echo "Name: " & objPrinter.Name
Wscript.Echo "Location: " & objPrinter.Location
Select Case objPrinter.PrinterStatus
Case 1
strPrinterStatus = "Other"
Case 2
strPrinterStatus = "Unknown"
Case 3
strPrinterStatus = "Idle"
Case 4
strPrinterStatus = "Printing"
Case 5
strPrinterStatus = "Warmup"
Case 6
strPrinterStatus = "case 6"
Case 7
strPrinterStatus = "offline"
End Select
Wscript.Echo "Printer Status: " & strPrinterStatus
Wscript.Echo "Server Name: " & objPrinter.ServerName
Wscript.Echo "Share Name: " & objPrinter.ShareName
Wscript.Echo
Next



But it does not detect if the local printer or network printers are offline, it just says they are idle?
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#123042 - 2004-07-30 12:08 PM Re: Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Yep this is the problem I had, I think you need a Bi-Directional cable.

Here is that code converted to KiX.

Anyone got PostPrep working with this new board, I get funny characters everywhere.

$strComputer = "."

$objWMIService = GetObject("winmgmts:"+"{impersonationLevel=impersonate}!\\"+$strComputer+"\root\cimv2")
$colInstalledPrinters = $objWMIService.ExecQuery ("Select * from Win32_Printer")


For Each $objPrinter In $colInstalledPrinters
? "Name: "+$objPrinter.Name
? "Location: "+$objPrinter.Location


Select Case $objPrinter.PrinterStatus
Case 1
$strPrinterStatus = "Other"
Case 2
$strPrinterStatus = "Unknown"
Case 3
$strPrinterStatus = "Idle"
Case 4
$strPrinterStatus = "Printing"
Case 5
$strPrinterStatus = "Warmup"
Case 6
$strPrinterStatus = "case 6"
Case 7
$strPrinterStatus = "offline"
EndSelect
? "Printer Status: "+$strPrinterStatus
? "Server Name: "+$objPrinter.ServerName
? "Share Name: "+$objPrinter.ShareName
Next



Edited by Richard Farthing (2004-07-30 12:09 PM)

Top
#123043 - 2004-07-30 01:12 PM Re: Set Local Printer As Default
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Found some c# which detects USB and parallel :
{Link]

Expect you know C# Richard? Wonder if it works though?
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#123044 - 2004-07-30 05:32 PM Re: Set Local Printer As Default
Richie19Rich77 Offline
Seasoned Scripter
*****

Registered: 2002-08-16
Posts: 624
Loc: London, England
Will load up C# tonight and have a look, but the code just looks like it is connecting into WMI. So can't see how it works.

Will let you know.

Thanks

Top
#123045 - 2004-07-30 08:59 PM Re: Set Local Printer As Default
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Lonkero has a new PostPrep code for the new board, but not sure he has completed work on it and don't believe he has published it yet.

Top
#123046 - 2004-08-05 10:59 AM Re: Set Local Printer As Default
Burger_Reto Offline
Fresh Scripter

Registered: 2004-08-05
Posts: 9
Loc: Luzern / Schweiz Switzerland
Hello

I have a something similar situation:
We have local USB-Printer and parallel-Printer and more networkprinter. I need a kix-script that search the localprinter (first USB, then LPT), an set this as the defaultprinter. if no localprinter is available, than i will define one of the networkprinter.

Can you or somone help me???

Thanks
Reto

Top
#123047 - 2004-08-05 11:39 AM Re: Set Local Printer As Default
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure, once you start your own thread.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


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

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.075 seconds in which 0.035 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