This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Enterprise console4.5/client9.5 - all PCs greyed out and won't report back, Help please!!

I had to reinstalled the console and it assigned itself a new certificate which was different to all the certificates on the existing clients. (I was unable to backup) when I reprotected the clients from the new console it does not automatically dish out a new certificate.

How do I distribute the new certificate?

Note: We have far too many computers to reinstall Sophos on. Plus many remote users :(

Cheers

:8665


This thread was automatically locked due to age.
Parents
  • ' RMS RE-INIT
    ' WILL ONLY RUN ONCE IF OK
    '  HKLM\SOFTWARE\[Wow6432Node]\Sophos\ReInit = 1 is set as check.
    ' Will not continue if "Server" router, based on:
    '  HKLM\SOFTWARE\[Wow6432Node]\Sophos\Messaging System\Router\ConnectionCache
    ' being 10. 
    ' Run with -force to skip above checks.
    ' To configure:
    '   strLogPath  'Path to the log file                
    '   strMRInitLog  'Where to write the log file for ClientMRInit.exe              
    '   strFilePathMrInit 'Location of new mrinit.conf (local or UNC)          
    '   strFilePathCac  'Location of new cac.pen (local or UNC)       
    ' Note: The account running the script needs to be an admin on the client and be
    ' able to read from the path where mrinit.conf and cac.pem are shared.     
    
    option explicit
    on error resume next
    
    const HKEY_LOCAL_MACHINE = &H80000002
    const ROUTER_SERVICE     = "Sophos Message Router"
    const AGENT_SERVICE      = "Sophos Agent"
    const REINIT_EXE_FILE    = "ClientMRInit.exe"
    const WOW_KEY            = "Wow6432Node"
    
    dim strLogPath, strMRInitLog, strFilePathCac, strFilePathMrInit, blInline, strCac
    dim strMrinit, objArgs, strArg, intForceRun
    
    intForceRun = 0
    
    Set objArgs = WScript.Arguments
    For Each strArg in objArgs
        if lcase(strArg) = "-force" then
          intForceRun = 1
        end if	
    Next 
    
    'IMPORTANT VARIABLE
    blInline  = False   
    'True|False, If True the script will create cac.pem and mrinit.conf 
    'from the below variables, these will need to be edited for YOUR installation.
    
    strCac ="-----BEGIN CERTIFICATE-----" &vbcrlf &_
    "MIIDFzCCAf+gAwIBAgIBATANBgkqhkiG9w0BAQQFADARMQ8wD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kUggu5rvrpZYxVOGBEc9hsYoCCQzfRDQtv5/U0p1" &vbcrlf &_
    "8wWdzETKXuMAEnT2PkL9yzwqSZ0tdg/NtA2untIW6Tiy7mXVSHTyvQiWU9BFrZXk" &vbcrlf &_
    "SzJwt4KzsdVReTsmYhE3ATUJbUFnOPfCky/e" &vbcrlf &_
    "-----END CERTIFICATE-----" &vbcrlf
    
    strMrinit = "[Config]" &vbcrlf &_ 
    """NotifyRouterUpdate""=""EM""" &vbcrlf &_ 
    """ClientIIOPPort""=dword:00002001" &vbcrlf &_ 
    """ClientSSLPort""=dword:00002002" &vbcrlf &_ 
    """ClientIORPort""=dword:00002000" &vbcrlf &_  
    """IORSenderPort""=dword:00002000" &vbcrlf &_ 
    """DelegatedManagerCertIdentityKey""=""s3IIjyQyBOiah2gMJ7lg15FmW2w=""" &vbcrlf &_  
    """ManagedAppCertIdentityKey""=""+lDc0ELrrIRnU14Nm3HV9ZZ4u20=""" &vbcrlf &_ 
    """RouterCertIdentityKey""=""qRS2iIVb8f5Ql3Y1SwJgOpB5vU0=""" &vbcrlf &_ 
    """ServiceArgs""=""""" &vbcrlf &_ 
    """MRParentAddress""=""192.168.1.70,p4,p4""" &vbcrlf &_  
    """ParentRouterAddress""=""192.168.1.70,p4,p4""" &vbcrlf 
    
    strLogPath                  = "C:\windows\temp\RMSReInit.log"
    strMRInitLog                = "C:\windows\temp"  'no trailing slash
    strFilePathMrInit           = "\\p4\SophosUpdate\CIDs\S000\SAVSCFXP\mrinit.conf"
    strFilePathCac              = "\\p4\SophosUpdate\CIDs\S000\SAVSCFXP\cac.pem"
    '*************************************************************************
    dim objFSO, objFile, strRMSPath, strWow6432Node,intPauseForServiceInSeconds
    
    strWow6432Node   = "\"
    intPauseForServiceInSeconds = 10
    
    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objFile = objFSO.CreateTextFile(strLogPath, true)
    WriteToLog 0, "Starting Script"
    
    if Is64() then
        strWow6432Node = "\" & WOW_KEY & "\"
    else
        strWow6432Node = "\"
    end if
    
    if intForceRun = 0 then
        if MarkerFound() then
            WriteToLog 0, "End of script"
            CloseLog()
            wscript.quit(1)
        end if
    	if ServerClassRouter() then
            WriteToLog 0, "End of script"
            CloseLog()
            wscript.quit(1)
        end if
    else
    	WriteToLog 0, "Running in Force mode (-force)"
    end if
    
    strRMSPath = GetRMSPath()
    
    If blInline then
       WriteToLog 0, "Creating Cac.pem and Mrinit.conf from script."
       CreateFile strCac, strRMSPath, "cac.pem"
       CreateFile strMrinit, strRMSPath, "mrinit.conf"
    else
        WriteToLog 0, "Copying Cac.pem and Mrinit.conf from locations."
        CopyFiles strFilePathCac, strRMSPath
        CopyFiles strFilePathMrInit, strRMSPath
    end if
    
    DeleteOrig(strRMSPath)
    StopService(AGENT_SERVICE)
    StopService(ROUTER_SERVICE)
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System", "cac", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\CertificationIdentityKeys", "CertificationIdentityKey", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\Router\Private", "pkc", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\Router\Private", "pkp", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\CertificationIdentityKeys", "ManagedApplication", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "CertificationIdentityKey", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "pkc", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "pkp", "."
    
    'Only create marker if ClientMrinit.exe returned ok
    if RunClientMRInit(strRMSPath) = 0 then
      CreateMarker()
    end if
    
    StartService(ROUTER_SERVICE)
    StartService(AGENT_SERVICE)
    WriteToLog 0, "Ending Script"
    CloseLog()
    
    Set objFSO = nothing
    
    
    '*************************************************************************
    Function CreateFile (strContents, strLocation, strFileName)
    
        WriteToLog 0, "--> CreateFile()"
    	
        dim objFileCreate
    
    	WriteToLog 0, "--> Creating file " & strFileName & " in " & strLocation
        Set objFileCreate = objFSO.CreateTextFile(strLocation & "\" & strFileName, true, false)
        
    	objFileCreate.Write strContents
    	
    	objFileCreate.close
    	
    	Set objFileCreate = nothing
    
    	 WriteToLog 0, "<-- CreateFile()"
    	
    End Function
    
    '*************************************************************************
    Function WriteToLog (strSev, strLogLine)
    
        dim strToWrite
    
        strToWrite = ""
    
        select case strSev
            case 0
    	        strToWrite = "INFO: "
            case 1
    	        strToWrite = "ERROR: "
            case else
    	        strToWrite = "UNKNOWN: "
        end select
    
        objFile.WriteLine Date() & " " & Time() & " " & strToWrite & " " & strLogLine
    
    End Function
    
    '*************************************************************************
    Function CloseLog()
    
        WriteToLog 0, "--> CloseLog() - No Function Exit Logged"
    
        objFile.Close
        
        set objFile = nothing
    
    End Function
    
    '*************************************************************************
    Function CreateMarker()
    
        WriteToLog 0, "--> CreateMarker()"	
    
        on error resume next
    
        dim oReg, intRetValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        intRetValue = oReg.SetStringValue (HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos" ,"ReInit", "1")
    
        if intRetValue = 0 then
            WriteToLog 0, "Created marker key." 
        else
            WriteToLog 1, "Failed to create marker.  Error code " & intRetValue
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- CreateMarker()"	
    
    End Function
    
    '*************************************************************************
    Function ServerClassRouter()
    
        WriteToLog 0, "--> ServerClassRouter()"	
    
        on error resume next
    
        dim oReg, intValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    			
    	    CloseLog()
           wscript.quit(1)
        end if
    
        oReg.GetDWORDValue HKEY_LOCAL_MACHINE,"SOFTWARE" &_
        	strWow6432Node & "Sophos\Messaging System\Router" ,"ConnectionCache", intValue
    
        if intValue = 10 then
            WriteToLog 0, "Router is a client, ok to run"
            ServerClassRouter = false
        else
            WriteToLog 1, "Router is a server router, will exit "
            ServerClassRouter = true
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- ServerClassRouter()"
    
    End Function
    
    '*************************************************************************
    Function MarkerFound()
    
        WriteToLog 0, "--> MarkerFound()"	
    
        on error resume next
    
        dim oReg, strValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    			
    	    CloseLog()
           wscript.quit(1)
        end if
    
        oReg.GetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE" &_
        	strWow6432Node & "Sophos" ,"ReInit", strValue
    
        if strValue = "1" then
            WriteToLog 0, "Script already run, will exit."
            MarkerFound = true
        else
            WriteToLog 0, "Script not already run."
            MarkerFound = false
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- MarkerFound()"
    
    End Function
    
    '*************************************************************************
    Function DeleteKey (strTopLevel, strKey, strName, strMachineName)
    
        WriteToLog 0,"--> DeleteKey()"	
        
    	on error resume next
    
        dim oReg, intReturn
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
        	strMachineName & "\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        WriteToLog 0, "Attemping to delete key: " &_
        	strMachineName & "\" & strTopLevel & "\" & strKey & "\" & strName
    
        intReturn = oReg.DeleteValue( HKEY_LOCAL_MACHINE, strKey, strName )
    
        if intReturn <> 0 then
            DeleteKey = intReturn
            WriteToLog 1, "Failed to delete Key: " & intReturn
        else  
            WriteToLog 0, "Deleted Key: " & intReturn
            DeleteKey = intReturn
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- DeleteKey()"
    
    End Function
    
    '*************************************************************************
    Function StopService(strServiceName)
    
        WriteToLog 0, "--> StopService()"
    
        on error resume next
    
        dim objWMIService, colServices, objService, intReturn
    
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colServices = objWMIService.ExecQuery ("Select * from win32_Service where name='" & strServiceName & "'")
    
        For each objService in colServices 
            intReturn = objService.StopService()
        Next
    
        wscript.sleep (intPauseForServiceInSeconds * 1000)
    
        WriteToLog 0, "Return code for stopping service: " & strServiceName & " : " & intReturn
    
        StopService = intReturn
    
        Set objWMIService = nothing
        Set colServices = nothing
    
        WriteToLog 0, "<-- StopService()"
    
    End function
    
    '*************************************************************************
    Function StartService(strServiceName)
    
        WriteToLog 0, "--> StartService()"
    
        on error resume next
    
        dim objWMIService, objService, colServices, intReturn
    
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colServices = objWMIService.ExecQuery ("Select * from win32_Service where name='" & strServiceName & "'")
    
        For each objService in colServices 
            intReturn = objService.StartService()
        Next
    
        WriteToLog 0, "Return code for starting service: " & strServiceName & " : " & intReturn
    
        StartService = intReturn
    
        Set objWMIService = nothing
        Set colServices = nothing
    
        WriteToLog 0, "<-- StartService()"
    
    End function
    
    '*************************************************************************
    Function RunClientMRInit(strPathToExe)
    
        WriteToLog 0, "--> RunClientMRInit()"
    
        on error resume next
    
        dim intReturn, oShell, strSwitches, strCommand
    
        WriteToLog 0, "Running command: " & strPathToExe & REINIT_EXE_FILE 
    
        Set oShell = WScript.CreateObject("WScript.Shell")
    
        if err.number <> 0 then
            WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        strSwitches = " -logpath " & strMRInitLog
        strSwitches = strSwitches & " -filepath" & " " & """" &  strPathToExe & """"
        strCommand  = """" & strPathToExe & REINIT_EXE_FILE & """" & strSwitches
    
        intReturn = oShell.Run(strCommand, 0, true)
    
        if intReturn <> 0 then
            WriteToLog 1, strPathToExe & REINIT_EXE_FILE &_
    			strSwitches & " Failed.  Exit code " & intReturn
        else
            WriteToLog 0, strPathToExe & REINIT_EXE_FILE &_
        		strSwitches & " Completed OK.  Exit code " & intReturn
        end if
    
        RunClientMRInit = intReturn
    
        set oShell = nothing
    
        WriteToLog 0, "--> RunClientMRInit()"
    
    End Function
    
    '*************************************************************************
    Function GetRMSPath()
    
        WriteToLog 0, "--> GetRMSPath()"
    
        on error resume next
    
        dim oReg, strValue, intReturn
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        intReturn = oReg.GetStringValue (HKEY_LOCAL_MACHINE, "SOFTWARE" &_
    		strWow6432Node & "Sophos\Messaging System\Router", "ServiceHomeDir", strValue)
    
        If strValue <> "" then
            WriteToLog 0, "RMS Path is " & strValue
            GetRMSPath = strValue
        else
            WriteToLog 1, "Return code " & intReturn
            CloseLog()
            wscript.quit(1)
        end if	
    
        set oReg = nothing
    
        WriteToLog 0, "<-- GetRMSPath()"
    
    End Function
    
    '*************************************************************************
    Function DeleteOrig(strFilePath)
    
        WriteToLog 0, "--> DeleteOrig()"
    
        on error resume next
        err.clear
    
        dim oFS, intReturn, strOrigPath
    
    	strOrigPath = strFilePath & "mrinit.conf.orig"
    	
        set oFS = CreateObject("Scripting.FileSystemObject")
    
        If oFS.FileExists(strOrigPath) Then
            WriteToLog 0, strOrigPath & " Exists"
    
            intReturn = oFS.DeleteFile(strOrigPath,  true)
    
            if intReturn = 0 then
                 WriteToLog 0, strOrigPath & " deleted."
             else
                 WriteToLog 1, strOrigPath & " Not deleted: Return code: " & intReturn
            end if
    
        else
            WriteToLog 0, strOrigPath & " does not exist, carrying on."
        End If
    
        set oFS = nothing
    
        WriteToLog 0, "<-- DeleteOrig()"
    
    End Function
    
    '*************************************************************************
    'FUNCTION COPY FILE FROM SERVER
    Function CopyFiles(strFilePath, strDestination)
    
        WriteToLog 0, "--> CopyFiles()"
    
        on error resume next
        err.clear
    
        dim oFS, intReturn
    
        set oFS = CreateObject("Scripting.FileSystemObject")
    
        If oFS.FileExists(strFilePath) Then
            WriteToLog 0, strFilePath & " Exists"
    
            intReturn = oFS.CopyFile(strFilePath, strDestination, true)
    
            if intReturn = 0 then
                 WriteToLog 0, strFilePath & " Copied to " & strDestination
             else
                 WriteToLog 1, strFilePath & " Not copied to " & strDestination & " Return code: " & intReturn
            end if
    
        else
            WriteToLog 1, strFilePath & " does not exist"
            CloseLog()
            wscript.quit(1)
        End If
    
        set oFS = nothing
    
        WriteToLog 0, "<-- CopyFiles()"
    
    End Function
    
    '*************************************************************************
    'FUNCTION TO GET PLATFORM
    Function Is64()
        WriteToLog 0, "--> Is64()"
        on error resume next
        err.clear
        
    	dim objWMIService, objColSettings, strDesc, objProcessor
    	
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    	Set objColSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_Processor") 
    	
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
        
    	For Each objProcessor In objColSettings 
    		strDesc = objProcessor.AddressWidth 
    	Next 
    	
        if strDesc = "86" then
            WriteToLog 0, "Platform is 32-Bit"
            Is64 = false
        end if
        if strDesc = "64" then
            WriteToLog 0, "Platform is 64-Bit"
            Is64 = true
        end if
    	
        Set objWMIService = nothing
    set objColSettings = nothing
    	
        WriteToLog 0, "<-- Is64()"
    End Function
    :8923
Reply
  • ' RMS RE-INIT
    ' WILL ONLY RUN ONCE IF OK
    '  HKLM\SOFTWARE\[Wow6432Node]\Sophos\ReInit = 1 is set as check.
    ' Will not continue if "Server" router, based on:
    '  HKLM\SOFTWARE\[Wow6432Node]\Sophos\Messaging System\Router\ConnectionCache
    ' being 10. 
    ' Run with -force to skip above checks.
    ' To configure:
    '   strLogPath  'Path to the log file                
    '   strMRInitLog  'Where to write the log file for ClientMRInit.exe              
    '   strFilePathMrInit 'Location of new mrinit.conf (local or UNC)          
    '   strFilePathCac  'Location of new cac.pen (local or UNC)       
    ' Note: The account running the script needs to be an admin on the client and be
    ' able to read from the path where mrinit.conf and cac.pem are shared.     
    
    option explicit
    on error resume next
    
    const HKEY_LOCAL_MACHINE = &H80000002
    const ROUTER_SERVICE     = "Sophos Message Router"
    const AGENT_SERVICE      = "Sophos Agent"
    const REINIT_EXE_FILE    = "ClientMRInit.exe"
    const WOW_KEY            = "Wow6432Node"
    
    dim strLogPath, strMRInitLog, strFilePathCac, strFilePathMrInit, blInline, strCac
    dim strMrinit, objArgs, strArg, intForceRun
    
    intForceRun = 0
    
    Set objArgs = WScript.Arguments
    For Each strArg in objArgs
        if lcase(strArg) = "-force" then
          intForceRun = 1
        end if	
    Next 
    
    'IMPORTANT VARIABLE
    blInline  = False   
    'True|False, If True the script will create cac.pem and mrinit.conf 
    'from the below variables, these will need to be edited for YOUR installation.
    
    strCac ="-----BEGIN CERTIFICATE-----" &vbcrlf &_
    "MIIDFzCCAf+gAwIBAgIBATANBgkqhkiG9w0BAQQFADARMQ8wDQYDVQQDFAZFTTJf" &vbcrlf &_
    "Q0EwHhcNMTAxMDIyMTgxODQxWhcNMzAxMDE4MTgxODQxWjARM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SZ0tdg/NtA2untIW6Tiy7mXVSHTyvQiWU9BFrZXk" &vbcrlf &_
    "SzJwt4KzsdVReTsmYhE3ATUJbUFnOPfCky/e" &vbcrlf &_
    "-----END CERTIFICATE-----" &vbcrlf
    
    strMrinit = "[Config]" &vbcrlf &_ 
    """NotifyRouterUpdate""=""EM""" &vbcrlf &_ 
    """ClientIIOPPort""=dword:00002001" &vbcrlf &_ 
    """ClientSSLPort""=dword:00002002" &vbcrlf &_ 
    """ClientIORPort""=dword:00002000" &vbcrlf &_  
    """IORSenderPort""=dword:00002000" &vbcrlf &_ 
    """DelegatedManagerCertIdentityKey""=""s3IIjyQyBOiah2gMJ7lg15FmW2w=""" &vbcrlf &_  
    """ManagedAppCertIdentityKey""=""+lDc0ELrrIRnU14Nm3HV9ZZ4u20=""" &vbcrlf &_ 
    """RouterCertIdentityKey""=""qRS2iIVb8f5Ql3Y1SwJgOpB5vU0=""" &vbcrlf &_ 
    """ServiceArgs""=""""" &vbcrlf &_ 
    """MRParentAddress""=""192.168.1.70,p4,p4""" &vbcrlf &_  
    """ParentRouterAddress""=""192.168.1.70,p4,p4""" &vbcrlf 
    
    strLogPath                  = "C:\windows\temp\RMSReInit.log"
    strMRInitLog                = "C:\windows\temp"  'no trailing slash
    strFilePathMrInit           = "\\p4\SophosUpdate\CIDs\S000\SAVSCFXP\mrinit.conf"
    strFilePathCac              = "\\p4\SophosUpdate\CIDs\S000\SAVSCFXP\cac.pem"
    '*************************************************************************
    dim objFSO, objFile, strRMSPath, strWow6432Node,intPauseForServiceInSeconds
    
    strWow6432Node   = "\"
    intPauseForServiceInSeconds = 10
    
    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objFile = objFSO.CreateTextFile(strLogPath, true)
    WriteToLog 0, "Starting Script"
    
    if Is64() then
        strWow6432Node = "\" & WOW_KEY & "\"
    else
        strWow6432Node = "\"
    end if
    
    if intForceRun = 0 then
        if MarkerFound() then
            WriteToLog 0, "End of script"
            CloseLog()
            wscript.quit(1)
        end if
    	if ServerClassRouter() then
            WriteToLog 0, "End of script"
            CloseLog()
            wscript.quit(1)
        end if
    else
    	WriteToLog 0, "Running in Force mode (-force)"
    end if
    
    strRMSPath = GetRMSPath()
    
    If blInline then
       WriteToLog 0, "Creating Cac.pem and Mrinit.conf from script."
       CreateFile strCac, strRMSPath, "cac.pem"
       CreateFile strMrinit, strRMSPath, "mrinit.conf"
    else
        WriteToLog 0, "Copying Cac.pem and Mrinit.conf from locations."
        CopyFiles strFilePathCac, strRMSPath
        CopyFiles strFilePathMrInit, strRMSPath
    end if
    
    DeleteOrig(strRMSPath)
    StopService(AGENT_SERVICE)
    StopService(ROUTER_SERVICE)
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System", "cac", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\CertificationIdentityKeys", "CertificationIdentityKey", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\Router\Private", "pkc", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Messaging System\Router\Private", "pkp", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\CertificationIdentityKeys", "ManagedApplication", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "CertificationIdentityKey", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "pkc", "."
    DeleteKey HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos\Remote Management System\ManagementAgent\Private", "pkp", "."
    
    'Only create marker if ClientMrinit.exe returned ok
    if RunClientMRInit(strRMSPath) = 0 then
      CreateMarker()
    end if
    
    StartService(ROUTER_SERVICE)
    StartService(AGENT_SERVICE)
    WriteToLog 0, "Ending Script"
    CloseLog()
    
    Set objFSO = nothing
    
    
    '*************************************************************************
    Function CreateFile (strContents, strLocation, strFileName)
    
        WriteToLog 0, "--> CreateFile()"
    	
        dim objFileCreate
    
    	WriteToLog 0, "--> Creating file " & strFileName & " in " & strLocation
        Set objFileCreate = objFSO.CreateTextFile(strLocation & "\" & strFileName, true, false)
        
    	objFileCreate.Write strContents
    	
    	objFileCreate.close
    	
    	Set objFileCreate = nothing
    
    	 WriteToLog 0, "<-- CreateFile()"
    	
    End Function
    
    '*************************************************************************
    Function WriteToLog (strSev, strLogLine)
    
        dim strToWrite
    
        strToWrite = ""
    
        select case strSev
            case 0
    	        strToWrite = "INFO: "
            case 1
    	        strToWrite = "ERROR: "
            case else
    	        strToWrite = "UNKNOWN: "
        end select
    
        objFile.WriteLine Date() & " " & Time() & " " & strToWrite & " " & strLogLine
    
    End Function
    
    '*************************************************************************
    Function CloseLog()
    
        WriteToLog 0, "--> CloseLog() - No Function Exit Logged"
    
        objFile.Close
        
        set objFile = nothing
    
    End Function
    
    '*************************************************************************
    Function CreateMarker()
    
        WriteToLog 0, "--> CreateMarker()"	
    
        on error resume next
    
        dim oReg, intRetValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        intRetValue = oReg.SetStringValue (HKEY_LOCAL_MACHINE, "SOFTWARE" & strWow6432Node & "Sophos" ,"ReInit", "1")
    
        if intRetValue = 0 then
            WriteToLog 0, "Created marker key." 
        else
            WriteToLog 1, "Failed to create marker.  Error code " & intRetValue
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- CreateMarker()"	
    
    End Function
    
    '*************************************************************************
    Function ServerClassRouter()
    
        WriteToLog 0, "--> ServerClassRouter()"	
    
        on error resume next
    
        dim oReg, intValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    			
    	    CloseLog()
           wscript.quit(1)
        end if
    
        oReg.GetDWORDValue HKEY_LOCAL_MACHINE,"SOFTWARE" &_
        	strWow6432Node & "Sophos\Messaging System\Router" ,"ConnectionCache", intValue
    
        if intValue = 10 then
            WriteToLog 0, "Router is a client, ok to run"
            ServerClassRouter = false
        else
            WriteToLog 1, "Router is a server router, will exit "
            ServerClassRouter = true
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- ServerClassRouter()"
    
    End Function
    
    '*************************************************************************
    Function MarkerFound()
    
        WriteToLog 0, "--> MarkerFound()"	
    
        on error resume next
    
        dim oReg, strValue
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    			
    	    CloseLog()
           wscript.quit(1)
        end if
    
        oReg.GetStringValue HKEY_LOCAL_MACHINE,"SOFTWARE" &_
        	strWow6432Node & "Sophos" ,"ReInit", strValue
    
        if strValue = "1" then
            WriteToLog 0, "Script already run, will exit."
            MarkerFound = true
        else
            WriteToLog 0, "Script not already run."
            MarkerFound = false
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- MarkerFound()"
    
    End Function
    
    '*************************************************************************
    Function DeleteKey (strTopLevel, strKey, strName, strMachineName)
    
        WriteToLog 0,"--> DeleteKey()"	
        
    	on error resume next
    
        dim oReg, intReturn
    
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
        	strMachineName & "\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " &_
        		err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        WriteToLog 0, "Attemping to delete key: " &_
        	strMachineName & "\" & strTopLevel & "\" & strKey & "\" & strName
    
        intReturn = oReg.DeleteValue( HKEY_LOCAL_MACHINE, strKey, strName )
    
        if intReturn <> 0 then
            DeleteKey = intReturn
            WriteToLog 1, "Failed to delete Key: " & intReturn
        else  
            WriteToLog 0, "Deleted Key: " & intReturn
            DeleteKey = intReturn
        end if
    
        Set oReg = nothing
    
        WriteToLog 0, "<-- DeleteKey()"
    
    End Function
    
    '*************************************************************************
    Function StopService(strServiceName)
    
        WriteToLog 0, "--> StopService()"
    
        on error resume next
    
        dim objWMIService, colServices, objService, intReturn
    
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colServices = objWMIService.ExecQuery ("Select * from win32_Service where name='" & strServiceName & "'")
    
        For each objService in colServices 
            intReturn = objService.StopService()
        Next
    
        wscript.sleep (intPauseForServiceInSeconds * 1000)
    
        WriteToLog 0, "Return code for stopping service: " & strServiceName & " : " & intReturn
    
        StopService = intReturn
    
        Set objWMIService = nothing
        Set colServices = nothing
    
        WriteToLog 0, "<-- StopService()"
    
    End function
    
    '*************************************************************************
    Function StartService(strServiceName)
    
        WriteToLog 0, "--> StartService()"
    
        on error resume next
    
        dim objWMIService, objService, colServices, intReturn
    
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colServices = objWMIService.ExecQuery ("Select * from win32_Service where name='" & strServiceName & "'")
    
        For each objService in colServices 
            intReturn = objService.StartService()
        Next
    
        WriteToLog 0, "Return code for starting service: " & strServiceName & " : " & intReturn
    
        StartService = intReturn
    
        Set objWMIService = nothing
        Set colServices = nothing
    
        WriteToLog 0, "<-- StartService()"
    
    End function
    
    '*************************************************************************
    Function RunClientMRInit(strPathToExe)
    
        WriteToLog 0, "--> RunClientMRInit()"
    
        on error resume next
    
        dim intReturn, oShell, strSwitches, strCommand
    
        WriteToLog 0, "Running command: " & strPathToExe & REINIT_EXE_FILE 
    
        Set oShell = WScript.CreateObject("WScript.Shell")
    
        if err.number <> 0 then
            WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        strSwitches = " -logpath " & strMRInitLog
        strSwitches = strSwitches & " -filepath" & " " & """" &  strPathToExe & """"
        strCommand  = """" & strPathToExe & REINIT_EXE_FILE & """" & strSwitches
    
        intReturn = oShell.Run(strCommand, 0, true)
    
        if intReturn <> 0 then
            WriteToLog 1, strPathToExe & REINIT_EXE_FILE &_
    			strSwitches & " Failed.  Exit code " & intReturn
        else
            WriteToLog 0, strPathToExe & REINIT_EXE_FILE &_
        		strSwitches & " Completed OK.  Exit code " & intReturn
        end if
    
        RunClientMRInit = intReturn
    
        set oShell = nothing
    
        WriteToLog 0, "--> RunClientMRInit()"
    
    End Function
    
    '*************************************************************************
    Function GetRMSPath()
    
        WriteToLog 0, "--> GetRMSPath()"
    
        on error resume next
    
        dim oReg, strValue, intReturn
        err.clear
    
        Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
    
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
    
        intReturn = oReg.GetStringValue (HKEY_LOCAL_MACHINE, "SOFTWARE" &_
    		strWow6432Node & "Sophos\Messaging System\Router", "ServiceHomeDir", strValue)
    
        If strValue <> "" then
            WriteToLog 0, "RMS Path is " & strValue
            GetRMSPath = strValue
        else
            WriteToLog 1, "Return code " & intReturn
            CloseLog()
            wscript.quit(1)
        end if	
    
        set oReg = nothing
    
        WriteToLog 0, "<-- GetRMSPath()"
    
    End Function
    
    '*************************************************************************
    Function DeleteOrig(strFilePath)
    
        WriteToLog 0, "--> DeleteOrig()"
    
        on error resume next
        err.clear
    
        dim oFS, intReturn, strOrigPath
    
    	strOrigPath = strFilePath & "mrinit.conf.orig"
    	
        set oFS = CreateObject("Scripting.FileSystemObject")
    
        If oFS.FileExists(strOrigPath) Then
            WriteToLog 0, strOrigPath & " Exists"
    
            intReturn = oFS.DeleteFile(strOrigPath,  true)
    
            if intReturn = 0 then
                 WriteToLog 0, strOrigPath & " deleted."
             else
                 WriteToLog 1, strOrigPath & " Not deleted: Return code: " & intReturn
            end if
    
        else
            WriteToLog 0, strOrigPath & " does not exist, carrying on."
        End If
    
        set oFS = nothing
    
        WriteToLog 0, "<-- DeleteOrig()"
    
    End Function
    
    '*************************************************************************
    'FUNCTION COPY FILE FROM SERVER
    Function CopyFiles(strFilePath, strDestination)
    
        WriteToLog 0, "--> CopyFiles()"
    
        on error resume next
        err.clear
    
        dim oFS, intReturn
    
        set oFS = CreateObject("Scripting.FileSystemObject")
    
        If oFS.FileExists(strFilePath) Then
            WriteToLog 0, strFilePath & " Exists"
    
            intReturn = oFS.CopyFile(strFilePath, strDestination, true)
    
            if intReturn = 0 then
                 WriteToLog 0, strFilePath & " Copied to " & strDestination
             else
                 WriteToLog 1, strFilePath & " Not copied to " & strDestination & " Return code: " & intReturn
            end if
    
        else
            WriteToLog 1, strFilePath & " does not exist"
            CloseLog()
            wscript.quit(1)
        End If
    
        set oFS = nothing
    
        WriteToLog 0, "<-- CopyFiles()"
    
    End Function
    
    '*************************************************************************
    'FUNCTION TO GET PLATFORM
    Function Is64()
        WriteToLog 0, "--> Is64()"
        on error resume next
        err.clear
        
    	dim objWMIService, objColSettings, strDesc, objProcessor
    	
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    	Set objColSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_Processor") 
    	
        if err.number <> 0 then
    	    WriteToLog 1, "Error Number: " & err.number & " Error Description: " & err.description
    	    CloseLog()
           wscript.quit(1)
        end if
        
    	For Each objProcessor In objColSettings 
    		strDesc = objProcessor.AddressWidth 
    	Next 
    	
        if strDesc = "86" then
            WriteToLog 0, "Platform is 32-Bit"
            Is64 = false
        end if
        if strDesc = "64" then
            WriteToLog 0, "Platform is 64-Bit"
            Is64 = true
        end if
    	
        Set objWMIService = nothing
    set objColSettings = nothing
    	
        WriteToLog 0, "<-- Is64()"
    End Function
    :8923
Children
No Data