2015-08-09 134 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