使用SetSystemTime和受限用户帐户
|
操作系统:Windows XP(嵌入式)
语言:c#
问题:
使用受限的用户帐户,我尝试通过使用函数SetSystemTime()来以编程方式更改Windows XP的日期和时间,但它返回false,错误代码为5:拒绝访问。
阅读MSDN文章后,我通过使用LogonUser()和Impersonate()函数,将受限用户帐户模拟为管理员用户(属于管理员组,并且有权更改系统时间),并在SetSystemTime()之后调用,但结果是和以前一样。
我模拟了特权之后,在调用AdjustTokenPrivileges()并没有返回错误之前,将特权“ SeSystemtimePrivilege \”赋予受限的用户帐户,但结果与之前相同。
码:
const int SE_PRIVILEGE_ENABLED = 2;
// Starting with limited user account
intPtr userToken = WindowsIdentity.GetCurrent(TokenAccessLevels.AdjustPrivileges | TokenAccessLevels.Query).Token;
IntPtr tokenDuplicate = IntPtr.Zero;
IntPtr token = IntPtr.Zero;
LogonUser(\"administrator\", domain, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token);
DuplicateToken(token, 2, ref tokenDuplicate);
WindowsImpersonationContext wic = (new WindowsIdentity(tokenDuplicate)).Impersonate();
bool enabled = true;
TOKEN_PRIVILEGES tokenPrivilege = new TOKEN_PRIVILEGES();
tokenPrivilege.PrivilegeCount = 1;
tokenPrivilege.Privileges = new LUID_AND_ATTRIBUTES[tokenPrivilege.PrivilegeCount];
tokenPrivilege.Privileges[0].Attributes = (UInt32)(enabled ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_DISABLED);
if (LookupPrivilegeValue(null, \"SeSystemtimePrivilege\", out tokenPrivilege.Privileges[0].Luid))
AdjustTokenPrivileges(userToken, false, ref tokenPrivilege, (UInt32)Marshal.SizeOf(typeof(TOKEN_PRIVILEGES)), IntPtr.Zero, IntPtr.Zero);
// Return to limited user account
wic.Undo();
if(!SetSystemTime(systemTime)) // systemTime in UTC time
.... Error code here, 5 if I let administrator impersonate or 1314
您有解决我问题的想法吗?
谢谢您的回答,
阿兰
没有找到相关结果
已邀请:
2 个回复
戊袱
澜悍景哭苟