2015-08-09 97 views
-2

我希望在從任何應用程序提供打印命令10秒後執行腳本。批處理腳本:我想在發出打印命令後運行批處理腳本

@echo off 
echo. 
echo Purging the print queue... 
net stop Spooler 
echo Deleting all print jobs... 
ping localhost -n 4 > nul 
del /q %SystemRoot%\system32\spool\printers\*.* 
net start Spooler 
echo Done! 
ping localhost -n 4 > nul 
+1

告訴我們你試過了什麼。沒有免費代碼寫作服務在這裏! – CrakC

+0

我有一個清除打印隊列的腳本,我希望在給出打印命令'@echo off echo 10秒後運行。 回聲清除打印隊列... 淨停止後臺處理程序 呼應刪除所有打印作業...... 平本地主機-N 4> NUL 德爾/ Q的%SystemRoot%\ SYSTEM32 \閥芯\打印機\ *。* 網絡啓動後臺打印程序 echo done! ping localhost -n 4> nul' –

+0

從任何應用程序打印後運行它都會非常困難(可能不可能)。你能告訴我們你想完成什麼嗎?也許還有另一種方法來實現它。 – aphoria

回答

0
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & _ 
    "." & "\root\cimv2") 


Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ 
    ("Select * From __InstanceCreationEvent Within 5 Where " _ 
    & "Targetinstance Isa 'CIM_DirectoryContainsFile' and " _ 
    & "TargetInstance.GroupComponent= " _ 
    & "'Win32_Directory.Name=""c:\\\\Windows\\\\System32\\\\Spool\\\\Printers""'") 

Do 
    Set objLatestEvent = colMonitoredEvents.NextEvent 
    Wscript.Echo objLatestEvent.TargetInstance.PartComponent 
Loop 

http://www.codeproject.com/Articles/42212/WMI-and-File-System-Monitoring

改編而且這將啓動一個服務

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") 

Set colItems = objWMIService.ExecQuery("Select * From Win32_Service") 

For Each objItem in colItems 
    If Lcase(objitem.Name) = "spooler" Then 
     msgbox objitem.name & " " & objitem.status & " " & objitem.state 
     objitem.StartService 
    End If 
Next 

這將刪除打印機文件夾中的文件

On error resume next 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set fldr = fso.GetFolder("c:\windows\system32\spool\Printers") 
For each f in fldr.files 
    f.delete 
Next 
+0

大部分時間打印隊列無法清除。這會導致隨機或重新打印相同的文件。我想確保隊列在持續時間後變得清晰,以便用戶可以手動提供下一個打印。因此,請告知如何使用此腳本 –

0

我在vwork和我的電腦在家打破了。像這樣的東西。

Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & _ 
    "." & "\root\cimv2") 


Set colMonitoredEvents = objWMIService.ExecNotificationQuery _ 
    ("Select * From __InstanceCreationEvent Within 5 Where " _ 
    & "Targetinstance Isa 'CIM_DirectoryContainsFile' and " _ 
    & "TargetInstance.GroupComponent= " _ 
    & "'Win32_Directory.Name=""c:\\\\Windows\\\\System32\\\\Spool\\\\Printers""'") 

Do 
    wscript.scleep 1000 
    On error resume next 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    Set fldr = fso.GetFolder("c:\windows\system32\spool\Printers") 
    For each f in fldr.files 
     f.delete 
    Next 
Loop