<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script type="text/javascript">
function init()
{
try
{
var nt = new ActiveXObject("WScript.Network");//alert(2);
var oPrinters = nt.EnumPrinterConnections();//需要编写 ActiveX 控件来获得
if(oPrinters==null||oPrinters.length==0)
{
alert('当前你的机器暂没安装打印机');
return;
}else
{
//alert('当前打印机台数:'+oPrinters.length);
}
var thisPrinter;
for(i = 0; i<oPrinters.length; i+=2)
{
alert(oPrinters.Item(i+1));
var name = oPrinters.Item(i+1);
//name += "";
if(name == "Microsoft XPS Document Writer")
{
nt.SetDefaultPrinter('Microsoft XPS Document Writer');
}
}
}catch(e)
{
alert(e.name + ":" + e.message);
}
}
</script>
</HEAD>
<BODY>
<table width="100%">
<tr>
<td align="center">
<input id="Print" type="Button" value="Print" onclick="init();" style="width:60px;"/>
<td>
</tr>
</table>
</BODY>
</HTML>