我想通過編程修改系統時間在C#(在Windows 8.1)和 我用Win32SetSystemTime和setSystemTime:win32set時間返回錯誤8.1
我設置權限之前,我調用這些功能,並設置權限返回true,但是當我調用Win32SetSystemTime或setSystemTime時,我得到錯誤1300和1314,系統時間根本沒有改變。 這些錯誤是關於特權! 而且每當我以管理員身份運行應用程序時,他們都能正常工作! 我用下面的代碼來設置權限:
string privilege = "SE_SYSTEMTIME_NAME";
try
{
bool retVal;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
retVal = OpenProcessToken(hproc,TOKEN_ALL_ACCESS , ref htok);
// retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return retVal;
}
catch (Exception ex)
{
throw ex;
}
提升權限並不是那麼簡單,你必須[很好地提出](http://stackoverflow.com/a/2818776/ 17034).. –