Kingdz changed to cainiao, one C # Small instance every day-C # automatically execute the program upon startup

Source: Internet
Author: User

Wow, hey, all kinds of abnormal demands. This time the whole system runs automatically at startup.Program. Don't say I'm bad. Hey hey, C # can also start to run the drip automatically. It's starting, wow, the whole blue screen, or the whole black screen, it's always black, the buddy needs to go to each new monitor. Wow, haha. This instance is dedicated to Yin, hey.

The name of this instance is "auto-running software upon startup". It is implemented using C #. This instance has no difficulty. It just adds a little bit of fun to our C # learning path.

First, we should make preparations. Of course, we will introduce the namespace.

 
UsingMicrosoft. Win32;UsingSystem. IO;

Then, let's get ready. There are two ways to get the running directory from the instance location,

First, splicing

 
// Obtain the current path of the fileStringDir =Directory. Getcurrentdirectory ();// Obtain all the paths of the executable fileStringExedir = dir +@ "\ Setstart.exe";

Hey, you can do the same.

StringStrname =Application. Executablepath;

Of course, we are going to operate the Registry. Hey hey, here we will use the 360 guard to test it to prevent me from restarting the computer. Haha Of course, you can also view it by inputting msconfig below.

Hey. Okay. Now we get our file.

Declare a field that can use the registry.

 
RegistrykeyReg =Null;

Then open the registry.

 
Reg =Registry. Localmachine. opensubkey ("Software \ Microsoft \ Windows \ CurrentVersion \ Run",True);

Of course, what should I do if I don't do it,

If(REG =Null) Reg =Registry. Localmachine. createsubkey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run");

Okay, you can write the registry value.

 
If(Isautorun) {Reg. setvalue (name, filename );MessageBox. Show ("Black screen is available for Boot","Prompt",Messageboxbuttons. OK,Messageboxicon. Information );}

OK.

 Public static void Setautorun ( String Filename, Bool Isautorun ){Registrykey Reg = Null ; Try { If (! File . Exists (filename )){ Throw new  Exception ( "What do you do if you have this file" );} String Name = filename. substring (filename. lastindexof ( @"\" ) + 1); 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 (name, filename ); MessageBox . Show ( "Black screen is available for Boot" , "Prompt" ,Messageboxbuttons . OK, Messageboxicon . Information );} Else Reg. setvalue (name, False );} Catch ( Exception Ex ){ Throw new  Exception (EX. tostring ());} Finally { If (Reg! = Null ) {Reg. Close ();}}}

Of course, I just implemented it for a moment. Hey hey, you can do it yourself

Every 3 seconds, the pop-up window tells you that you have been spoofed! (This window cannot be closed );

You cannot use CTRL + ALT + DEL to open the Task Manager (meaning you are running, unless you restart it, or you don't want to close it !)

...... Drinking black, I still don't want to talk about it. Prevent management from being banned.

Last served

At last, the administrator privilege is required to operate the registry. Therefore, make sure that the program runs with the permissions of the operator.

I like communication and programming. This is a programmer in kingdz. Hahaha

CodeDownload

Setstart.rar

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.