Sign in to follow this  
Followers 0
lexus

Read data

45 posts in this topic

Hi,

soory, im new here and beginner...

How do I get the value in a GUICtrlSetData.?

 

I need this (the variable $computer and status) in a textfeld.
    _GUICtrlListView_AddItem($hListview, $aComputer[$i][0], $i)
    _GUICtrlListView_AddSubItem($hListview, $i, $aComputer[$i][1], 1)

 

Thanks and

BR

Lexus

 

 

 

 

Share this post


Link to post
Share on other sites



lexus,

Welcome to the AutoIt forums.  But please do not hijack old threads - particularly when they have very little to do with the question you are asking - just start a new one as I have now done for you.

What exactly are you trying to do? Get a user to input a computer name and status? Read the values from somewhere else? Please help us to help you by giving us some more information as what you have offered so far does not really give us a lot.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Melba,

here the example from user UEZ.

 

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
local $host
$host = "localhost"
;$hGUI =  GUICreate("Test", 220, 460, 120, 200, -1, $WS_EX_ACCEPTFILES)
$hGUI = GUICreate("RDP Broker", 1264, 810, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN, $WS_EX_ACCEPTFILES)
GUICtrlCreateLabel("Select an available PC " & @LF & _
                                "----carriage return" & @LF, 10, 10)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2") ;http://msdn.microsoft.com/en-us/library/aa381344(v=VS.85).aspx
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 230, 20, 1024, 768)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$listview =  GUICtrlCreateListView("PC Name          |Status   ", 10, 40, 200, 380)
$hListview = GUICtrlGetHandle($listview)
$rdp =   GUICtrlCreateButton("Open RDP Session", -1, 430, 100, 20)
GUISetState()
Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")
Global $aComputer[3][2] =[["LocalHost", ""], ["PC44444", ""],["PC66666", ""]] ;2D array whereas 1st entry is the hostname and 2nd entry is for the status
Global $status, $result

For $i = 0 To UBound($aComputer) - 1
    $status = WMI_ProcessExits($aComputer[$i][0], "explorer.exe")
    Switch $status
        Case 0
            $aComputer[$i][1] = "Available"
        Case 1
            $aComputer[$i][1] = "Busy"
        Case Else
            $aComputer[$i][1] = "Unknown"
    EndSwitch
    _GUICtrlListView_AddItem($hListview, $aComputer[$i][0], $i)
    _GUICtrlListView_AddSubItem($hListview, $i, $aComputer[$i][1], 1)
Next
Do
    $msg =   GUIGetMsg()
    Switch $msg
        Case $rdp
            $selection = _GUICtrlListView_GetSelectedIndices($hListview, False)
            $host = _GUICtrlListView_GetItemText($hListview, $selection)
            $status = _GUICtrlListView_GetItemText($hListview, $selection, 1)
            If $status <> "Unknown" And $status <> "Busy" Then
                $oRDP.DesktopWidth = 1024
                $oRDP.DesktopHeight = 768
                $oRDP.Fullscreen = False
                $oRDP.ColorDepth = 16
                $oRDP.AdvancedSettings3.SmartSizing = True
                $oRDP.Server = $host
                $oRDP.UserName = @Username ;<<<<<<< enter here the user name
                $oRDP.Domain = "REBUSHR-UK"
                $oRDP.AdvancedSettings2.ClearTextPassword = ""
                $oRDP.ConnectingText = "Connecting to " & $host
                $oRDP.DisconnectedText = "Disconnected from " & $host
                $oRDP.StartConnected = True
                $oRDP.Connect()
            Else
                MsgBox(48, "Information", $host & " is busy or unknown")
            EndIf
    EndSwitch
Until $msg = $GUI_EVENT_CLOSE
$oRDP.Disconnect()
Exit

