CodePudding user response:
C # program to realize software boot automatically start two commonly used methodsCodePudding user response:
2. Set the system time///& lt; Summary>
///sets the system time
///& lt;/summary>
///& lt; Param name="d" & gt;
Public static void SetSysDateTime (DateTime d)
{
Try
{
Microsoft, visual basic DateAndTime. Today=d;
Microsoft, visual basic, DateAndTime TimeOfDay=d;
}
Catch {}
}
Add reference Microsoft visual basic
CodePudding user response:
1. As an administrator to run:Public static bool UACCheckCurAdministratorAndRunAs (string [] args)
{
//if it is under xp system class does not handle
If (Environment) OSVersion) Platform==PlatformID. Win32NT & amp; & Environment. OSVersion. Version. Major & lt;=5) return true;
//will pop-up confirmation!!!!!!
/* *
* the user is administrator, start the application directly
* if not administrator, use the start object start procedure, to ensure that the use of an administrator to run
*/
//get the current login Windows users sign
System. Security. Principal. WindowsIdentity identity=System. Security. Principal. WindowsIdentity. GetCurrent ();
System. Security. Principal. WindowsPrincipal Principal=new System. Security. Principal. WindowsPrincipal (identity);
//whether the current login user to administrator
if (! Principal. IsInRole (System. Security. Principal. WindowsBuiltInRole. Administrator))
{
//start creating object
System. Diagnostics. ProcessStartInfo startInfo=new System. Diagnostics. The ProcessStartInfo ();
//set the run file
StartInfo. FileName=System. Windows. Forms. Application. ExecutablePath;
//set the boot parameters
If (args! StartInfo=null). The Arguments=String. Join (" ", args);
//set to start the action, make sure to run as an administrator
StartInfo. Verb="runas";
Try
{
//if not administrator, then start the UAC
System. Diagnostics. Process. The Start (startInfo);
//out
System. Windows. Forms. Application. The Exit ();
return false;
}
Catch
{
}
}
return true;
}
Winform procedure of the program. Cs:
///& lt; Summary>
///the application's main entry point,
///& lt;/summary>
[STAThread]
The static void Main ()
{
Application.EnableVisualStyles();
Application. SetCompatibleTextRenderingDefault (false);
if (! WindowsTools. UACCheckCurAdministratorAndRunAs (null)) return;
.
CodePudding user response:
Do a small program main project set to boot from and when to start to start the applet and then change the system time can don't know