PDA

Показать полную графическую версию : [решено] Как убрать "Диспетчер очереди печати" (spoolsv.exe) из трея?


kuzyaka
14-03-2010, 20:54
Суть такова.
Периодически забивается очередь печати, не дающая возможность печатать что либо дальше.
Единственный способ - перезапустить службу "Диспетчер очереди печати" с очисткой файлов из очереди печати.

Вот скрипт:
#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=printer.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

;============================================ Check of running copy ============================================
If WinExists(@ScriptName) Then Exit
AutoItWinSetTitle(@ScriptName)

$objShellApp = ObjCreate("Shell.Application")
$Service = "Spooler"
$dir = @SystemDir & "\spool\PRINTERS\"

If FileFindFirstFile($dir & "*.*") = -1 Then
MsgBox(48, "Очистка очереди печати.", "В очереди печати нет ни одного задания!" & @CRLF & "Можете продолжать печать!")
Exit
EndIf

If MsgBox(32+4, "Очистка очереди печати.", "Вы действительно хотите очистить очередь печати?") = 7 Then Exit

If $objShellApp.IsServiceRunning($Service) Then
If $objShellApp.ServiceStop($Service, false) = 0 Then
MsgBox(16, "Очистка очереди печати.","Ошибка " & @error & " при остановке сервиса")
Exit
EndIf
EndIf

Sleep(500)

If FileDelete($dir & "*.*") = 0 Then
MsgBox(16, "Очистка очереди печати.","Ошибка при удалении файлов из очереди печати!" & @CRLF & "Попробуйте еще раз!")
If $objShellApp.ServiceStart($Service, false) = 0 Then
MsgBox(16, "Очистка очереди печати.","Ошибка " & @error & " при запуске сервиса")
Else
If $objShellApp.IsServiceRunning($Service) = False Then
MsgBox(16, "Очистка очереди печати.","Ошибка " & @error & " при запуске сервиса")
EndIf
EndIf
Exit
EndIf

If $objShellApp.ServiceStart($Service, false) = 0 Then
MsgBox(16, "Очистка очереди печати.","Ошибка " & @error & " при запуске сервиса")
Else
If $objShellApp.IsServiceRunning($Service) = False Then
MsgBox(16, "Очистка очереди печати.","Ошибка " & @error & " при запуске сервиса")
EndIf
MsgBox(48, "Очистка очереди печати.","Очередь печати успешно очищена" & @CRLF & "Можете продолжить печать!")
EndIf

Но, после всего этого, в трее продолжает висеть значок "Диспетчера очереди печати" и сам он оттуда уже не убирается, даже если продолжаешь печатать.
Единственный способ (при пустой очереди печати) - это в его контекстном меню выбрать пункт "Обновить ...", тогда он исчезает.

Вот даже нашел скрипт как открыть контекстное меню:
#NoTrayIcon
#include <SysTray_UDF.au3>
;

$Pid = ProcessExists("spoolsv.exe")

If Not $Pid Then
MsgBox(16, "Error", "This process not exists")
Exit
EndIf

$Index = _SysTrayIconIndex($Pid)

If @error Then
MsgBox(16, "Error", "This process not have tray icon")
Exit
EndIf

_SysTrayIconClick($Index, "Right")

If @error Then
MsgBox(16, "Error", "There was an error to click on the icon")
Exit
EndIf

Func _SysTrayIconClick($iIndex, $sButton="Main")
Local $TrayIcon_Pos = _SysTrayIconPos($iIndex)
If Not IsArray($TrayIcon_Pos) Then Return SetError(1, 0, 0)

Local $Old_Mouse_Pos = MouseGetPos()
MouseClick($sButton, $TrayIcon_Pos[0], $TrayIcon_Pos[1], 1, 0)
MouseMove($Old_Mouse_Pos[0], $Old_Mouse_Pos[1], 0)
EndFunc

А вот как выбрать пункт меню "Обновить ..." пока не знаю.
Пытался с помощью ResHacker-а узнать ID контекстного меню, но в файле spoolsv.exe меню не оказалось.
Может иконку из трея можно убрать как то и иначе, не знаю, пока нашел только способ с "Обновить ..." - в общем надо как то её убрать из трея.

Так, что я пока в очень сильном затруднении как поступить дальше.

amel27
15-03-2010, 05:09
как выбрать пункт меню "Обновить ..." »
#include <GuiToolBar.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>

$sToolTipTitle = "Отложено документов:"
$hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
If @error Then Exit MsgBox(16, "Error", "System tray not found")

$iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
If $iSystray_ButCount = 0 Then Exit MsgBox(16, "Error", "No items found in system tray")

For $iSystray_ButtonNumber = 1 To $iSystray_ButCount
If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) Then ExitLoop
Next

If $iSystray_ButtonNumber = $iSystray_ButCount+1 Then Exit MsgBox(16, "Error", "Item Not Found")
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right", True, 1, 0)

WinWait("[CLASS:#32768]")
$hWndTray = WinGetHandle("[CLASS:#32768]")
$hMenu = _SendMessage($hWndTray, $MN_GETHMENU, 0, 0)
$aRect = _GUICtrlMenu_GetItemRect($hWndTray, $hMenu, 2)
MouseClick("left", $aRect[0]+5, $aRect[1]+5, 1, 1)

kuzyaka
15-03-2010, 14:48
amel27
Благодарю - все прекрасно работает.