Func WMI_ProcessExits($host, $processname, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Or $host = "localhost" Or $host = @IPAddress1 Or $host = @ComputerName Then
        If ProcessExists($processname) Then Return 1
        Return 0
    Else
        Local $ping = Ping($host, 1000)
        If @error Then Return SetError(1, 0, -1) ; Host not pingable
        Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
        Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", "&H80")
        If @error Then Return SetError(3, 0, -1)
        Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Process WHERE Name='" & $processname & "'", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.Name <> "" Then Return 1
            Next
        Else
            Return SetError(4, 0, -1)
        EndIf
        Return 0
    EndIf
EndFunc   ;==>WMI_ProcessExits

Func ObjErrorHandler()
    ConsoleWrite("A COM Error has occured!" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oErrorHandler.description & @CRLF & _
            "err.windescription:" & @TAB & $oErrorHandler & @CRLF & _
            "err.number is: " & @TAB & Hex($oErrorHandler.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oErrorHandler.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oErrorHandler.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oErrorHandler.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oErrorHandler.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oErrorHandler.helpcontext & @CRLF _
            )
EndFunc   ;==>ObjErrorHandler

i will $computer and the status in a input textbox / GUICtrlSetData  in the same script

how i can the output display in the textbox ?

for one computer = one textbox,  for two computer = two textboxs

Edited by lexus

Share this post


Link to post
Share on other sites

lexus,

My best guess at what you mean:

_GUICtrlListView_AddItem($hListview, $aComputer[$i][0], $i)
    _GUICtrlListView_AddSubItem($hListview, $i, $aComputer[$i][1], 1)

    MsgBox($MB_SYSTEMMODAL, "Computer " & $i + 1, $aComputer[$i][0] & @CRLF & $aComputer[$i][1])

Next

That will display a MsgBox for each computer in the array.   If that is not what you want, then please explain in more detail.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hi Melba23,

Sorry for my bad english.is almost correct :-)

I do not want a MsgBox popup. I want the status in a textbox /input.

When i open the gui, i want see the status from computers without click the button.

Thank you.....

 

BR

Lexus

 

 

 

 

sample.jpg

Share this post


Link to post
Share on other sites

No one can help me ? 

Share this post


Link to post
Share on other sites

lexus,

I have shown you above how to extract the required data from the $aComputer array. Just use GUICtrlSetData to place it in the GUI controls instead of the MsgBox.

I see you have designed the GUI - have you tried to write some code to get the data into it? Give it a go and see how you get on - you know where we are if you run into problems.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hi,

this here is the final code. I think there is still something missing.

I've forgotten ?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ColorConstantS.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>




#Region ### START Koda GUI section ### Form=\\retde147-nt0001\axus$\desktop\ping\form3.kxf
$Form1_1_1 = GUICreate("Form1", 701, 298, 214, 91, BitOR($WS_MINIMIZEBOX,$WS_POPUP,$WS_GROUP))
$Label1 = GUICtrlCreateLabel("computer1", 15, 40, 73, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Label12 = GUICtrlCreateLabel("computer2", 15, 80, 67, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Label2 = GUICtrlCreateLabel("computer3", 15, 120, 108, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Label3 = GUICtrlCreateLabel("computer4", 15, 160, 74, 26)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
$Status_computer1 = GUICtrlCreateInput("Status", 136, 40, 150, 21)
$Statu_computer2 = GUICtrlCreateInput("Status", 136, 82, 150, 21)
$Input3_computer3 = GUICtrlCreateInput("Status", 136, 124, 150, 21)
$Input4_computer4 = GUICtrlCreateInput("Status", 136, 159, 150, 21)
$btn_computer1 = GUICtrlCreateButton("Stop and Start Process", 387, 40, 147, 25)
$btn_computer2 = GUICtrlCreateButton("Stop and Start Process", 387, 80, 147, 25)
$btn_computer3 = GUICtrlCreateButton("Stop and Start Process", 387, 120, 147, 25)
$btn_computer4 = GUICtrlCreateButton("Stop and Start Process", 387, 160, 147, 25)
$btn_reboot_computer1 = GUICtrlCreateButton("Reboot", 582, 40, 100, 25)
$btn_reboot_computer2 = GUICtrlCreateButton("Reboot", 582, 80, 100, 25)
$btn_reboot_computer3 = GUICtrlCreateButton("Reboot", 582, 120, 100, 25)
$btn_reboot_computer4 = GUICtrlCreateButton("Reboot", 582, 160, 100, 25)
$btn_close = GUICtrlCreateButton("Close", 496, 224, 97, 17)
GUICtrlSetBkColor(-1, 0xFF9933)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")
Global $aComputer[1][2] =[["Computer1", ""]] ;2D array whereas 1st entry is the hostname and 2nd entry is for the status
Global $status, $result








For $i = 0 To UBound($aComputer) - 1
    $status = WMI_ProcessExits($aComputer[$i][0], "calc.exe")
    Switch $status
        Case 0
            $aComputer[$i][1] = "Online"
        Case 1
            $aComputer[$i][1] = "Process run"
        Case Else
            $aComputer[$i][1] = "Offline"
         EndSwitch

    _GUICtrlListView_AddItem($hListview,$aComputer[$i][0], $i)
    _GUICtrlListView_AddSubItem($hListview,$i,$aComputer[$i][1], 1)

  GUICtrlSetData ($MB_SYSTEMMODAL, "Computer " & $i + 1, $aComputer[$i][0] & @CRLF & $aComputer[$i][1])



 Next





Func WMI_ProcessExits($host, $processname, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Or $host = "localhost" Or $host = @IPAddress1 Or $host = @ComputerName Then
        If ProcessExists($processname) Then Return 1
        Return 0
    Else
        Local $ping = Ping($host, 1000)
        If @error Then Return SetError(1, 0, -1) ; Host not pingable
        Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
        Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", "&H80")
        If @error Then Return SetError(3, 0, -1)
        Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Process WHERE Name='" & $processname & "'", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.Name <> "" Then Return 1
            Next
        Else
            Return SetError(4, 0, -1)
        EndIf
        Return 0
    EndIf
EndFunc   ;==>WMI_ProcessExits



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


         Case $btn_computer1
                RunWait ("c:\windows\pstools\pskill  \\.... -u .... -p ..... POWERPNT.exe -accepteula")

            Sleep(5000)
               RunWait('c:\windows\pstools\psexec.exe  \\..... -u ...... -p ......-i 1 -high "......." ')

         Case  $btn_reboot_computer1
                RunWait  ("c:\windows\pstools\psshutdown.exe  \\..... -u ......7 -p ....... -f -r -t 3 -accepteula")


         Case $btn_computer2
                RunWait ("c:\windows\pstools\pskill  \\.... -u .... -p ..... POWERPNT.exe -accepteula")

            Sleep(5000)
                 RunWait('c:\windows\pstools\psexec.exe  \\..... -u ...... -p ......-i 1 -high "......." ')

         Case  $btn_reboot_computer2
                RunWait  ("c:\windows\pstools\psshutdown.exe  \\..... -u ......7 -p ....... -f -r -t 3 -accepteula")


         Case $btn_computer3
               RunWait ("c:\windows\pstools\pskill  \\.... -u .... -p ..... POWERPNT.exe -accepteula")

            Sleep(5000)
              RunWait('c:\windows\pstools\psexec.exe  \\..... -u ...... -p ......-i 1 -high "......." ')

         Case  $btn_reboot_computer3
                RunWait  ("c:\windows\pstools\psshutdown.exe  \\..... -u ......7 -p ....... -f -r -t 3 -accepteula")


         Case $btn_computer4
               RunWait ("c:\windows\pstools\pskill  \\.... -u .... -p ..... POWERPNT.exe -accepteula")

            Sleep(5000)
                RunWait('c:\windows\pstools\psexec.exe  \\..... -u ...... -p ......-i 1 -high "......." ')

         Case  $btn_reboot_computer4
               RunWait  ("c:\windows\pstools\psshutdown.exe  \\..... -u ......7 -p ....... -f -r -t 3 -accepteula")




         Case $Form1_1_1
        Case $Label1
        Case $Label2


         Case $btn_close
              $GUI_EVENT_CLOSE
         Exit


    EndSwitch

WEnd

 

Share this post


Link to post
Share on other sites

lexus,

Much easier if you use arrays to hold the various ControlIDs:

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

Global $aInput[5], $aStop_Start[5], $aReboot[5]
; 2D array whereas 1st entry is the hostname and 2nd entry is for the status
Global $aComputer[4][2] = [["Computer1", ""], ["Computer2", ""], ["Computer3", ""], ["Computer4", ""]]
Global $status, $result
Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")

$Form1_1_1 = GUICreate("Form1", 701, 298, 214, 91, $WS_POPUP)

For $i = 1 To 4
    GUICtrlCreateLabel($aComputer[$i - 1][0], 15, (40 * $i), 100, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $aInput[$i] = GUICtrlCreateInput("Status", 136, (40 * $i), 150, 21)
    $aStop_Start[$i] = GUICtrlCreateButton("Stop and Start Process", 387, (40 * $i), 147, 25)
    $aReboot[$i] = GUICtrlCreateButton("Reboot", 582, (40 * $i), 100, 25)
Next
$btn_close = GUICtrlCreateButton("Close", 496, 224, 97, 17)
GUICtrlSetBkColor(-1, 0xFF9933)

GUISetState(@SW_SHOW)

SplashTextOn("Initialising", "Please be patient.....")

For $i = 0 To UBound($aComputer) - 1
    $status = WMI_ProcessExists($aComputer[$i][0], "calc.exe")
    Switch $status
        Case 0
            $aComputer[$i][1] = "Online"
        Case 1
            $aComputer[$i][1] = "Process run"
        Case Else
            $aComputer[$i][1] = "Offline"
    EndSwitch
    ; Set status into input
    GUICtrlSetData($aInput[$i + 1], $aComputer[$i][1])

Next

SplashOff()

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $btn_close
            Exit
        Case Else
            For $i = 1 To 4
                If $iMsg = $aStop_Start[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Stop/Start " & $i)
                    ExitLoop
                EndIf
            Next
            For $i = 1 To 4
                If $iMsg = $aReboot[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Reboot " & $i)
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

Func WMI_ProcessExists($host, $processname, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Or $host = "localhost" Or $host = @IPAddress1 Or $host = @ComputerName Then
        If ProcessExists($processname) Then Return 1
        Return 0
    Else
        Local $ping = Ping($host, 1000)
        If @error Then Return SetError(1, 0, -1) ; Host not pingable
        Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
        Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", "&H80")
        If @error Then Return SetError(3, 0, -1)
        Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Process WHERE Name='" & $processname & "'", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.Name <> "" Then Return 1
            Next
        Else
            Return SetError(4, 0, -1)
        EndIf
        Return 0
    EndIf
EndFunc   ;==>WMI_ProcessExists

Please ask if you have any questions.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

wow .... am thrilled  :thumbsup:

respect, this code is very smaller.

it is possible the process is displayed in real time? loop with a while?

Thanks for the good job...

Edited by lexus

Share this post


Link to post
Share on other sites

lexus,

Quote

it is possible the process is displayed in real time? loop with a while?

Of course - and you have suggested exactly what is required. So back to you to see if you can code it.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

can i a make two loops ?

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

Global $aInput[5], $aStop_Start[5], $aReboot[5]
; 2D array whereas 1st entry is the hostname and 2nd entry is for the status
Global $aComputer[4][2] = [["Computer1", ""], ["Computer2", ""], ["Computer3", ""], ["Computer4", ""]]
Global $status, $result
Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")

$Form1_1_1 = GUICreate("Form1", 701, 298, 214, 91, $WS_POPUP)

For $i = 1 To 4
    GUICtrlCreateLabel($aComputer[$i - 1][0], 15, (40 * $i), 100, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $aInput[$i] = GUICtrlCreateInput("Status", 136, (40 * $i), 150, 21)
    $aStop_Start[$i] = GUICtrlCreateButton("Stop and Start Process", 387, (40 * $i), 147, 25)
    $aReboot[$i] = GUICtrlCreateButton("Reboot", 582, (40 * $i), 100, 25)
 Next
 
 While 1
$btn_close = GUICtrlCreateButton("Close", 496, 224, 97, 17)
GUICtrlSetBkColor(-1, 0xFF9933)

GUISetState(@SW_SHOW)

SplashTextOn("Initialising", "Please be patient.....", 0, 0, 0, 0)

For $i = 0 To UBound($aComputer) - 1
    $status = WMI_ProcessExists($aComputer[$i][0], "calc.exe")
    Switch $status
        Case 0
            $aComputer[$i][1] = "Online"
        Case 1
            $aComputer[$i][1] = "Process run"
        Case Else
            $aComputer[$i][1] = "Offline"
    EndSwitch
    ; Set status into input
    GUICtrlSetData($aInput[$i + 1], $aComputer[$i][1])

Next

SplashOff()
WEnd

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $btn_close
            Exit
        Case Else
            For $i = 1 To 4
                If $iMsg = $aStop_Start[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Stop/Start " & $i)
                    ExitLoop
                EndIf
            Next
            For $i = 1 To 4
                If $iMsg = $aReboot[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Reboot " & $i)
                    ExitLoop
                EndIf
            Next
    EndSwitch



Func WMI_ProcessExists($host, $processname, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Or $host = "localhost" Or $host = @IPAddress1 Or $host = @ComputerName Then
        If ProcessExists($processname) Then Return 1
        Return 0
    Else
        Local $ping = Ping($host, 1000)
        If @error Then Return SetError(1, 0, -1) ; Host not pingable
        Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
        Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", "&H80")
        If @error Then Return SetError(3, 0, -1)
        Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Process WHERE Name='" & $processname & "'", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.Name <> "" Then Return 1
            Next
        Else
            Return SetError(4, 0, -1)
        EndIf
        Return 0
    EndIf
EndFunc   ;==>WMI_ProcessExists

now is the process in realtime but the buttons doesent work.

and where I now copy my psexec code for the command ?

Edited by lexus

Share this post


Link to post
Share on other sites

lexus,

You need to think through the logic flow of how you want the script to work a little more. This example initialises the 4 computers and then updates them in turn every 5 secs:

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

Global $aInput[5], $aStop_Start[5], $aReboot[5]
; 2D array whereas 1st entry is the hostname and 2nd entry is for the status
Global $aComputer[4][2] = [["Computer1", ""], ["Computer2", ""], ["Computer3", ""], ["Computer4", ""]]
Global $status, $result
Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")

$Form1_1_1 = GUICreate("Form1", 701, 298, 214, 91, $WS_POPUP)

For $i = 1 To 4
    GUICtrlCreateLabel($aComputer[$i - 1][0], 15, (40 * $i), 100, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $aInput[$i] = GUICtrlCreateInput("Status", 136, (40 * $i), 150, 21)
    $aStop_Start[$i] = GUICtrlCreateButton("Stop and Start Process", 387, (40 * $i), 147, 25)
    $aReboot[$i] = GUICtrlCreateButton("Reboot", 582, (40 * $i), 100, 25)
Next

$cUpdating = GUICtrlCreateLabel("", 136, 224, 97, 25)

$btn_close = GUICtrlCreateButton("Close", 496, 224, 97, 17)
GUICtrlSetBkColor(-1, 0xFF9933)

GUISetState(@SW_SHOW)

; Initialise all the status inputs
SplashTextOn("Initialising", "Please be patient.....")

For $i = 0 To UBound($aComputer) - 1
    _Update($i)
Next

SplashOff()

; Set an index for the status checks
$iIndex = 0
; Set a timestamp
$nBegin = TimerInit()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE, $btn_close
            Exit
        Case Else
            For $i = 1 To 4
                If $iMsg = $aStop_Start[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Stop/Start " & $i)
                    ExitLoop
                EndIf
            Next
            For $i = 1 To 4
                If $iMsg = $aReboot[$i] Then
                    MsgBox($MB_SYSTEMMODAL, "Hi", "You pressed Reboot " & $i)
                    ExitLoop
                EndIf
            Next
    EndSwitch

    ; Every 5 secs
    If TimerDiff($nBegin) > 5000 Then
        ; Disable GUI & display label
        GUICtrlSetData($cUpdating, "Updating")
        GUISetState(@SW_DISABLE, $Form1_1_1)
        ; Check a computer
        _Update($iIndex)
        ; Set the index for the next check
        $iIndex += 1
        If $iIndex = 4 Then $iIndex = 0
        ; Reset the timestamp
        $nBegin = TimerInit()
        ; Re-enable GUI & clear label
        GUISetState(@SW_ENABLE, $Form1_1_1)
        GUICtrlSetData($cUpdating, "")
    EndIf

WEnd

Func _Update($iIndex)

    $status = WMI_ProcessExists($aComputer[$iIndex][0], "calc.exe")
    Switch $status
        Case 0
            $aComputer[$iIndex][1] = "Online"
        Case 1
            $aComputer[$iIndex][1] = "Process run"
        Case Else
            $aComputer[$iIndex][1] = "Offline"
    EndSwitch
    ; Set status into input
    GUICtrlSetData($aInput[$iIndex + 1], $aComputer[$iIndex][1])

EndFunc

Func WMI_ProcessExists($host, $processname, $usr = "", $pass = "") ;coded by UEZ 2011
    If $host = "." Or $host = "localhost" Or $host = @IPAddress1 Or $host = @ComputerName Then
        If ProcessExists($processname) Then Return 1
        Return 0
    Else
        Local $ping = Ping($host, 1000)
        If @error Then Return SetError(1, 0, -1) ; Host not pingable
        Local $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
        Local $objWMIService = $objWMILocator.ConnectServer($host, "\root\cimv2", $usr, $pass, "", "", "&H80")
        If @error Then Return SetError(3, 0, -1)
        Local $colItems = $objWMIService.ExecQuery("SELECT Name FROM Win32_Process WHERE Name='" & $processname & "'", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                If $objItem.Name <> "" Then Return 1
            Next
        Else
            Return SetError(4, 0, -1)
        EndIf
        Return 0
    EndIf
EndFunc   ;==>WMI_ProcessExists

You place the psexec code where I have the MsgBox lines - all you need to do is pass the correct parameters to the command depending on the value of $i.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

90% completed..,...  :thumbsup:

but I can not put $ i in psexec code ?

for 12 pc  can i write 12x the code with computer1 , computer2 ...... computer12

For $i = 1 To 12
                If $iMsg = $aReboot[$i] Then
                     RunWait  ("c:\windows\pstools\psshutdown.exe  \\computer1 -u user -p password -f -r -t 3 -accepteula")
                    ExitLoop
                EndIf


               

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Try this:

RunWait  ("c:\windows\pstools\psshutdown.exe  \\computer" & $i & " -u user -p password -f -r -t 3 -accepteula")

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Hi UEZ,

its doesent work.

the computername in our company is

Global $aComputer[12][2] = [[" it1429-wcom1", ""], [["  it1429-wcom2", ""],[["  it1429-wcom3", ""]].......

i have tested

 

If $iMsg = $aStop_Start[$i] Then
                     RunWait ("c:\windows\pstools\pskill  \\" & $i & "  -u user  -p password POWERPNT.exe -accepteula")

            Sleep(5000)
               RunWait('c:\windows\pstools\psexec.exe  \\" & $i & "  -u user -p password -i 1 -high "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Eingang.bat" ')
                    ExitLoop
                EndIf
             Next

 but this message come in psexec comand

Unbenannt.jpg

Edited by lexus

Share this post


Link to post
Share on other sites

That makes no sense.

Give this a try:

RunWait  ("c:\windows\pstools\psshutdown.exe  \\" & $aComputer[$i][0] & " -u user -p password -f -r -t 3 -accepteula")

 

Don't use white space within computer names as it was done in your array -> e.g. " it1429-wcom1". Must be "it1429-wcom1".


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

yesterday was late :-)

it works. $aComputer = workstations in our company.

but when i click the first button (for computer1 ), run the script for computer2.  click the secont button (for computer2 ), run the script for computer3.

Global $aComputer[4][2] = [["computer1", ""], ["computer2", ""], ["computer3", ""], ["computer4", ""]]


For $i = 1 To 4
                If $iMsg = $aStop_Start[$i] Then
                     RunWait ("c:\windows\pstools\pskill  \\" & $aComputer[$i][0] & "  -u user -p password POWERPNT.exe -accepteula")
                    ExitLoop
                EndIf
            Next

 

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

lexus,

That is because the array holding the computer data is 0-based, while the index in the loop is 1-based. So you need to convert the index like this:

$aComputer[$i - 1][0]

M23

Edited by Melba23
Typo

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hi Melba23,

but it is  $aComputer[$i - 1][0]


 

For $i = 1 To 4
    GUICtrlCreateLabel($aComputer[$i - 1][0], 15, (40 * $i), 100, 26)
    GUICtrlSetFont(-1, 14, 400, 0, "Arial")
    $aInput[$i] = GUICtrlCreateInput("Status", 136, (40 * $i), 150, 21)
    $aStop_Start[$i] = GUICtrlCreateButton("Stop and Start Process", 387, (40 * $i), 147, 25)
    $aReboot[$i] = GUICtrlCreateButton("Reboot", 582, (40 * $i), 100, 25)
Next

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0