Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7870227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:33:34+00:00 2026-06-03T01:33:34+00:00

There is a self deleting program #include <windows.h> #include <stdio.h> void main(int argc, char*

  • 0

There is a self deleting program

#include <windows.h>
#include <stdio.h>

void main(int argc, char* argv[])
{
    STARTUPINFO si = {0};
    PROCESS_INFORMATION pi = {0};
    si.cb = sizeof(si);

    if (argc == 1)
    {
        SECURITY_ATTRIBUTES sa;
        sa.nLength = sizeof(sa);
        sa.lpSecurityDescriptor = NULL;
        sa.bInheritHandle = TRUE;

        CopyFile(argv[0], "1.exe", FALSE);
        MoveFile(argv[0], "2.exe");

        CreateFile("1.exe", 0, FILE_SHARE_READ, &sa, 
            OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);

        CreateProcess(NULL, "1.exe x", NULL, NULL, 
            TRUE, 0, NULL, NULL, &si, &pi);
    }
    else if (argc == 2)
    {
        while(!DeleteFile("2.exe"));

        CreateProcess(NULL, "net", NULL, NULL, TRUE, 
            DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
    }
}

If I remove this :CreateProcess(NULL, "net", NULL, NULL, TRUE, DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
it can’t work.
Could anyone explain to me how it works?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:33:36+00:00Added an answer on June 3, 2026 at 1:33 am

    Here’s an explanation (as I understand things)

    void main(int argc, char* argv[])
    {
        STARTUPINFO si = {0};
        PROCESS_INFORMATION pi = {0};
        si.cb = sizeof(si);
    
        if (argc == 1)
        {
            SECURITY_ATTRIBUTES sa;
            sa.nLength = sizeof(sa);
            sa.lpSecurityDescriptor = NULL;
            sa.bInheritHandle = TRUE;
    
            // Make a copy of ourselves which we'll use to delete the version we were run from
            CopyFile(argv[0], "1.exe", FALSE);
    
            // Rename the running copy of ourself to another name
            MoveFile(argv[0], "2.exe");
    
            // Make sure we delete the copy of ourselves that's going to delete us when we die
            CreateFile("1.exe", 0, FILE_SHARE_READ, &sa, OPEN_EXISTING, FILE_FLAG_DELETE_ON_CLOSE, NULL);
    
            // Invoke the process that will delete us
            // allowing it to inherit the handle we just created above.
            CreateProcess(NULL, "1.exe x", NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
        }
        else if (argc == 2)
        {
            // Wait for the original program to die (deleting us and closing a handle), then delete it
            while(!DeleteFile("2.exe"));
    
            // Launch a child process which will inherit our file handles
            // -- This keeps the file handle with FILE_FLAG_DELETE_ON_CLOSE (which we inherited) alive beyond our lifetime
            // this allowing us to be deleted after we've died and our own handle is closed.
            CreateProcess(NULL, "notepad", NULL, NULL, TRUE, DEBUG_ONLY_THIS_PROCESS, NULL, NULL, &si, &pi);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should I always release self when there is a failure inside init, or should
I was wondering if there was a way to convert a self subquery to
Are there any performance/other implications in having an object relates to itself? (self join)
Is there a difference between filter and exclude in django? If I have self.get_query_set().filter(modelField=x)
Is there a difference in usage between class Helper class << self # ...
When I call self::$parameter = 1; the __set is not called. Is there a
The short question, is there an off the self function to make a graph
I have a problem with my self-made search page. There is 2 tables: **name
I have a client running an ASP.NET application. Inside of that, there's a self-contained
I have a main dialog and on that dialog there is a button. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.