mamont1
10-06-2010, 19:57
amel27 с вашей подсказки перелопатил скрипт для закрытия AdMunch.exe
#include <GuiToolBar.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>

;$sToolTipTitle = "Отложено документов:"
$sToolTipTitle = "Ad Muncher v4.8 Build 31318/2796"
$hSysTray_Handle = ControlGetHandle("[Class:Shell_TrayWnd]", "", "[Class:ToolbarWindow32;Instance:1]")
If @error Then Exit ;MsgBox(16, "Error", "System tray not found")

$iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)
If $iSystray_ButCount = 0 Then Exit ;MsgBox(16, "Error", "No items found in system tray")

For $iSystray_ButtonNumber = 1 To $iSystray_ButCount
If StringInStr(_GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber), $sToolTipTitle) Then ExitLoop
Next

If $iSystray_ButtonNumber = $iSystray_ButCount+1 Then Exit ;MsgBox(16, "Error", "Item Not Found")
_GUICtrlToolbar_ClickButton($hSysTray_Handle, $iSystray_ButtonNumber, "right", True, 1, 0)

WinWait("[CLASS:#32768]")
$hWndTray = WinGetHandle("[CLASS:#32768]")
$hMenu = _SendMessage($hWndTray, $MN_GETHMENU, 0, 0)
;$aRect = _GUICtrlMenu_GetItemRect($hWndTray, $hMenu, 2)
$aRect = _GUICtrlMenu_GetItemRect($hWndTray, $hMenu, 11)
MouseClick("left", $aRect[0]+170, $aRect[1]+5, 1, 0)

но - тоже не всегда срабатывает (если водиш мышкой)
используй BlockInput() на время работы этого куска кода

а куда вставить ?

madmasles
10-06-2010, 21:45
mamont1,
У меня Ad Muncher так закрывается:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <SysTray_UDF.au3>

$Pid = ProcessExists (http://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm)("AdMunch.exe")
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) $Pid Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
BlockInput (http://www.autoitscript.com/autoit3/docs/functions/BlockInput.htm)(1)
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $Old_Mouse_Pos = MouseGetPos (http://www.autoitscript.com/autoit3/docs/functions/MouseGetPos.htm)()
MouseMove (http://www.autoitscript.com/autoit3/docs/functions/MouseMove.htm)(@DesktopWidth (http://www.autoitscript.com/autoit3/docs/macros.htm#@desktopwidth) / 2, @DesktopHeight (http://www.autoitscript.com/autoit3/docs/macros.htm#@desktopheight), 0)
Sleep (http://www.autoitscript.com/autoit3/docs/functions/Sleep.htm)(50)
$Index = _SysTrayIconIndex($Pid)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) @error (http://www.autoitscript.com/autoit3/docs/macros.htm#@error) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
_SysTrayIconClick($Index, "Right")
MouseMove (http://www.autoitscript.com/autoit3/docs/functions/MouseMove.htm)($Old_Mouse_Pos[0], $Old_Mouse_Pos[1], 0)
BlockInput (http://www.autoitscript.com/autoit3/docs/functions/BlockInput.htm)(0)
Func (http://www.autoitscript.com/autoit3/docs/keywords.htm#Func) _SysTrayIconClick($iIndex, $sButton = "Main")
Local (http://www.autoitscript.com/autoit3/docs/keywords.htm#Local) $TrayIcon_Pos = _SysTrayIconPos($iIndex)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) Not (http://www.autoitscript.com/autoit3/docs/keywords.htm#Not) IsArray (http://www.autoitscript.com/autoit3/docs/functions/IsArray.htm)($TrayIcon_Pos) Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) Return (http://www.autoitscript.com/autoit3/docs/keywords.htm#Return) SetError (http://www.autoitscript.com/autoit3/docs/functions/SetError.htm)(1, 0, 0)
MouseClick (http://www.autoitscript.com/autoit3/docs/functions/MouseClick.htm)($sButton, $TrayIcon_Pos[0], $TrayIcon_Pos[1], 1, 0)
MouseClick (http://www.autoitscript.com/autoit3/docs/functions/MouseClick.htm)("left", $TrayIcon_Pos[0] - 15, $TrayIcon_Pos[1] - 15, 1, 0)
EndFunc (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndFunc) ;==>_SysTrayIconClickSysTray_UDF.au3 (http://www.autoitscript.com/forum/index.php?showtopic=13704&hl=SysTray_UDFau3&st=0)

А так, ИМХО, проще всего:If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) ProcessExists (http://www.autoitscript.com/autoit3/docs/functions/ProcessExists.htm)("AdMunch.exe") Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then) ProcessClose (http://www.autoitscript.com/autoit3/docs/functions/ProcessClose.htm)("AdMunch.exe")

amel27
11-06-2010, 05:19
но - тоже не всегда срабатывает (если водиш мышкой)
Цитата:
используй BlockInput() на время работы этого куска кода
а куда вставить ? »

BlockInput(1) - в начале,
BlockInput(0) - в конце скрипта

mamont1
11-06-2010, 12:17
madmasles у меня ваш вариант старый (http://forum.oszone.net/post-1420909.html#post1420909) тоже работал, но не всегда.
А вариант который ваше с
BlockInput(1) - в начале,
BlockInput(0) - в конце скрипта »
работает (шевелил мышку - бодро). Спасибо.

amel27 Спасибо.

Какой редактор используете для встави кода? Или ... ?




© OSzone.net 2001-2012