Jump to content
Sign in to follow this  
Modugno

Working with services on a remote computer

Recommended Posts

I am just getting back into using autoit(might as well call me a newb). I am trying to create a gui that will check the status of a remote service. I also want to be able to start and stop them. I have found many exmples and they all work well. The only problem is that the remote systems are not a member of any domain and I would never be logged in with a user account that would have admin rights on the remote box. My question is how do I pass alternative credentials to the remote system. Thanks so much for any help

Here is the code that works great if I have admin permissions - this is just a simple test, but if i can get this working I can finish my project - thanks again

#include <_NTServices.au3>

$result = _ServiceStatus("acproxy", "ip address")

MsgBox(1,"test","acproxy is " & $result)

$result = _ServiceStatus("spooler", "ip address")

MsgBox(1,"test","spooler is " & $result)

_ServiceStart("spooler","ip address")

$result = _ServiceStatus("spooler", "ip address")

MsgBox(1,"test","spooler is " & $result)

Share this post


Link to post
Share on other sites

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <TabConstants.au3>

#include <WindowsConstants.au3>

#include <_NTServices.au3>

#include <Services2.au3>

#include <GuiTab.au3>

#Region ### START Koda GUI section ### Form=

DirCreate("c:\_software\files")

FileInstall("Logo2.jpg","c:\_software\Files\",1)

FileInstall("turbine.bmp","c:\_software\Files\",1)

$Form1 = GUICreate("Vestas SCADA Tools", 615, 448, 192, 124)

$Tab1 = GUICtrlCreateTab(20, 8, 577, 417)

$TabSheet1 = GUICtrlCreateTabItem("Information")

_GUICtrlTab_SetBkColor($Form1, $Tab1, 0xFFFFFF)

$Pic2 = GUICtrlCreatePic("c:\_software\files\logo2.jpg", 32, 40, 193, 49)

$Pic5 = GUICtrlCreatePic("c:\_software\files\turbine.bmp", 72, 88, 468, 332)

$TabSheet2 = GUICtrlCreateTabItem("Services")

$Label2 = GUICtrlCreateLabel("Please Select Service", 40, 153, 108, 17)

$Label1 = GUICtrlCreateLabel("Please Enter The IP Address", 40, 114, 140, 17)

$Group1 = GUICtrlCreateGroup("Status", 360, 104, 217, 81)

$Input1 = GUICtrlCreateInput("", 408, 136, 121, 21)

GUICtrlSetColor(-1, 0xFFFFFF)

GUICtrlCreateGroup("", -99, -99, 1, 1)

$Pic1 = GUICtrlCreatePic("c:\_software\files\logo2.jpg", 32, 40, 193, 49)

$inpIPAddress = GUICtrlCreateInput("", 208, 112, 130, 21)

$Combo1 = GUICtrlCreateCombo("", 208, 153, 130, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))

GUICtrlSetData(-1, "Spooler|ACproxy|Test")

$Button1 = GUICtrlCreateButton("Status", 40, 333, 75, 25)

$Button2 = GUICtrlCreateButton("Stop", 192, 333, 75, 25)

$Button3 = GUICtrlCreateButton("Start", 352, 333, 75, 25)

$Button4 = GUICtrlCreateButton("Exit", 496, 333, 75, 25)

$Label3 = GUICtrlCreateLabel("Please make sure you have created a ticket before you stop or start any server service. You must also notify the", 40, 223, 533, 17)

$Label4 = GUICtrlCreateLabel("site before you proceed. If the service you plan on restarting is ACproxy, please check with site to make sure that", 40, 253, 537, 17)

$Label5 = GUICtrlCreateLabel("no users are able to login. If some users can the issue might be isolated to the callers laptop.", 40, 283, 439, 17)

$Progress1 = GUICtrlCreateProgress(38, 376, 531, 17)

$TabSheet3 = GUICtrlCreateTabItem("TabSheet3")

$Pic3 = GUICtrlCreatePic("c:\_software\files\logo2.jpg", 32, 40, 193, 49)

$TabSheet4 = GUICtrlCreateTabItem("TabSheet4")

$Pic4 = GUICtrlCreatePic("c:\_software\files\logo2.jpg", 32, 40, 193, 49)

GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

;set state of lables - reset to hide at each case

Func _GUICtrlTab_SetBkColor($hWnd, $hSysTab32, $sBkColor)

Local $aTabPos = ControlGetPos($hWnd, "", $hSysTab32)

Local $aTab_Rect = _GUICtrlTab_GetItemRect($hSysTab32, -1)

GUICtrlCreateLabel("", $aTabPos[0]+2, $aTabPos[1]+$aTab_Rect[3]+4, $aTabPos[2]-6, $aTabPos[3]-$aTab_Rect[3]-7)

GUICtrlSetBkColor(-1, $sBkColor)

GUICtrlSetState(-1, $GUI_DISABLE)

EndFunc

While 1

$nMsg = GUIGetMsg()

Select

;Show status of service

Case $nMsg = $Button1

$Service = ""

$IPAddress = ""

$inc = 0

$result = ""

GUICtrlSetData($Progress1, "0")

GUICtrlSetBkColor($input1, 0xFFFFFF)

GUICtrlSetData($input1,"")

$IPAddress = GUICtrlRead($inpIPAddress)

$Service = GUICtrlRead($Combo1)

If $IPAddress = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Enter Remote Computer IP Address")

ElseIf $Service = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Select Service From Drop Down")

Else

GUICtrlSetData($Progress1, "10")

GUICtrlSetData($Progress1, "20")

$result = _Service_GetState($Service, $IPAddress)

;$result = _ServiceStatus("thislskjf", $IPAddress)

If $result = "Stopped" Then

$i = 0

Do

GUICtrlSetData($input1,"Service Is Stopped")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

$inc = $inc + 33

$i = $i + 1

GUICtrlSetData($Progress1, $inc)

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service is stopped")

GUICtrlSetData($Progress1, "0")

ElseIf $result = "Running" Then

$i = 0

GUICtrlSetData($Progress1, "10")

Do

GUICtrlSetData($input1,"Service Is Running")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

$inc = $inc + 33

GUICtrlSetData($Progress1, $inc)

$i = $i + 1

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service is running")

GUICtrlSetData($Progress1, "0")

Else

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Unable to verify status. Server" & @CRLF & "might be down, or service" & @CRLF & "might not be registered")

GUICtrlSetData($Progress1, "0")

EndIf

EndIf

;stop service

Case $nMsg = $Button2

$Service = ""

$IPAddress = ""

$inc = 0

GUICtrlSetData($Progress1, "0")

GUICtrlSetBkColor($input1, 0xFFFFFF)

GUICtrlSetData($input1,"")

$IPAddress = GUICtrlRead($inpIPAddress)

$Service = GUICtrlRead($Combo1)

If $IPAddress = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Enter Remote Computer IP Address")

ElseIf $Service = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Select Service From Drop Down")

Else

GUICtrlSetData($Progress1, "10")

$result = _ServiceStop($Service, $IPAddress)

GUICtrlSetData($Progress1, "10")

GUICtrlSetData($Progress1, "10")

Sleep("2000")

$result = _Service_GetState($Service, $IPAddress)

;$result = _ServiceStatus("thislskjf", $IPAddress)

If $result = "Stopped" Then

$i = 0

Do

GUICtrlSetData($input1,"Service Is Stopped")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

$inc = $inc + 25

$i = $i + 1

GUICtrlSetData($Progress1, $inc)

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service is stopped")

GUICtrlSetData($Progress1, "0")

ElseIf $result = "Running" Then

$i = 0

GUICtrlSetData($Progress1, "10")

Do

GUICtrlSetData($input1,"Service Is Running")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

$inc = $inc + 33

GUICtrlSetData($Progress1, $inc)

$inc = $inc + 25

$i = $i + 1

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service is is still running" & @CRLF & "Wait a moment and run status check again" & @CRLF & "If service is still not stopped escalate issue")

GUICtrlSetData($Progress1, "0")

EndIf

EndIf

;start service

Case $nMsg = $Button3

$Service = ""

$IPAddress = ""

$inc = 0

GUICtrlSetData($Progress1, "0")

GUICtrlSetBkColor($input1, 0xFFFFFF)

GUICtrlSetData($input1,"")

$IPAddress = GUICtrlRead($inpIPAddress)

$Service = GUICtrlRead($Combo1)

If $IPAddress = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Enter Remote Computer IP Address")

ElseIf $Service = "" Then

MsgBox(1,"Vestas SCADA Tools","Please Select Service From Drop Down")

Else

GUICtrlSetData($Progress1, "10")

$result = _Service_Start($Service, $IPAddress)

GUICtrlSetData($Progress1, "10")

GUICtrlSetData($Progress1, "10")

Sleep("2000")

$result = _Service_GetState($Service, $IPAddress)

;$result = _ServiceStatus("thislskjf", $IPAddress)

If $result = "Stopped" Then

$i = 0

Do

GUICtrlSetData($input1,"Service Is Stopped")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFF0000)

$inc = $inc + 33

$i = $i + 1

GUICtrlSetData($Progress1, $inc)

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service has not started" & @CRLF & "Wait a moment and run status check again" & @CRLF & "If service is still not start escalate issue")

GUICtrlSetData($Progress1, "0")

ElseIf $result = "Running" Then

$i = 0

GUICtrlSetData($Progress1, "10")

Do

GUICtrlSetData($input1,"Service Is Running")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

Sleep("500")

GUICtrlSetBkColor($input1, 0xFFFFFF)

Sleep("500")

GUICtrlSetBkColor($input1, 0x0066CC)

$inc = $inc + 33

GUICtrlSetData($Progress1, $inc)

$i = $i + 1

Until $i = 3

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Service is running")

GUICtrlSetData($Progress1, "0")

Else

GUICtrlSetData($Progress1, "100")

MsgBox(1,"Vestas SCADA Tools","Unable to comunicate with server." & @CRLF & "Please make sure server is not down" & @CRLF & "If proplem continues escalte issue")

GUICtrlSetData($Progress1, "0")

EndIf

EndIf

Case $nMsg = $Button4

Exit

EndSelect

If $nMsg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...