Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for default printer on network PC's 1

Status
Not open for further replies.

MikeSh

MIS
Dec 19, 2003
4
0
0
US
We have the need to find out which PC's on our network do not have default printers installed. Is there any way to search for that type of information?
 
Hello MikeSh,

This is how you can do it with vbs. Copy and paste the script to a plaintext file with extension .vbs. Double-click on it to let go.
Code:
do while true
sComputer=inputbox("Enter the computer name or its ip address : -" & vbcrlf & vbcrlf & _
	"Local computer can be ""."" or ""127.0.0.1""", _
	"Search for default printer on a Computer",".")
if IsEmpty(sComputer) then wscript.echo "Operation is aborted by user." : wscript.quit(1)

if defaultprtr(sComputer, defaultprintername)=0 then
	if sComputer="." or sComputer="127.0.0.1" then sNameComp="Localhost" else sNameComp=sComputer
	if isempty(defaultprintername) then
		msg="Computer " & sNameComp & " does not have an assigned default printer."
	else
		msg="Computer " & sNameComp & " has an assigned default printer : " & defaultprintername & "."
	end if
else
	msg="Computer cannot be reached for various reason."
end if
wscript.echo msg 
loop

function defaultprtr(shost, prtrname)

	defaultprtr=0	'error-less return
	prtrname=""	'out-param
	on error resume next
	set svc=getobject("winmgmts:\\" & shost & "\root\cimv2")
	set cprtr=svc.execquery("select name, attributes from win32_printer")
	for each oprtr in cprtr
		if (oprtr.attributes and &h04)=&h04 then prtrname=oprtr.name : exit for
	next
	if err.number<>0 then defaultprtr=err.number : err.clear : prtrname=""
	on error goto 0
	set cprt=nothing : set svc=nothing

end function
regards - tsuji
 
tsuji,

A star for you sir. Just excellent work.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top