One C # Small instance per day --- C # automatically execute the program upon startup

Source: Internet
Author: User

Wow, hey, a variety of abnormal needs, this time the entire boot automatically runs the 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.

Using Microsoft. Win32;
Using System. IO; then let's start and prepare the location of our instance. There are two ways to get the running directory,

First, splicing

// Obtain the current path of the file
String dir = Directory. GetCurrentDirectory ();
// Obtain all the paths of the executable file
String exeDir = dir + @ "\ SetStart.exe"; hey, you can do the same.

String strName = Application. executablePath; of course, we are going to operate the Registry. Hey hey, use the 360 guard to test it to prevent me from restarting the computer. Haha, of course, you can also view the following input msconfig

 

Hey. Okay. Now we get our file.

Declare a field that can use the registry.

RegistryKey reg = null; then we open the Registry

Reg = Registry. LocalMachine. OpenSubKey ("SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true); of course, if there is no such thing, you can create it,

If (reg = null)
Reg = Registry. LocalMachine. CreateSubKey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run"); OK, you can write the Registry value.

If (isAutoRun)
{
Reg. SetValue (name, fileName );
MessageBox. Show ("black screen is available when boot is enabled", "prompt", MessageBoxButtons. OK, MessageBoxIcon. Information );
} OK, complete, encapsulate it.

Public static void SetAutoRun (string fileName, bool isAutoRun)
{
RegistryKey reg = null;
Try
{
If (! File. Exists (fileName ))
{
Throw new Exception ("What should I do if I 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 when boot is enabled", "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. 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.

 

Author: "ASP. NET Self-taught blog"
 

Related Article

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.