使用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
您有解决我问题的想法吗? 谢谢您的回答, 阿兰     
已邀请:
我最近发布了一个类似的问题,但角度不同,但基本需求相同,该问题的标题为“如何以非管理员身份检查本地安全策略权限”以供参考。 无论如何,如果您在本地安全策略中明确授予该标准用户“更改系统时间”特权,则该非管理员可以正常访问SetSystemTime。我会在我的问题中解释我如何解决我的特殊需求,也许对您有帮助? 祝好运!     
请参考这篇文章:http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/c98a6b72-2330-4dee-b740-a3ab666b1f4b/。该问题无法解决。     

要回复问题请先登录注册