Permissions are not enough, resulting in the inability to modify the system time, so I ran as an administrator, the results of the test success, here is a description of how C # by default as an administrator to run programs
Last blog wrote about how to update the system time through the network time, when writing how to test is not successful, and then think of my operating system (then was developed on the Win8) problem. At that time I guess should be insufficient permissions, resulting in the inability to modify the system time, so I ran as an administrator, the results of the test success! Originally really is the question of permissions, so in the program to add the default as an administrator to run the code. Let's take a look at how to achieve it! programs run as admin by default code: static void Main (string[] Args) { /** * When the current user is an administrator, start the application directly &nbs P * If not an administrator, start the program using the startup object to make sure that you are running */ //Getting the currently logged on Windows user ID System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent (); //Create Windows user theme Application.enablevisualstyles (); System.Security.Principal.WindowsPrincipal Principal = new System.Security.Principal.WindowsPrincipal (identity); //Determine if the current logged-on user is an administrator if (principal). IsInRole (System.Security.Principal.WindowsBuiltInRole.Administrator)) { ///If administrator, run directly Application.enablevisualstyles (); Application.Run (New Form1 ()); } -else //Create Startup Object System.Diagnostics.ProcessStartInfo startinfo = new System.diagnOstics. ProcessStartInfo (); //Set Run file Startinfo.filename = System.Windows.Forms.Application.ExecutablePath; //Set startup parameters Startinfo.arguments = String.Join ("", Args); //Set up startup action to ensure running as Administrator Startinfo.verb = " runas "; //If not an administrator, start uac System.Diagnostics.Process.Start (startinfo); //Exit System.Windows.Forms.Application.Exit (); } } Open the Program.cs file in the assembly and replace the code in the main method with the above code to enable the program to run as an administrator by default. This blog should have been published long ago, but because of the network and other reasons, until now to be published, network problems will soon be resolved, will continue to revert to a weekly update frequency, I hope we continue to pay attention to.