用ASP進(jìn)行網(wǎng)絡(luò)打印功能
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
[p]<%@ language=vbscript %>[br]<%[br]option explicit[/p]
[p]dim strsubmit 'form中用來(lái)保存提交按鈕的值[br]dim strprinterpath 'form中保存網(wǎng)絡(luò)打印機(jī)路徑的值[br]dim strusername 'form中用戶(hù)名的值[br]dim strpassword 'form中密碼的值[br]dim strmessage 'form打印內(nèi)容的值[br]dim objfs 'vbscript中的文件系統(tǒng)對(duì)象[br]dim objwshnet 'wsh中的網(wǎng)絡(luò)對(duì)象[br]dim objprinter '打印對(duì)象[/p] [p]strsubmit = request.form("submit")[br]%>[/p] [p][br][br][br][br][/p] [p]<%[br]if strsubmit = "" then[br]%>[/p] [p]注意的是:[br]由于這是演示,其中有關(guān)nt的帳號(hào)和密碼都是使用了不加密的手段在asp中傳遞的[br]真正的運(yùn)用中應(yīng)該對(duì)該登錄過(guò)程進(jìn)行安全處理。[br][/p] [p]當(dāng)以上信息被提交后,就可以按照下面的代碼進(jìn)行打印了。[br]<%[br]else[br]' 從form中取得響應(yīng)信息。[br]strprinterpath = request.form("printerpath")[br]strusername = request.form("username")[br]strpassword = request.form("password")[br]strmessage = request.form("message")[/p] [p]we will now use the vbscript filesystemobject object and the wsh network object. the network object will[br]give us the methods we need to open a printer connection, and the filesystemobject will allow us to stream our[br]output to the printer. we create these objects in the following code example: [/p] [p]set objfs = createobject("scripting.filesystemobject")[br]set objwshnet = createobject("wscript.network")[br]' 使用wsh連接網(wǎng)絡(luò)打印機(jī)[br]objwshnet.addprinterconnection "lpt1", strprinterpath, false, strusername, strpassword[br]' 使用文件系統(tǒng)對(duì)象將打印設(shè)備作為一個(gè)文件使用[br]set objprinter = objfs.createtextfile("lpt1:", true)[br]' 給打印設(shè)備送出文本[br]objprinter.write(strmessage)[br]'關(guān)閉打印設(shè)備對(duì)象并進(jìn)行錯(cuò)誤陷阱處理[br]on error resume next[br]objprinter.close[br]' 如果發(fā)生錯(cuò)誤,關(guān)閉打印連接,并輸出錯(cuò)誤信息[br]if err then[br]response.write ("error # " & cstr(err.number) & " " & err.description)[br]err.clear [br]else[br]' 操作成功,輸出確認(rèn)信息[br]response.write("
該文章在 2010/7/8 1:03:23 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |