Win7 boot up

Source: Internet
Author: User
Tags dotnet throw exception

1. Write the code in the registration form, set the program to start the boot; However, this will require administrator rights, add the program with administrator privileges to start, and not directly into the Software startup interface, UAC control

Code One:

/// <summary>        ///set the application to run automatically/// </summary>        /// <param name= "FileName" >the file name of the application</param>        /// <param name= "Isautorun" >whether to run automatically, or False to cancel Autorun</param>        /// <exception cref= "System.Exception" >throw exception when setting is unsuccessful</exception>         Public Static voidSetautorun (stringFileName,BOOLIsautorun) {RegistryKey reg=NULL; Try{reg= Registry.LocalMachine.OpenSubKey (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true); if(reg = =NULL) Reg= Registry.LocalMachine.CreateSubKey (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run"); if(Isautorun) Reg. SetValue ("Witdashell", FileName); ElseReg. SetValue ("Witdashell",false); Reg.            Close (); }            Catch(Exception ex) {//block error messages that do not have permission            }            finally            {                if(Reg! =NULL) Reg.            Close (); }     }
View Code

Code two:

http://www.cnblogs.com/MaxIE/archive/2013/04/17/3027229.html (Get administrator privileges at startup)

2. Using the Window service

Originally this should be no problem, but the work environment using embedded Wes, do not know which place was deleted by themselves, resulting in all services can not be viewed on the interface above, so I wrote a bunch of code that could be run on the machine, deployed in the test machine when dumbfounded

And do not want to immediately reinstall the test machine operating system environment;

3. Using the Task Scheduler

Code One:

  #if ! DEBUG //  boot start program  dotnet.util Ities. Helper.taskhelper th = new    author  Span style= "color: #800000;" > ", "   boot start software   ", "  startapp   ", Path.Combine (Directory.GetCurrentDirectory (), "  witda. Shell.exe     #endif  
View Code

Code two:

  Public classTaskhelper {/// <summary>        ///Delete Task/// </summary>        /// <param name= "TaskName" ></param>        Private Static voidDeletetask (stringtaskname) {Taskschedulerclass TS=NewTaskschedulerclass (); Ts. Connect (NULL,NULL,NULL,NULL); Itaskfolder folder= ts. GetFolder ("\\"); Folder. Deletetask (TaskName,0); }        /// <summary>        ///Get All Tasks/// </summary>         Public Staticiregisteredtaskcollection getalltasks () {taskschedulerclass TS=NewTaskschedulerclass (); Ts. Connect (NULL,NULL,NULL,NULL); Itaskfolder folder= ts. GetFolder ("\\"); Iregisteredtaskcollection tasks_exists= folder. Gettasks (1); returntasks_exists; }        /// <summary>        ///Check Task isexists/// </summary>        /// <param name= "TaskName" ></param>        /// <returns></returns>         Public Static BOOLIsexists (stringtaskname) {            varIsexists =false; Iregisteredtaskcollection tasks_exists=getalltasks ();  for(inti =1; I <= tasks_exists. Count; i++) {Iregisteredtask T=Tasks_exists[i]; if(T.name.equals (taskname)) {isexists=true;  Break; }            }            returnisexists; }        /// <summary>        ///Create a task/// </summary>        /// <param name= "creator" >name of the person who created the task</param>        /// <param name= "TaskName" >Task Name</param>        /// <param name= "path" >Path of the executing program</param>         Public voidCreatetaskscheduler (stringCreatorstringDescription,stringTaskName,stringpath) {            Try            {                if(Isexists (taskname)) {return; }                //New SchedulerTaskschedulerclass Scheduler =NewTaskschedulerclass (); //Pc-name/ip,username,domain,passwordScheduler. Connect (NULL,NULL,NULL,NULL); //Get Scheduler FolderItaskfolder folder = Scheduler. GetFolder ("\\"); //Set Base attrItaskdefinition task = scheduler. NewTask (0); Task. Registrationinfo.author= Creator;//CreatorTask. Registrationinfo.description = Description;//Descriptiontask. Principal.runlevel=_task_runlevel.                Task_runlevel_highest; //Set Trigger (Idailytrigger Itimetrigger)task. Triggers.create (_task_trigger_type2.                Task_trigger_logon); //Set ActionIexecaction action =(iexecaction) task. Actions.create (_task_action_type.                TASK_ACTION_EXEC); Action. Path=path; Task. Settings.runonlyifidle=true; Task. Settings.executiontimelimit="pt0s";//Run task time timeout stop task? PTOs does not turn on timeoutTask. Settings.disallowstartifonbatteries =false;//only performed on AC powerTask. Settings.runonlyifidle =false;//execute only if the computer is idleTask. Settings.priority =0; Iregisteredtask Regtask=folder. Registertaskdefinition (TaskName, Task, (int) _task_creation. Task_create,NULL,//User                                                                    NULL,//Password_task_logon_type. Task_logon_interactive_token,""); }            Catch(Exception ex) {} }}
View Code

Summarize:

His current status is particularly bad, not a day or two days do not want to do things, I want to prepare, to meet the change; playing games every day is not what you should do for such a large person;

have been playing for one months, not like Caiguai

Win7 boot up

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.