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

  • SEARCH
  • Home
  • 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 6243887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:13:23+00:00 2026-05-24T12:13:23+00:00

I can inject a hook into running processes to catch when they create, destroy,

  • 0

I can inject a hook into running processes to catch when they create, destroy, max/min. But I haven’t come up with a way to catch the creation of a new process so that I can inject my hook into that one.
Does anyone know the best way to accomplish this?

  • 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-05-24T12:13:24+00:00Added an answer on May 24, 2026 at 12:13 pm

    SetWindowsHookEx is your easiest solution.

    If you don’t mind upsetting the anti-virus software, you can also inject a DLL into each process that will then hook CreateProcess (to inject the DLL into further processes) and CreateWindowEx (for your purposes).

    EDIT: I just read your question completely. Yes, you’ll want to just hook CreateProcessW and inject your hook into future processes.

    EDIT #2: I was actually working on something like this yesterday, so some code which does what you want.

    #include <windows.h>
    
    // call GetModuleFileNameto get the full path of the module before installing the hook
    static LPWSTR lpszDllName;
    
    HMODULE LoadModuleEx(__in HANDLE hProcess, __in_z LPCTSTR lpcszDll)
    {
      DWORD   cdwSize;
      LPVOID  lpvAllocation;
      HANDLE  hThread;
      HMODULE hRet;
    
      cdwSize = lstrlen(lpcszDll) + 1;
      cdwSize *= sizeof(TCHAR);
    
      lpvAllocation = VirtualAllocEx(hProcess, NULL, cdwSize, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
      if (lpvAllocation != NULL)
      {
        if (WriteProcessMemory(hProcess, lpvAllocation, lpcszDll, cdwSize, NULL))
        {
          hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibrary, lpvAllocation, 0, NULL);
          if (hThread != NULL)
          {
            GetExitCodeThread(hThread, (LPDWORD)&hRet);
            CloseHandle(hThread);
          }
        }
        VirtualFreeEx(hProcess, lpvAllocation, cdwSize, MEM_DECOMMIT);
      }
      return hRet;
    }
    
    // hook future process creation - install this hook on top of CreateProcessW
    // I'd suggest using Microsoft Detours [http://research.microsoft.com/en-us/projects/detours/]
    BOOL WINAPI CreateProcessWHook(__in_opt LPCWSTR lpApplicationName, __inout_opt LPWSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCWSTR lpCurrentDirectory, __in LPSTARTUPINFO lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation)
    {
      // create the process suspended
      if (dwCreationFlags & CREATE_SUSPENDED != CREATE_SUSPENDED)
        dwCreationFlags |= CREATE_SUSPENDED;
    
      // call original CreateProcessW
      BOOL bRet = _CreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);
      if (bRet)
      {
        // inject DLL
        LoadModuleEx(lpProcessInformation->hProcess, lpszDllName);
    
        // resume thread
        ResumeThread(lpProcessInformation->hThread);
      }
    
      return bRet;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The vb6 code I am using can inject an application into a running process.
Is there any way we can inject new methods and properties into classes during
How can I use the Prototype library and create unobtrusive javascript to inject the
I have a strange problem. Afaik I can inject a SessionScoped bean into a
Is there any tool which can inject into an .exe or .dll information like
Does anyone know if I can inject value from pages.xml into a Seam component?
Using Mootools, we can inject an element into another element: $('childID').inject($('parentID'), 'top'); The second
I wonder, if I can inject a list of (stateless) beans, that all implementing
I can't seem to figure out how to inject a disabled element. Any help
When using Ninjects ConstructorArgument you can specify the exact value to inject to specific

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.