Jump to content

New to AutoIt - Display data into one MSG box


Go to solution Solved by rsviper,

Recommended Posts

I managed to get this much together but having trouble cleaning up the script to display all the services and tasks into one msg box with status and green check box for running services and red X for failed services. Is that even possible? HELP!  :sweating:

ConsoleWrite(_IsServiceRunning('RSMgmtSrvc') & @CRLF)
ConsoleWrite(_IsServiceRunning('RemovableStorageService') & @CRLF)
ConsoleWrite(_IsServiceRunning('EAFRCliNP') & @CRLF)
ConsoleWrite(_IsServiceRunning('EAFRCliManager') & @CRLF)
 
; Check if a service is running.
Func _IsServiceRunning($sService)
    Local $oShell = ObjCreate('shell.application')
    If @error Then
        Return SetError(1, 0, False)
    EndIf
    Return $oShell.IsServiceRunning($sService)
 
EndFunc   ;==>_IsServiceRunning
 
; Check if Process is running.
$ProcessName1 = "RemovableStorageMgmtService.exe"
If ProcessExists($ProcessName1) Then
MsgBox(0,"Running",$ProcessName1 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName1 & " is not running.")
 
EndIf
$ProcessName2 = "EAFRCliStart.exe"
If ProcessExists($ProcessName2) Then
MsgBox(0,"Running",$ProcessName2 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName2 & " is not running.")
 
EndIf
$ProcessName3 = "RemovableStorageService.exe"
If ProcessExists($ProcessName3) Then
MsgBox(0,"Running",$ProcessName3 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName3 & " is not running.")
 
EndIf
$ProcessName4 = "EACommunicatorSrv.exe"
If ProcessExists($ProcessName4) Then
MsgBox(0,"Running",$ProcessName4 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName4 & " is not running.")
 
EndIf
$ProcessName5 = "EAFRCliManager.exe"
If ProcessExists($ProcessName5) Then
MsgBox(0,"Running",$ProcessName5 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName5 & " is not running.")
 
EndIf
$ProcessName6 = "RSGUIProvider.exe"
If ProcessExists($ProcessName6) Then
MsgBox(0,"Running",$ProcessName6 & " is running.")
Else
MsgBox(0,"Not Running",$ProcessName6 & " is not running.")
 
EndIf
Link to comment
Share on other sites

rsviper,

I would look into creating a GUI with labels, one for your service name and the status can sit next to it.  The Koda form designer can help set the labels up for you.  You can even do fancy things, like set the status font to red or green depending on if it's running or not.  Try it out and if you need help, let me know.

Also check this out - '?do=embed' frameborder='0' data-embedContent>> - It's a great UDF to check on service statuses (is statuses a word?, maybe statusi?, who knows...).

Link to comment
Share on other sites

If you are using SciTE, then Koda can be accessed from the Tools menu.  There are some samples if you click the new button once in Koda.  Press F9 then you'll see some code that you can insert into SciTE.  Watch out though, because it will overwrite code in SciTE if you have some selected before clicking through Tools.

I'll give you a quick sample in a few minutes of what I was talking about before.

Link to comment
Share on other sites

  • Moderators

rsviper, while Koda is great for learning how a GUI is set up, most find themselves moving away from it quickly as they progress in knowledge. Personally, I think the help file is your greatest tool: start with a very simple snippet taken from the GUICreate example: 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $msg

GUICreate("Test", 300, 300)
GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
            Select
                Case $msg = $GUI_EVENT_CLOSE
                    ExitLoop
            EndSelect
    WEnd

GUIDelete()

You can use this as a mini-template for creating your initial GUI. Then, depending on what you would like to add, just look at that option in the help file (GUICtrlCreateButton, GUICtrlCreateCheckBox, GUICtrlCreateInput, etc.)

Also, depending on the amount of data you would like to display, you may just want to check out Melba's ExtMsgBox function. It has some nice additional features:

http://www.autoitscript.com/forum/index.php?showtopic=109096

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

As long as I've been using AutoIT and SciTE and Koda, I am always in Koda designing my forms.  Makes for quick additions/movements and then you can tweak the settings of button locations, etc.. when you import back into SciTE.

