I have a couple of functions from the Kernel32.dll which I am calling from C# program. I imported the functions as follows:
[System.Runtime.InteropServices.DllImport("Kernel32.dll", EntryPoint = "GetSystemTime", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
private static extern void GetSystemTime(ref SYSTEMTIME lpSystemTime);
[System.Runtime.InteropServices.DllImport("Kernel32.dll", EntryPoint = "SetSystemTime", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Ansi, SetLastError = true)]
private static extern UInt32 SetSystemTime(ref SYSTEMTIME lpSystemTime);
where SYSTEMTIME is a struct accepted by these methods. 
The documentation for SetSystemTime says that it returns 0 if the function fails and call GetLastError to get extended information on the failure. So I imported GetLastError from Kernel32.dll file in the same way as the above functions. Now when I simulate the failure as:
if (SetSystemTime(ref st) == 0) {
      Console.WriteLine(GetLastError() + " Error occurred: SetSystemTime returned zero.");
}
The GetLastError() prints a code of 1314 which is for A required privilege not held by the client. I changed the Local security policy to add the user to the Replace a process level token in the User rights assignment as well but I still get the same code. Is what I am doing correct or am I missing something?
 
    