相关疑难解决方法(0)

如何强制我的.NET应用程序以管理员身份运行?

一旦我的程序安装在客户端计算机上,如何强制我的程序在Windows 7上以管理员身份运行?

.net c# administrator windows-7 elevated-privileges

838
推荐指数
12
解决办法
44万
查看次数

为什么我不能将系统时间设置为接近夏令时转换的时间

我的时代,他们正在改变,也就是说,因为我需要他们.我正在测试一些涉及我使用的调度程序的情况,这涉及到夏令时之间转换的行为.

代码

这篇文章我得到了一个工作方法,使我能够以编程方式更改系统日期(重新发布大部分代码):

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

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetSystemTime(ref SYSTEMTIME st);
Run Code Online (Sandbox Code Playgroud)

为了我自己的方便,我只是在我实际调用的函数中包装它:

public static void SetSytemDateTime(DateTime timeToSet)
{
    DateTime uniTime = timeToSet.ToUniversalTime();
    SYSTEMTIME setTime = new SYSTEMTIME()
    {
        wYear = (short)uniTime.Year,
        wMonth = (short)uniTime.Month,
        wDay = (short)uniTime.Day,
        wHour = (short)uniTime.Hour,
        wMinute = (short)uniTime.Minute, …
Run Code Online (Sandbox Code Playgroud)

.net c# timezone datetime dst

11
推荐指数
2
解决办法
1420
查看次数

如何使用.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万
查看次数