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
告訴我們你試過了什麼。沒有免費代碼寫作服務在這裏! – CrakC
我有一個清除打印隊列的腳本,我希望在給出打印命令'@echo off echo 10秒後運行。 回聲清除打印隊列... 淨停止後臺處理程序 呼應刪除所有打印作業...... 平本地主機-N 4> NUL 德爾/ Q的%SystemRoot%\ SYSTEM32 \閥芯\打印機\ *。* 網絡啓動後臺打印程序 echo done! ping localhost -n 4> nul' –
從任何應用程序打印後運行它都會非常困難(可能不可能)。你能告訴我們你想完成什麼嗎?也許還有另一種方法來實現它。 – aphoria