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!

default printer and location 1

Status
Not open for further replies.

Fursten

Programmer
Dec 27, 2000
403
0
0
PT
Hi,

Can someone tell me how can I get the default printer and location using javascript.

Thank you
 
Not easily. You could possibly create an ActiveX control. Search for printer in this forum, you should get a lot of answers back.

*cLFlaVA
----------------------------
[tt]insert funny quotation here.[/tt]
 
Hello Fursten,

In wsh script .js and for the local box, it is something like this.
Code:
var bFound=false;
var shost=".";
var svc=GetObject("WinMgmts:\\\\"+shost+"\\root\\cimv2");
var squery="select name, attributes, location from win32_printer";
var cprtr=svc.ExecQuery(squery);
var e=new Enumerator(cprtr);
for (;!e.atEnd();e.moveNext()) {
	if ((e.item().attributes & 4) == 4) {
		//location can be null meaning unknown
		WScript.Echo ("Default printer : " + e.item().name + "\n" + "Printer location : " + e.item().location);
		e.moveLast;
		bFound = true;
	}
}
if (!bFound) WScript.Echo ("Default printer not found.")
Make its way to html may encounter security problem. If you transcribe it to .hta file, it should do with WScript.Echo() being replaced by alert() or document.write according to the setting.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top