SetDate of system from inside of our program
-
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);By the above code I can change the system date of many version of MicroSoft Windows 7, but doesn't work on all of them. Do I miss something?
-
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);By the above code I can change the system date of many version of MicroSoft Windows 7, but doesn't work on all of them. Do I miss something?
As this call requires the SE_SYSTEMTIME_NAME privilege, I suspect you've hit a permissions issue.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
"Mind bleach! Send me mind bleach!" - Nagy Vilmos
CodeStash - Online Snippet Management | My blog | MoXAML PowerToys | Mole 2010 - debugging made easier
-
[DllImport("kernel32.dll", EntryPoint = "SetSystemTime", SetLastError = true)]
public extern static bool Win32SetSystemTime(ref SystemTime sysTime);By the above code I can change the system date of many version of MicroSoft Windows 7, but doesn't work on all of them. Do I miss something?
Only an administrator account can change the system time. If your code is launched by a normal user it's not going to work.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak