<%@ language=vbscript %>
<%
option explicit
dim strsubmit 'form中用來保存提交按鈕的值
dim strprinterpath 'form中保存網(wǎng)絡打印機路徑的值
dim strusername 'form中用戶名的值
dim strpassword 'form中密碼的值
dim strmessage 'form打印內(nèi)容的值
dim objfs 'vbscript中的文件系統(tǒng)對象
dim objwshnet 'wsh中的網(wǎng)絡對象
dim objprinter '打印對象
strsubmit = request.form("submit")
%>
<%
if strsubmit = "" then
%>
注意的是:
由于這是演示,其中有關nt的帳號和密碼都是使用了不加密的手段在asp中傳遞的
真正的運用中應該對該登錄過程進行安全處理。
當以上信息被提交后,就可以按照下面的代碼進行打印了。
<%
else
' 從form中取得響應信息。
strprinterpath = request.form("printerpath")
strusername = request.form("username")
strpassword = request.form("password")
strmessage = request.form("message")
we will now use the vbscript filesystemobject 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連接網(wǎng)絡打印機
objwshnet.addprinterconnection "lpt1", strprinterpath, false, strusername, strpassword
' 使用文件系統(tǒng)對象將打印設備作為一個文件使用
set objprinter = objfs.createtextfile("lpt1:", true)
' 給打印設備送出文本
objprinter.write(strmessage)
'關閉打印設備對象并進行錯誤陷阱處理
on error resume next
objprinter.close
' 如果發(fā)生錯誤,關閉打印連接,并輸出錯誤信息
if err then
response.write ("error # " & cstr(err.number) & " " & err.description)
err.clear
else
' 操作成功,輸出確認信息
response.write("
")
response.write("")
response.write("打印消息送出: | ")
response.write("" & strmessage & " |
")
response.write("網(wǎng)絡打印機路徑: | ")
response.write("" & strprinterpath & " |
")
response.write("登錄帳號: | ")
response.write("" & strusername & " |
")
response.write("
")
response.write("")
end if
' 取消打印連接
objwshnet.removeprinterconnection "lpt1:"
set objwshnet = nothing
set objfs = nothing
set objprinter = nothing
end if
%>
該文章在 2010/7/8 1:03:23 編輯過