Anyways...rsviper, Here's a quick and dirty script for you!

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$YourGUIForm = GUICreate("Processes Running?", 357, 217, -1, -1)
$Label1 = GUICtrlCreateLabel("Removable Storage Mgmt", 14, 49, 148, 17)
$Label2 = GUICtrlCreateLabel("EAFRCliStart", 15, 72, 148, 17)
$Label3 = GUICtrlCreateLabel("Removable Storage", 15, 96, 148, 17)
$Label4 = GUICtrlCreateLabel("EACommunicator", 15, 120, 148, 17)
$Label5 = GUICtrlCreateLabel("EAFRCliManager", 15, 144, 148, 17)
$Label6 = GUICtrlCreateLabel("RSGUIProvider", 17, 166, 148, 17)
; the "hidden" labels, until check if processes exists below
$RemovableStorageMgmt = GUICtrlCreateLabel("", 171, 48, 175, 17)
$EAFRCliStart = GUICtrlCreateLabel("", 171, 72, 175, 17)
$RemovableStorageSVC = GUICtrlCreateLabel("", 171, 96, 175, 17)
$EACommunicator = GUICtrlCreateLabel("", 171, 120, 175, 17)
$EAFRCliManager = GUICtrlCreateLabel("", 171, 144, 175, 17)
$RSGUIProvider = GUICtrlCreateLabel("", 171, 168, 175, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; put your checks for processes here, right after the GUI loads

; Check if Process is running.
$ProcessName1 = "RemovableStorageMgmtService.exe"
If ProcessExists($ProcessName1) Then
    GUICtrlSetData($RemovableStorageMgmt, "running")
    GUICtrlSetColor($RemovableStorageMgmt, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($RemovableStorageMgmt, "not running")
    GUICtrlSetColor($RemovableStorageMgmt, 0xFF0000) ; sets font to red
EndIf

$ProcessName2 = "EAFRCliStart.exe"
If ProcessExists($ProcessName2) Then
    GUICtrlSetData($EAFRCliStart, "running")
    GUICtrlSetColor($EAFRCliStart, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($EAFRCliStart, "not running")
    GUICtrlSetColor($EAFRCliStart, 0xFF0000) ; sets font to red
EndIf

$ProcessName3 = "RemovableStorageService.exe"
If ProcessExists($ProcessName3) Then
    GUICtrlSetData($RemovableStorageSVC, "running")
    GUICtrlSetColor($RemovableStorageSVC, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($RemovableStorageSVC, "not running")
    GUICtrlSetColor($RemovableStorageSVC, 0xFF0000) ; sets font to red
EndIf

$ProcessName4 = "EACommunicatorSrv.exe"
If ProcessExists($ProcessName4) Then
    GUICtrlSetData($EACommunicator, "running")
    GUICtrlSetColor($EACommunicator, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($EACommunicator, "not running")
    GUICtrlSetColor($EACommunicator, 0xFF0000) ; sets font to red
EndIf

$ProcessName5 = "EAFRCliManager.exe"
If ProcessExists($ProcessName5) Then
    GUICtrlSetData($EAFRCliManager, "running")
    GUICtrlSetColor($EAFRCliManager, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($EAFRCliManager, "not running")
    GUICtrlSetColor($EAFRCliManager, 0xFF0000) ; sets font to red
EndIf

$ProcessName6 = "RSGUIProvider.exe"
If ProcessExists($ProcessName6) Then
    GUICtrlSetData($RSGUIProvider, "running")
    GUICtrlSetColor($RSGUIProvider, 0x66CD00) ; sets font to green
Else
    GUICtrlSetData($RSGUIProvider, "not running")
    GUICtrlSetColor($RSGUIProvider, 0xFF0000) ; sets font to red
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Link to comment
Share on other sites

You can add all the services into an array...then do loops.  It will clean up the code and allow dynamic gui re-sizes...adding any number of processes, will expand the gui to the necessary height and create all the labels...I also added a timer to check status every 5 seconds:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

Global Enum $iProcess_1D_RSMS, _
    $iProcess_1D_EAFRCS, _
    $iProcess_1D_RSS, _
    $iProcess_1D_EACS, _
    $iProcess_1D_EAFRCM, _
    $iProcess_1D_RSGUIP, _
    $iProcess_1D_UBound
Global Enum $iProcess_2d_Name, _
    $iProcess_2d_Label, _
    $iProcess_2d_Status, _
    $iProcess_2d_UBound
Global $aProcess[$iProcess_1D_UBound][$iProcess_2d_UBound]

$aProcess[$iProcess_1D_RSMS][$iProcess_2d_Name]     = "RemovableStorageMgmtService.exe"
$aProcess[$iProcess_1D_EAFRCS][$iProcess_2d_Name]   = "EAFRCliStart.exe"
$aProcess[$iProcess_1D_RSS][$iProcess_2d_Name]      = "RemovableStorageService.exe"
$aProcess[$iProcess_1D_EACS][$iProcess_2d_Name]     = "EACommunicatorSrv.exe"
$aProcess[$iProcess_1D_EAFRCM][$iProcess_2d_Name]   = "EAFRCliManager.exe"
$aProcess[$iProcess_1D_RSGUIP][$iProcess_2d_Name]   = "RSGUIProvider.exe"

$iStaticHeight  = 15
$iStaticSpace   = 10

$YourGUIForm = GUICreate("Processes Running?", 300,($iProcess_1D_UBound*$iStaticHeight)+(($iProcess_1D_UBound+1)*$iStaticSpace))

; the "hidden" labels, until check if processes exists below
For $i = 0 To UBound($aProcess)-1
    $aProcess[$i][$iProcess_2d_Label]   = GUICtrlCreateLabel($aProcess[$i][$iProcess_2d_Name],  $iStaticSpace,  ($iStaticSpace*($i+1))+$iStaticHeight*$i)
    $aProcess[$i][$iProcess_2d_Status]  = GUICtrlCreateLabel("",                                200,            ($iStaticSpace*($i+1))+$iStaticHeight*$i, 100, $iStaticHeight)
Next

CheckStatus()

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Func CheckStatus()
    ConsoleWrite("Checking status" & @CRLF)
    ; loop through, get statuses
    For $i = 0 To UBound($aProcess)-1
        If ProcessExists($aProcess[$i][$iProcess_2d_Name]) Then
            GUICtrlSetData($aProcess[$i][$iProcess_2d_Status], "running")
            GUICtrlSetColor($aProcess[$i][$iProcess_2d_Status], 0x66CD00) ; sets font to green
        Else
            GUICtrlSetData($aProcess[$i][$iProcess_2d_Status], "not running")
            GUICtrlSetColor($aProcess[$i][$iProcess_2d_Status], 0xFF0000) ; sets font to red
        EndIf
    Next
EndFunc

$bCheckStatus = True
$iTimer = TimerInit()
$iCheckSeconds = 5000
While 1
    If TimerDiff($iTimer) > $iCheckSeconds Then
        $iTimer = TimerInit()
        CheckStatus()
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I am using this code to view and kill  process remotely now.... trying to use the initial portion for the remote PC

Const $ForReading = 0
Const $ForWriting = 2
Const $ForAppending = 1
 
Global $type = "Process"
Global $pslist = @ComSpec & ' /c "' & @ScriptDir & '\pslist.exe"'
Global $pskill = @ScriptDir & "\pskill.exe"
Dim $pscommand, $psfileread, $pskill, $pslist
Dim $ComputerName, $CheckType, $ProcessCtrl, $ServiceCtrl, $GoButton, $ItemCtrl
$ComputerName = @ComputerName
 
; GUI
GUICreate("Remote Process Manager", 400, 400)
 
; LABEL
GUICtrlCreateLabel("Computer Name :", 5, 8, 48, 40)
 
; INPUT
$CNameInput = GUICtrlCreateInput($ComputerName, 55, 10, 130, 22)
 
; LABEL
GUICtrlCreateLabel("Select type :", 200, 8, 48, 40)
; COMBO
$CheckType = GUICtrlCreateCombo("Process", 250, 10, 120, 100)
GUICtrlSetData(-1, "Service")
 
$ActionInput = GUICtrlCreateCombo("Search For", 5, 45, 120, 100)
GUICtrlSetData(-1, "Kill")
 
$Tinput = GUICtrlCreateInput("", 130, 45, 180, 22)
GUICtrlSetState(-1, $GUI_DROPACCEPTED); to allow drag and dropping
 
; LIST VIEW
$listView = GUICtrlCreateListView("Target|ID|Result", 5, 75, 305, 300)
 
; BUTTON
$GoButton = GUICtrlCreateButton("Go", 340, 340, 40, 30)
 
; GUI MESSAGE LOOP
GUISetState()
While GUIGetMsg() <> $GUI_EVENT_CLOSE
    $Msg = GUIGetMsg()
    
    Select
        Case $Msg = $CheckType
            $type = GUICtrlRead($CheckType)
            Select
                Case $type = "Process"
                    GUICtrlSetData($ItemCtrl, "|Search For|Kill", "Search For")
                Case $type = "Service"
                    GUICtrlSetData($ItemCtrl, "|Search For|Stop|Start|Restart|Delete", "Search For")
            EndSelect
        Case $Msg = $GoButton
            $type = GUICtrlRead($CheckType)
            Select
                Case $type = "Process"
                    ProType()
                Case $type = "Service"
                    SerType()
            EndSelect
            
            
    EndSelect
 
WEnd
 
Func ProType()
    $ComputerName = GUICtrlRead($CNameInput)
    $Action = GUICtrlRead($ActionInput)
    $Target = GUICtrlRead($Tinput)
    $Result = "Process Not Found"
    $PID = "NA"
    $i = 3
    GUICtrlDelete($listView)
; LIST VIEW
    $listView = GUICtrlCreateListView("Target|ID|Result", 5, 75, 305, 300)
    Select
        Case $Action = "Search For"
            $pscommand = $pslist & " \\" & $ComputerName & " " & $Target & " > pslist.txt"
            RunWait($pscommand, "", @SW_HIDE)
            $pslistfile = FileOpen("pslist.txt", $ForReading)
            $psfileread = FileRead($pslistfile)
            $pslistfound = StringInStr($psfileread, "CPU Time")
            If $pslistfound > 0 Then
                $Result = "Process Exists"
                Do
                    $i = $i + 1
                    $line = FileReadLine($pslistfile, $i)
                    If @error = -1 Then ExitLoop
            ;MsgBox(0,"File Line",$line)
                    Do
                        $line = StringReplace($line, "  ", " ")
                    Until @extended = 0
                    
                    $lineitems = StringSplit($line, " ")
                    GUICtrlCreateListViewItem($lineitems[1] & "|" & $lineitems[2] & "|" & $Result, $listView)
                Until @error = -1
            Else
                GUICtrlCreateListViewItem($Target & "|" & $PID & "|" & $Result, $listView)
            EndIf
            
        Case $Action = "Kill"
            $prokill = ShellExecuteWait($pskill, "\\" & $ComputerName & " -t " & $Target, "", "", @SW_HIDE)
            If $prokill = 0 Then
                $Result = "Process killed"
            Else
                $Result = $prokill
            EndIf
            GUICtrlCreateListViewItem($Target & "|" & $PID & "|" & $Result, $listView)
    EndSelect
    
EndFunc ;==>ProType
 
Func SerType()
EndFunc ;==>SerType
Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

rsviper,

When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

rsviper,

Now you're moving on to bigger and better things, good!  Hopefully this is for admin purposes only.   :pirate:  Below is something I found in the forums.  Works a treat too!  (use process name without the .exe)

You'll need to get the 'ServiceControl.au3', putting it in your 'Include' folder, by SumTingWong here -> '?do=embed' frameborder='0' data-embedContent>>.  Then go and get the GUI from GrayWalker here (the one in the last post) -> '?do=embed' frameborder='0' data-embedContent>>

Link to comment
Share on other sites

  • Solution

Working on it.... ty! Yes - I Manage Symantec Endpoint Encryption Console and looking to put a tool together to check remote PCs that do not report into the console now. I am using the standalone option to verify when I am logged on to the PCs, but some users are remote and too busy for me to logon to their PCs.... 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...