Skip to content

Instantly share code, notes, and snippets.

@matt40k
Created May 28, 2015 14:01
Show Gist options
  • Save matt40k/649a9e6cc0e8546adda0 to your computer and use it in GitHub Desktop.
Save matt40k/649a9e6cc0e8546adda0 to your computer and use it in GitHub Desktop.
Updates your SOLUS3 Agent config with the new Deployment server
''
' Name: UpdateS3AgentDS.vbs
'
' Description:
' Updates your SOLUS3 Agent config with the new Deployment server
'
' Version: 1.1
'
' Usage: UpdateS3AgentDS.vbs <oldservername> <newservername>
'
' Change History
' ==============
' 1.0 - Release
' 1.1 - Stop S3Agent service prior to making change then starts again post change
''
Option Explicit
Dim objFSO, xmlDoc, colNodes
Dim objWMIService, colListOfServices, objService
Dim strServiceName, strOld, strNew, oldport, newport, strDef
Dim node, att
If WScript.Arguments.Count <> 2 Then
WScript.Quit(1)
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
strServiceName = "Solus3Agent"
oldport = "52965"
newport = "52965"
strOld = "net.tcp://" + WScript.Arguments(0) + ":" + oldport
strNew = "net.tcp://" + WScript.Arguments(1) + ":" + newport
strDef = "c:\program files\solus3\AgentService\Sims.Solus3.Agent.AgentService.exe.config"
If objFSO.FileExists (strDef) then
Call Main(strDef)
End If
Sub Main(strDef)
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load (strDef)
Set colNodes = xmlDoc.SelectNodes("/configuration/system.serviceModel/client/endpoint")
For Each node In colNodes
For Each att In node.Attributes
If att.Name = "name" And att.Text = "IAgentServiceManager_Standard" Then
Call ChangeAddressAttribute(node)
End If
Next
Next
Call Stop_S3Agent
xmlDoc.Save (strDef)
Call Start_S3Agent
End Sub
Sub ChangeAddressAttribute(node)
For Each att In node.Attributes
If att.Name = "address" Then
If att.Value = strOld Then
att.Value = strNew
Exit Sub
End If
End If
Next
End Sub
Sub Start_S3Agent
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StartService()
Next
End Sub
Sub Stop_S3Agent
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colListOfServices = objWMIService.ExecQuery("Select * from Win32_Service Where Name='" & strServiceName & "'")
For Each objService in colListOfServices
objService.StopService()
Next
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment