locked
P/Invoking SetLocalTime/SetSystemTime fails under Vista (even with proper privileges) RRS feed

  • Question

  • (NOTE: I had to cross-post this on the "General Vista Development issues" forums also since I thought it was topical there too)

     

    We had a fairly large codebase that ran successfully on XP thus far.  One part of the code was calling the SetLocalTime to set the current system time.  This call expectedly failed under Vista due to privileges issue.

     

    I wrote a small test C# console based application to P/Invoke SetLocalTime/SetSystemTime.  The calls consistently return false (and time is obviously not set) even if I embed a manifest that has a 'requireAdministrator' execution level.  The logged on user belongs to the administrator group.  In fact the code doesn't work even if I run the console app from an elevated command prompt.  Surprisingly, calling Marshal.GetLastWin32Error() immediately after returns 0 indicating "the operation completed successfully".

     

    I can post the code but its really simple.  I have some P/Invoke signatures for the SYSTEMTIME structure and the SetLocalTime/SetSystemTime APIs.

    I haven't yet turned off UAC and tested this (and I don't want to either if that is what will get this to work!).

     

    I have also tried P/Invoking the appropriate APIs (LookUpPrivilege, AdjustTokenPrivileges, OpenProcessToken) to explicity grant the SE_SYSTEMTIME_NAME privilege but to no avail!

     

    Monday, May 19, 2008 11:22 PM