Page 1 of 1 1
Topic Options
#159734 - 2006-03-24 07:09 PM Need help detecting USB or LPT1 printers
dtadin Offline
Fresh Scripter

Registered: 2006-03-17
Posts: 5
I need to add something to my login script that checks to see if the user currently has a LPT1 or USB printer as their default. If not I need to map the user to a network printer.
Now I know I can easly see if they have a LPT1 printer using IF EXIST('LPT1:')
any idea what I can do with a USB printer? DOT4_001 is the port showing in windows and doesnt seem to want to work if I use that in place of LPT1:

Anyhelp?

Thanks
Dennis Tadin

Top
#159735 - 2006-03-24 07:16 PM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Hello and Welcome to the board


You could read the registry and do an IfInStr after enuming the keys

HKEY_CURRENT_USER\Printers\Connections

If you need further assistance assembling the code to do this please let us know.

Top
#159736 - 2006-03-24 08:27 PM Re: Need help detecting USB or LPT1 printers
dtadin Offline
Fresh Scripter

Registered: 2006-03-17
Posts: 5
ntdoc I havent used kixtart to check the registry yet.
So yes im probley going to need some help with that part.
what am I looking for inside connections? I have users with a dozen or so diffrent types of printers some lpt some usb. I really dont want to check form every diffrent type of printer (I see in connections it lists them by names and not by port)


Edited by dtadin (2006-03-24 08:28 PM)

Top
#159737 - 2006-03-24 08:40 PM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Not sure... if I get time I'll look and see if one of the many UDFs can help or how to detect that alone.

I don't have any USB printer installed at the moment so can't really check, but I may have access to one that has a USB printer installed.

Top
#159738 - 2006-03-24 08:51 PM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
PrinterList() will help you get the ports, but you will still need some code to figure out what printer is the default.
Top
#159739 - 2006-03-24 08:59 PM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Try this...
Code:
 
break on

$objWMIService = GetObject("winmgmts:\\.\root\cimv2")
$colPrinters = $objWMIService.ExecQuery("Select * From Win32_Printer Where Default = TRUE")
For Each $objPrinter in $colPrinters
? $objPrinter.Name
? $objPrinter.portname
Next


Top
#159740 - 2006-03-24 09:00 PM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Well there is a UDF to get that too
Top
#159741 - 2006-03-24 09:01 PM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I figured there was... I just couldn't put my hands on it.
Top
#159742 - 2006-03-25 12:17 AM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
GetDefaultPrinter() - Returns default printer
http://www.kixtart.org/ubbthreads/showflat.php?Cat=0&Number=117544

Top
#159743 - 2006-03-25 12:58 AM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Just having a little fun with this...

Microsoft.com - Managing Printer Operations

Code:
break on 


$dp=GetDefaultPrinterProperties
? "Capabilities: " + join($dp.Capabilities,",")
? "CapabilityDescriptions: " + join($dp.CapabilityDescriptions,",")
? "Description: " + $dp.Description
? "DeviceID: " + $dp.DeviceID
? "DriverName: " + $dp.DriverName
? "Location: " + $dp.Location
? "Name: " + $dp.Name
? "PortName: " + $dp.PortName
? "Separtor File: " + $dp.SeparatorFile
? "ServerName: " + $dp.ServerName
? "ShareName: " + $dp.ShareName
? "StartTime: " + $dp.StartTime
? "TimeofLastReset: " + $dp.TimeOfLastReset
? "UntilTime: " + $dp.UntilTime


Function GetDefaultPrinterProperties()
dim $colprinters,$printer
$colprinters=GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * From Win32_Printer Where Default = TRUE")
if @error
exit @error
endif
for each $printer in $colprinters
$GetDefaultPrinterProperties=$printer
next
endfunction



Produces:
Code:
 
