Sign in to follow this  
Followers 0
Tsiyoshi

Checking if PowerPoint process is working on a remote computer

13 posts in this topic

Hi,

I'm writing a script that will check if PowerPoint process is running on a remote computer.

I know how ro check it locally, Any idea how to check on a remote computer ?

Thanks!

Share this post


Link to post
Share on other sites



You could use pslist from sysinternals.Link


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Another way!

#Include <Array.au3>

dim $process [1]

$wbemFlagReturnImmediately = 0x10
$wbemFlagForwardOnly = 0x20
$processtocheck = "powerpnt.exe"
$colItems = ""
$RemoteComputer = "computername"

$Output=""
$objWMIService = ObjGet("winmgmts:\\" & $RemoteComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_Process", "WQL", _
                                        $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) then
   For $objItem In $colItems
    $Output &= $objItem.Name ;& @CRLF
      _ArrayAdd($process, $Output)
      $Output=""
   Next
Else
   Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_Process" )
Endif

$result = _ArraySearch($process, $processtocheck)
if $result >= 0 then ConsoleWrite ("POWERPOINT IS RUNNING " & @CRLF)
if $result < 0 then ConsoleWrite ("POWERPOINT NOT RUNNING" & @CRLF)

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this

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
    EndIf
    Return 0
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

Replace "." with the remote host name.

Br,

UEZ

Edited by UEZ
1 person likes this

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

Hi UEZ,

I am hoping you can help me adjust your script above to set a variable rather than display a message box but honestly i am a beginner and make my scripts by using pieces of others and adding them together and adjusting the bits i do understand.

I am working with the explorer process and basically want if the explorer process exists on a remote PC a return code of 1 is set which inturn writes a variable of that PC being busy:

Here is how i am trying to adjust it if it makes sense to you:

$PC1 = PC55555

MsgBox(0, "Test", WMI_ProcessExits($PC1, "explorer.exe"))

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

Somwhere here i then want to be able to say something like:

If Return = 1

$PC1 = "Busy"

Set a flag in a GUI to say busy

EndIf

If Return = 0

$PC1 = "Available"

Set flag in a GUI to say available

EndIF

Then i would amend the script to run this function against for example 3 machines and populate a GUI with something like:

PC Name Status

PC1 Busy

PC2 Available

PC3 Available

Then i would have a button to launch an embedded RDP session to a random pick of the available machines.

So the problem i am having is seeing how i can use the output from your If ProcessExists statement cause i am not sure how to manipulate the Return values without breaking the lower part that has the error handling and the other bits its doing.

Thank you

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Something like that?

Global $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")
Global $aComputer[3][2] =[["PC55555", ""], ["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
    $result &= $aComputer[$i][0] & @TAB & $aComputer[$i][1]  & @LF
Next

MsgBox(0, "Test", "PC Name" & @TAB & "Status" & @LF & _
                                "===============" & @LF & $result)

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

Br,

UEZ

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

Hi UEZ,

Blimey! Yes it does output like i want with the correct information however now it is so complex i have no idea what it is doing and i cant amend it at all without breaking it. I cant even figure out how to add a 4th PC!

Because the $result string displays multiple information i dont know how to re-write that into a clickable list :-(

Here is a piece of a script i use to map a load of drives and wanted to adapt that to this to come up with some form of GUI.

---------------------------------------------------------------------------------------------- (Having an awful time with this website so cant post this nicely.)

Managers()
Func Managers()
$hGUI =  GUICreate("Map Drives", 220, 460, 120, 200, -1, $WS_EX_ACCEPTFILES)
  GUICtrlCreateLabel("Select the users primary site", 10, 10)
$listview =  GUICtrlCreateListView("Site Code   |Site", 10, 40, 200, 380)
$map =   GUICtrlCreateButton("Map Drives Now", -1, 430, 100, 20)
; Below is what i was hoping to use the $result for populating the GUI
$item1 =  GUICtrlCreateListViewItem("BIRM-PAR|Birmingham", $listview)
$item2 =  GUICtrlCreateListViewItem("BRIS-AZT|Bristol Aztec West", $listview)
$item3 =  GUICtrlCreateListViewItem("BRIS-WST|Bristol Wine Street", $listview)
; This goes on for quite a while
  GUICtrlSetState(-1, $GUI_DROPACCEPTED)
      GUISetState()
  Do
$msg =   GUIGetMsg()
        If $msg = $map Then
           $iSelect = ControlListView($hGUI, "", $listview, "GetSelected")
         ConsoleWrite("Debug:  $iSelect = " & $iSelect & @LF)
        If $iSelect <> "" Then
           $sSelect = ControlListView($hGUI, "", $listview, "GetText", $iSelect, 0)
    $dSelect = $sSelect & "\"
    $fSelect = @Username & ".userdomain"

DriveMapAdd("P:", "\\fileserver\secureshare\Data", 1)

; More drives get mapped
      Until $msg = $GUI_EVENT_CLOSE
EndFunc

Thank you

P.S. You are the oracle!

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Try this here then:

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

$hGUI =  GUICreate("Test", 220, 460, 120, 200, -1, $WS_EX_ACCEPTFILES)
GUICtrlCreateLabel("PC Status", 10, 10)
$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], "explorer1.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" Then Run("mstsc /v:" & $host)
    EndSwitch
Until $msg = $GUI_EVENT_CLOSE

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

Br,

UEZ

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

Hi UEZ,

Yes that is more like what i was trying to achieve, however see below with how i am trying to merge 2 scripts:

#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)
$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()
$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], "explorer1.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)
            If $aComputer[$selection][1] <> "Unknown" Then Run("mstsc /v:" & $aComputer[$selection][0])
    EndSwitch
Until $msg = $GUI_EVENT_CLOSE
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

So what i need to do here is get the button to set the host and then the embedded RDP session to launch in the GUI. Its almost there but not quite yet! If you launch the above you will see i am pretty close getting everything aligned in the GUI.

All i need to be able to do is when you press connect it connects to the highlighted "available" PC and either doesnt let you select to an "unknown" or "busy" PC or just passes a message (message box is fine) to the user to select an available PC instead - All within the window.

Thanks a lot for all your help UEZ, you really should start doing classes in this - i would be more than willing to attend ;-)

