74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
//----------------------------------------------------------------------------
|
|
//
|
|
// Copyright (c) Intel Corporation, 2011 - 2014 All Rights Reserved.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Intel.Manageability;
|
|
using Intel.Manageability.Exceptions;
|
|
using HLAPI;
|
|
using Common.Utils;
|
|
using System.IO;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace AgentPresenceLocalSample2
|
|
{
|
|
class Program
|
|
{
|
|
[DllImport("kernel32.dll", CallingConvention = CallingConvention.StdCall)]
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
|
public static extern bool SetDefaultDllDirectories(int directoryFlags);
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
// set default dll lookup directory to system
|
|
SetDefaultDllDirectories(0x00000800); //LOAD_LIBRARY_SEARCH_SYSTEM32
|
|
|
|
IAMTInstance amt = null;
|
|
ConnectionInfoEX ci = null;
|
|
|
|
try
|
|
{
|
|
// Check if JSON path was provided as an argument. If not, default path would be used.
|
|
try
|
|
{
|
|
ci = ProgramInput.DeserializeJsonToStruct(args.Length > 0 ? args[0] : null);
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
Console.WriteLine($"Could not read argument file: {e.Message}");
|
|
return;
|
|
}
|
|
|
|
amt = AMTInstanceFactory.CreateEX(ci);
|
|
}
|
|
catch (ManageabilityException e)
|
|
{
|
|
ci?.Dispose();
|
|
Console.WriteLine(e.Message);
|
|
return;
|
|
}
|
|
|
|
try
|
|
{
|
|
// StartPresence causes the agent to start sends heartbeats.
|
|
AgentPresenceLocalFunctionality2.Start(amt, "Agent1");
|
|
|
|
// ExpirePresence causes the StartPresence to stop sending heartbeats. The thread that performs it was finished
|
|
// and the agent's state was changed to "expire".
|
|
AgentPresenceLocalFunctionality2.Expire(amt, "Agent1");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
finally
|
|
{
|
|
amt?.Dispose();
|
|
}
|
|
}
|
|
}
|
|
} |