Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/16/2024 in all areas

  1. jguinch

    Printers Management UDF

    Hello. I did create these few functions several months ago. I post here, if it can interest someone. These functions based on WMI queries allow you to manage printers : add / delete printer, driver, port, or obtain configuration, set default printer ... I let you discover it with the code. Here is the list of the available functions : _PrintMgr_AddLocalPort _PrintMgr_AddLPRPort _PrintMgr_AddPrinter _PrintMgr_AddPrinterDriver _PrintMgr_AddTCPIPPrinterPort _PrintMgr_AddWindowsPrinterConnection _PrintMgr_CancelAllJobs _PrintMgr_CancelPrintJob _PrintMgr_EnumPorts _PrintMgr_EnumPrinter _PrintMgr_EnumPrinterConfiguration _PrintMgr_EnumPrinterDriver _PrintMgr_EnumPrinterProperties _PrintMgr_EnumPrintJobs _PrintMgr_EnumTCPIPPrinterPort _PrintMgr_Pause _PrintMgr_PortExists _PrintMgr_PrinterExists _PrintMgr_PrinterSetComment _PrintMgr_PrinterSetDriver _PrintMgr_PrinterSetPort _PrintMgr_PrinterShare _PrintMgr_PrintTestPage _PrintMgr_RemoveLocalPort _PrintMgr_RemoveLPRPort _PrintMgr_RemovePrinter _PrintMgr_RemovePrinterDriver _PrintMgr_RemoveTCPIPPrinterPort _PrintMgr_RenamePrinter _PrintMgr_Resume _PrintMgr_SetDefaultPrinter And some examples : #include <Array.au3> #include "PrintMgr.au3" _Example() Func _Example() ; Remove a printer called "My old Lexmark printer" : _PrintMgr_RemovePrinter("My old Lexmark printer") ; Remove the driver called "Lexmark T640" : _PrintMgr_RemovePrinterDriver("Lexmark T640") ; Remove the TCP/IP printer port called "TCP/IP" _PrintMgr_RemoveTCPIPPrinterPort("MyOLDPrinterPort") ; Add a driver, called "Samsung ML-451x 501x Series", and driver inf file is ".\Samsung5010\sse2m.inf" _PrintMgr_AddPrinterDriver("Samsung ML-451x 501x Series", "Windows NT x86", @ScriptDir & "\Samsung5010", @ScriptDir & "\Samsung5010\sse2m.inf") ; Add a TCP/IP printer port, called "MyTCPIPPrinterPort", with IPAddress = 192.168.1.10 and Port = 9100 _PrintMgr_AddTCPIPPrinterPort("MyTCPIPPrinterPort", "192.168.1.10", 9100) ; Add a printer, give it the name "My Printer", use the driver called "Samsung ML-451x 501x Series" and the port called "MyTCPIPPrinterPort" _PrintMgr_AddPrinter("My Printer", "Samsung ML-451x 501x Series", "MyTCPIPPrinterPort") ; Set the printer called "My Printer" as default printer _PrintMgr_SetDefaultPrinter("My Printer") ; Connect to the shared printer "\\192.168.1.1\HPDeskjetColor") _PrintMgr_AddWindowsPrinterConnection("\\192.168.1.1\HPDeskjetColor") ; List all installed printers Local $aPrinterList = _PrintMgr_EnumPrinter() _ArrayDisplay($aPrinterList) ; List all printers configuration Local $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration() _ArrayDisplay($aPrinterConfig) ; List all installed printer drivers Local $aDriverList = _PrintMgr_EnumPrinterDriver() _ArrayDisplay($aDriverList) ; Retrieve the printer configuration for the printer called "Lexmark T640" $aPrinterConfig = _PrintMgr_EnumPrinterConfiguration("Lexmark T640") _ArrayDisplay($aPrinterConfig) ; Add a local printer port (for a file output) _PrintMgr_AddLocalPort("c:\temp\output.pcl") ; Remove the local port _PrintMgr_RemoveLocalPort("c:\temp\output.pcl") ; Enum a print job Local $aJobList = _PrintMgr_EnumPrintJobs() _ArrayDisplay($aJobList) EndFunc ;==>_Example Download link : PrintMgr_Example.au3 PrintMgr.au3
    1 point
  2. Here : #RequireAdmin #include <GUIConstants.au3> #include <Array.au3> Global $oHandler = ObjEvent("AutoIt.Error", WMIerror) Main() Func Main() Local $hGUI = GUICreate("Service") Local $idServ = GUICtrlCreateCombo("", 10, 10, 250, 25) Local $idActiv = GUICtrlCreateButton("Start/Stop", 30, 50) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetData($idServ, _ArrayToString(GetList())) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idServ If Not GUICtrlRead($idServ) Then GUICtrlSetData($idActiv, "Start/Stop") GUICtrlSetState($idActiv, $GUI_DISABLE) Else GUICtrlSetData($idActiv, IsStarted(GUICtrlRead($idServ)) ? "Stop" : "Start") GUICtrlSetState($idActiv, $GUI_ENABLE) EndIf Case $idActiv SetState(GUICtrlRead($idServ), GUICtrlRead($idActiv)) If @error Then MsgBox($MB_OK, "Error", "Unable to change state") GUICtrlSetData($idActiv, IsStarted(GUICtrlRead($idServ)) ? "Stop" : "Start") EndSwitch WEnd EndFunc ;==>Main Func GetList() Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oList = $oWMIService.ExecQuery('SELECT name, started FROM Win32_Service') Local $aServ[$oList.count], $i = 0 For $oServ In $oList $aServ[$i] = $oServ.name $i += 1 Next Return $aServ EndFunc ;==>GetList Func IsStarted($sName) Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oService = $oWMIService.Get("Win32_Service.Name='" & $sName & "'") Return $oService.Started EndFunc ;==>IsStarted Func SetState($sName, $sState) Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oService = $oWMIService.Get("Win32_Service.Name='" & $sName & "'") If $sState = "Start" Then $oService.StartService() Else $oService.StopService() EndIf If @error Then Return SetError(1) EndFunc ;==>SetState Func WMIerror($oError) EndFunc
    1 point
  3. replace $TextInput by GUICtrlRead($TextInput) for e.g : #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiButton.au3> #include <Process.au3> #include <MsgBoxConstants.au3> $ServiceControl = GUICreate("Services",240,240,-1,-1,-1,-1) $TextInput = GUICtrlCreateInput("Type name of service",40,40,120,20,-1,-1) $ButtonExit = GUICtrlCreateButton("Exit",120,200,100,24,-1,-1) $ButtonStart = GUICtrlCreateButton("Start",20,150,100,24,-1,-1) $ButtonStop = GUICtrlCreateButton("Stop",120,150,100,24,-1,-1) GUISetState(@SW_SHOW,$ServiceControl) MsgBox(1,"",GUICtrlRead($TextInput)) ; Canary GuiSetState() While 1 $msg=GuiGetMsg() ; $msg = GUI input ;~ If $msg = GUI buttonX then goto function buttonX If $msg=-3 Then Exit If $msg=$ButtonStart Then Start() If $msg=$ButtonStop Then Stop() If $msg=$ButtonExit Then TestExit() Wend Func Start() ;~ $StartService = _RunDos("net start " & $TextInput) MsgBox(1,"start",GUICtrlRead($TextInput)) ; Canary EndFunc Func Stop() ;~ $StartService = _RunDos("net stop " & $TextInput) MsgBox(1,"stop","stop") ; Canary EndFunc Func TestExit() Exit EndFunc ;~ While 1 ;~ Switch GUIGetMsg() ;~ Case $GUI_EVENT_CLOSE ;~ Case $ButtonExit ;~ TestExit() ;~ EndSwitch ;~ WEnd
    1 point
  4. 🙂 of course, but can't say we aren't biased.
    1 point
  5. @hudsonhock Few suggestions. 1- By specifying a timeout on _WinAPI_WaitForSingleObjectEx, you disable the ability to use the HotKeySet (or any other means to stop the script) 2- You could use result of _WinAPI_WaitForSingleObjectEx to determine if an event occurred or not, would make the script more readable. Local $iRes, $hTimer = TimerInit() While TimerDiff($hTimer) < 5 * 60 * 1000 ; 5 mins $iRes = _WinAPI_WaitForSingleObjectEx($hEvent, 0, 1) If $iRes = $WAIT_IO_COMPLETION Then $hTimer = TimerInit() ; $WAIT_IO_COMPLETION = 0xC0 Sleep(100) WEnd ConsoleWrite("No activity for 5 minutes. Exiting..." & @CRLF)
    1 point
  6. Jacov

    Startint 'new Teams'

    After my IT updated Teams to new_Teams , it doesn't have exe file , it is windows application. How can I launch it by AutoIt (without creating shortcut and running it) ?
    1 point
  7. ioa747

    AutoIt Snippets

    RunApp('wordpad') ;this will Launch wordpad ConsoleWrite(" next" & @CRLF) Func RunApp($appName) For $app In ObjCreate('Shell.Application').NameSpace('shell:AppsFolder').Items If $app.Name = $appName Then RunWait('explorer shell:appsFolder\' & $app.Path) ConsoleWrite("$app.Name=" & $app.Name & @CRLF) Next EndFunc ;==>runApp
    1 point
  8. Jon

    Random DoS Attacks

    Hi, some random DoS attacks ongoing at the mo. Server is auto banning, but maybe some outages. Thanks, Jos, for letting me know,
    1 point
×
×
  • Create New...