Thank you

Here is the original embed RDP object script that i am using with a small modification to allow me to specify the host using an input box: (going forward logged on username and password would be used as opposed to input boxes)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIListView.au3>
$passwd = InputBox("Security Check", "Enter your userdomain password...", "", "*", 190, 135)
  If @error = 1 Then MsgBox(16, "ERROR", "The cancel button was pushed") Then Exit
$host = InputBox("Where?", "What shall we connect to?", "", "", 210, 135) ;<<<<<<< enter here the host name or ip address
  If @error = 1 Then MsgBox(16, "ERROR", "The cancel button was pushed") Then Exit
;Remote Desktop ActiveX Control Interfaces -> http://msdn.microsoft.com/en-us/library/aa383022(v=VS.85).aspx
$hGUI = GUICreate("RDP Broker", 1285, 810, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN)
$oRDP = ObjCreate("MsTscAx.MsTscAx.2") ;http://msdn.microsoft.com/en-us/library/aa381344(v=VS.85).aspx
$oRDP_Ctrl = GUICtrlCreateObj($oRDP, 30, 20, 1024, 768)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetStyle($oRDP_Ctrl , $WS_VISIBLE)
$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 = "userdomain"
$oRDP.AdvancedSettings2.ClearTextPassword = $passwd
$oRDP.ConnectingText = "Connecting to " & $host
$oRDP.DisconnectedText = "Disconnected from " & $host
$oRDP.StartConnected = True
$oRDP.Connect()

GUISetState(@SW_SHOW, $hGUI)
;~ ConsoleWrite($oRDP.GetErrorDescription() & @CRLF)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            $oRDP.Disconnect()
            Exit
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Next try:

#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

Btw, the RDP code looks familiar to me :graduated:

Br,

UEZ

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

Thanks UEZ, that is exactly how i wanted it however i just need to make it look a bit more appealing but hopefully i can sort this out.

Can you just help me with 2 more bits of info.

How do i add another computer to check? I am unsure how many but it doesnt seem as simple as just adding another bracket filled piece of text, see below (I dont understand all the brackets inside brackets):

Global $aComputer[3][2] =[["LocalHost", ""], ["PC44444", ""],["PC66666", ""], ["PC77777", ""]]

More importantly if i re-size the window the RDP session becomes unresponsive is there a way to make it resize with the GUI window or can we fix the GUI window if thats not possible?

Thanks alot

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

The first number is the count of rows, the second is number of the columns, so if you want to add another row, just increase 3-->4

Global $aComputer[4][2] = [["LocalHost", ""],["PC44444", ""],["PC66666", ""],["PC77777", ""]]
_Array2dDisplay2($aComputer)

Func _Array2dDisplay2(ByRef $ar_Array, $s_Title = "Array contents", $n_Index = 0)
    ;-------------------------------------
    ; Display 2 dimensional array
    Local $output = ""
    Local $r = 0, $c = 0
    If Not IsArray($ar_Array) Then Return -1
    For $r = $n_Index To UBound($ar_Array, 1) - 1
        $output &= @LF
        For $c = 0 To UBound($ar_Array, 2) - 1
            $output &= "|" & $ar_Array[$r][$c]
        Next
    Next
    MsgBox(4096, $s_Title, $output)
    Return
EndFunc   ;==>_Array2dDisplay2
Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thanks alot Xeno that now makes i wouldnt say perfect sense but at least i can see and understand what its doing.

Now i just need a bit of help with the embedded rdp session re-sizing issue then i can go about making it look a bit nicer.

Thank you

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