用ASP进行网络打印功能 (转)

用ASP进行网络打印功能 (转)[@more@]vbscript %>
Option Explicit

Dim strSubmit 'Form中用来保存提交按钮的值
Dim strPrinterPath 'Form中保存 网络打印机路径的值
Dim strUsername 'Form中 用户名的值
Dim strPass word 'Form中密码的值
Dim strMessage 'Form打印内容的值
Dim objFS 'VBScript中的 文件 系统 对象
Dim objWS .NET 'WSH中的网络对象
Dim objPrinter '打印对象

strSubmit = Request.Form("Submit")
%>



microsoft Visual Studio 6.0">



If strSubmit = "" Then
%>

注意的是:
由于这是演示,其中有关NT的帐号和密码都是使用了不 加密的手段在 ASP中传递的
真正的运用中应该对该登录过程进行 安全处理。
RM action="ASPPrint.asp" method=POST id=form name=form>
网络打印机路径:value="< domain >< Printer >">
登录帐号:value="">
登录口令:name=password>
请输入你想打印的文字:name=message>
 id=submit name=submit>



当以上信息被提交后,就可以按照下面的代码进行打印了。
Else
' 从form中取得响应信息。
strPrinterPath = Request.Form("printerpath")
strUsername = Request.Form("username")
strPassword = Request.Form("password")
strMessage = Request.Form("message")

We will now use the VBScript FileSystem object object and the WSH Network object. The Network object will
give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our
output to the printer. We create these objects in the following code example:

Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")
' 使用WSH连接网络打印机
objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, strUsername, strPassword
' 使用文件系统对象将打印设备作为一个文件使用
Set objPrinter = objFS.CreateTextFile("LPT1:", True)
' 给打印设备送出文本
objPrinter.Write(strMessage)
'关闭打印设备对象并进行错误陷阱处理
On Error Resume Next
objPrinter.Close
' 如果发生错误,关闭打印连接,并输出错误信息
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Description)
Err.Clear
Else
' 操作成功,输出确认信息
Response.Write("
")
Response.Write("
打印消息送出:" & strMessage & "
网络打印机路径:" & strPrinterPath & "
登录帐号:" & strUsername & "
")
Response.Write("
")
End If
' 取消打印连接
objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing
End If
%>



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10790690/viewspace-953083/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10790690/viewspace-953083/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值