'Script to Install Device Control Plus Agent
'============================================

'To install agent with the share path given as argument
'=======================================================

On Error Resume Next


Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("Process")
DrivePath = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
checkOSArch = WshShell.RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")


if Err Then
	Err.Clear
	regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\AdventNet\ManageEngine\UESAgent\"
else
	if checkOSArch = "x86" Then
		regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\AdventNet\ManageEngine\UESAgent\"
	else
		regkey = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\AdventNet\ManageEngine\UESAgent\"
	End IF
End If


' Get Location and arguments of the script
currdir = WSCript.Arguments.Item(0)
agentVersion = WshShell.RegRead(regkey&"AgentVersion")

if Err Then
	Err.Clear
	if WSCript.Arguments.count = 2 then
		mstFile = WSCript.Arguments.Item(1)
		WshShell.Run "msiexec.exe /i """&currdir&"""  ENABLESILENT=yes REBOOT=ReallySuppress /qn MSIRESTARTMANAGERCONTROL=Disable INSTALLSOURCE=GPO /lv "&DrivePath&"\AgentInstallerLog.log",0,True
	Elseif WSCript.Arguments.count = 1 then
		WshShell.Run "msiexec.exe /i """&currdir&""" ENABLESILENT=yes REBOOT=ReallySuppress /qn MSIRESTARTMANAGERCONTROL=Disable /lv "&DrivePath&"\AgentInstallerLog.log",0,True
	End if
End If