Capabilities: 4,3,5
CapabilityDescriptions: Copies,Duplex,Collate
Description:
DeviceID: hp LaserJet 1012
DriverName: hp LaserJet 1012
Location:
Name: hp LaserJet 1012
PortName: IP_192.168.0.2
Separtor File:
ServerName:
ShareName:
StartTime:
TimeofLastReset:
UntilTime:



Edited by Allen (2006-03-25 04:32 AM)

Top
#159744 - 2006-03-25 03:40 AM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Allen can you confirm this works for you against a remote computer?

On every system I've tried so far it comes back blank.
It does work locally though.

Top
#159745 - 2006-03-25 04:32 AM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I did not do a whole lot of testing on it... and I bet your finding are right... I'll change it. Thanks for looking at it.
Top
#159746 - 2006-03-26 12:26 AM Re: Need help detecting USB or LPT1 printers
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_printer.asp

Just reading through this article and noticed that the Default Property only works on XP and above.

Top
#159747 - 2006-03-26 06:28 AM Re: Need help detecting USB or LPT1 printers
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Yeah I know, but I've run it against other XP and 2003 systems and they come back blank.

Not sure if I'm having some type of networking issue or what so was curious if it worked remotely for you.

Top
#159748 - 2006-03-27 09:25 PM Re: Need help detecting USB or LPT1 printers
dtadin Offline
Fresh Scripter

Registered: 2006-03-17
Posts: 5
Ok guys taking your code I thought I had a solution. (This is just a test to see if it works) But it doesnt seem to want to work... Any ideas? Help this n00b kixtart user ;p

Code:
break on 


$dp=GetDefaultPrinterProperties
$printerport= "$dp.PortName"


? "Printer PortName: " + $dp.PortName


Function GetDefaultPrinterProperties()
dim $colprinters,$printer
$colprinters=GetObject("winmgmts:\\.\root\cimv2").ExecQuery("Select * From Win32_Printer Where Default = TRUE")
if @error
exit @error
endif
for each $printer in $colprinters
$GetDefaultPrinterProperties=$printer
next
endfunction

if $printerport = ("IP_192.168.4.39")
? "IP Port Exists"
else
? "IP Port Does not Exist"
endif

if $printerport = "LPT1:"
? "LPT1 Port Exists"
else
? "LPT1 Port Does not Exist"
endif

if $printerport = "DOT4_001"
? "USB Port Exists"
else
? "USB Port Does not Exist"
endif


Top
#159749 - 2006-03-27 11:28 PM Re: Need help detecting USB or LPT1 printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I ran your script
Code:
$printerport= "$dp.PortName"

I would not use quotes because $dp is a variable
Code:
? "Printer PortName:            " + $dp.PortName

This returns the (IP) port name of my (default) home printer
Your script seems OK to me...

Top
#159750 - 2006-03-27 11:39 PM Re: Need help detecting USB or LPT1 printers
dtadin Offline
Fresh Scripter

Registered: 2006-03-17
Posts: 5
Um yeah witto, but the part thats not working is the
if $printerport = ("IP_192.168.4.39")
? "IP Port Exists"
else
? "IP Port Does not Exist"
endif

Change that ip to the ip of your home printer and see if it says IP Port exists... It doesnt detect it right. Not sure what I am doing wrong.

Top
#159751 - 2006-03-27 11:46 PM Re: Need help detecting USB or LPT1 printers
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Well, I added
Code:
If $printerport = "IP_192.168.222.1"
? "IP Port Exists"
Else
? "IP Port Does not Exist"
EndIf


and removed the other If/EndIf statements.
The output on the screen is:
Code:
Printer PortName:            IP_192.168.222.1
IP Port Exists



Edited by Witto (2006-03-28 08:26 AM)

Top
#159752 - 2006-03-27 11:56 PM Re: Need help detecting USB or LPT1 printers
dtadin Offline
Fresh Scripter

Registered: 2006-03-17
Posts: 5
It was those damn quotes, I fixed that and your right its working now.

Thanks Witto!
Dtadin

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

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