'Manage Engine Device Control Plus Agent .

'Script to Configure ManageEngine Device Control Plus Agent - Server Communication Settings .
'=======================================================================================

On Error Resume Next

Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("Process")

checkOSArch = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")

'Wscript.Echo checkOSArch 

if Err Then
	Err.Clear
	'WScript.Echo "The OS Architecture is unable to find ,so it was assumed to be 32 bit"
	regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\AdventNet\ManageEngine\UESAgent\ServerInfo\"
else
	if checkOSArch = "x86" Then
		'Wscript.Echo "The OS Architecture is 32 bit"
		regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\AdventNet\ManageEngine\UESAgent\ServerInfo\"
	else
		'Wscript.Echo "The OS Architecture is 64 bit"
		regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\AdventNet\ManageEngine\UESAgent\ServerInfo\"
	End IF
End If
'Needs five arguments 

if WScript.Arguments.Count = 5 Then

   serverName		= WScript.Arguments.Item(0) ' servername 
   ipaddress 		= WScript.Arguments.Item(1) ' server ip address 
   serverHttpPort 	= WScript.Arguments.Item(2) ' http port number
   serverHttpsPort 	= WScript.Arguments.Item(3) ' https port number 
   serverProtocol 	= WScript.Arguments.Item(4) ' protocol (http/https)
   
   WshShell.Run "%windir%\system32\sc stop "   &Chr(34)& "ManageEngine Unified Endpoint Security - Agent"  &Chr(34),1,True

   WshShell.RegWrite regkey&"ServerName",serverName
   WshShell.RegWrite regkey&"ServerIPAddress",ipaddress
   WshShell.RegWrite regkey&"LastAccessName",ipaddress
   WshShell.RegWrite regkey&"ServerPort",serverHttpPort
   WshShell.RegWrite regkey&"ServerSecurePort",serverHttpsPort
   WshShell.RegWrite regkey&"ServerProtocol",serverProtocol
   
	WshShell.Run "%windir%\system32\sc start "   &Chr(34)& "ManageEngine Unified Endpoint Security - Agent"  &Chr(34),1,True

End if 
 
'******************************************************************************************************