相关疑难解决方法(0)

如何使用.NET更新系统的日期和/或时间

我正在尝试使用以下内容更新系统时间:

[StructLayout(LayoutKind.Sequential)] 
private struct SYSTEMTIME
{
    public ushort wYear;
    public ushort wMonth;
    public ushort wDayOfWeek;
    public ushort wDay;
    public ushort wHour;
    public ushort wMinute;
    public ushort wSecond;
    public ushort wMilliseconds;
}

[DllImport("kernel32.dll", EntryPoint = "GetSystemTime", SetLastError = true)]
private extern static void Win32GetSystemTime(ref SYSTEMTIME lpSystemTime);

[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
private extern static bool Win32SetSystemTime(ref SYSTEMTIME lpSystemTime);

public void SetTime()
{
    TimeSystem correctTime = new TimeSystem();
    DateTime sysTime = correctTime.GetSystemTime();
    // Call the native GetSystemTime method
    // with …
Run Code Online (Sandbox Code Playgroud)

.net c# vb.net

8
推荐指数
2
解决办法
1万
查看次数

在Asp.net中设置Windows时钟c#

我需要在我的Asp.net网站上设置Windows时钟(用C#编写)

我在stackoverflow中找到了一个解决方案:

如何使用C#将Windows系统时钟设置为正确的本地时间?

但是当我使用它时,我给出了异常:

客户不持有所需的特权

我的应用程序轮询标识是:LocalSystem

asp.net iis privileges kernel32

6
推荐指数
1
解决办法
637
查看次数

标签 统计

.net ×1

asp.net ×1

c# ×1

iis ×1

kernel32 ×1

privileges ×1

vb.net ×1