一旦我的程序安装在客户端计算机上,如何强制我的程序在Windows 7上以管理员身份运行?
我的时代,他们正在改变,也就是说,因为我需要他们.我正在测试一些涉及我使用的调度程序的情况,这涉及到夏令时之间转换的行为.
从这篇文章我得到了一个工作方法,使我能够以编程方式更改系统日期(重新发布大部分代码):
[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) 我正在尝试使用以下内容更新系统时间:
[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)