Skip to content

Latest commit

 

History

History
277 lines (201 loc) · 8.24 KB

procthread.md

File metadata and controls

277 lines (201 loc) · 8.24 KB

Processes and threads

Contents

Reference

Functions

CreateUserAccountProcess

  • It's better using Wini32Ex::System::Session::NewProcess method than this funtion.
  • Example
    • Creating a user account process in the current session.

      #include <Win32Ex/System/Process.h>
      
      CreateUserAccountProcess(WTSGetActiveConsoleSessionId(), NULL, TEXT("CMD.exe /C QUERY SESSION"), /* ... */);    

CreateSystemAccountProcess

  • It's better using Wini32Ex::System::Session::NewProcess method than this funtion.
  • Example
    • Creating a system account process in the current session.

      #include <Win32Ex/System/Process.h>
      
      CreateSystemAccountProcess(WTSGetActiveConsoleSessionId(), NULL, TEXT("CMD.exe /C QUERY SESSION"), /* ... */);    

CreateUserAccountProcessT<typename CharType>

  • C++ only
  • It's better using Wini32Ex::System::Session::NewProcess method than this funtion.
  • Example
    • Creating a user account process at the current session.

      #include <Win32Ex/System/Process.h>
      
      CreateUserAccountProcessT<CHAR>(WTSGetActiveConsoleSessionId(), NULL, "CMD.exe /C QUERY SESSION", /* ... */);

CreateSystemAccountProcessT<typename CharType>

  • C++ only
  • It's better using Wini32Ex::System::Session::NewProcess method than this funtion.
  • Example
    • Creating a system account process at the current session.

      #include <Win32Ex/System/Process.h>
      
      CreateSystemAccountProcessT<CHAR>(WTSGetActiveConsoleSessionId(), NULL, "CMD.exe /C QUERY SESSION", /* ... */);

Classes

Process

  • ProcessT<Win32Ex::String>
  • Example
    • Attach Process by process id, process handle.

      #include <Win32Ex/System/Process.hpp>
      
      DWORD pid = ...
      Win32Ex::System::Process process(pid);
      if (process.IsAttached())
      {
      process.ExecutablePath();
      }
      
      HANDLE hProcess = ..
      Win32Ex::System::Process process(Win32Ex::System::ProcessHandle::FromHANDLE(hProcess));
      if (process.IsAttached())
      {
      process.ExecutablePath();
      }
    • Enumerate all processes.

      #include <Win32Ex/System/Process.hpp>
      
      for (auto process : Win32Ex::System::Process::All())
      {
          if (process)
          {
              if (process->IsAttached())
                  std::cout << "[Attached] PID :" << process->Id() << "\t\tPATH : " << process->ExecutablePath() << '\n';
              else
                  std::cout << "PID :" << process->Id() << "\t\tPATH : " << process->ExecutablePath() << '\n';
          }
          }

ProcessW

  • ProcessT<Win32Ex::StringW>

ProcessT<class StringType = Win32Ex::StringT>

  • Implements WaitableObject.

RunnableProcess

  • Abstract
  • RunnableProcessT<Win32Ex::String>
  • Example
    • Use the RunnableProcess class to run 'user account process'.

      #include <Win32Ex/System/Process.hpp>
      // It's better using the Wini32Ex::System::Session::NewProcess method than this class.
      Win32Ex::System::UserAccountProcess process("CMD", "/C WHOAMI");
      Win32Ex::System::RunnableProcess &runnable = process;
      runnable.Run();

RunnableProcessW

  • Abstract
  • RunnableProcessT<Win32Ex::StringW>

RunnableProcessT<class StringType = Win32Ex::StringT>

  • Abstract
  • Implements ProcessT.

UserAccountProcess

  • RunnableSessionProcessT<UserAccount, Win32Ex::String>
  • It's better using Wini32Ex::System::Session::NewProcess method than this class.
  • Example
    • Creating a user account process at the current session.

      #include <Win32Ex/System/Process.hpp>
      
      Win32Ex::System::UserAccountProcess process("CMD.exe");
      process.Run("/C QUERY SESSION");
      
      auto waiter = process.RunAsync("/C QUERY SESSION");
      waiter.Wait();
    • Runs user account process at each sessions.

      #include <Win32Ex/System/Process.hpp>
      
      PWTS_SESSION_INFO sessionInfo = NULL;
      DWORD count = 0;
      if (WTSEnumerateSessions(WTS_CURRENT_SERVER, 0, 1, &sessionInfo, &count))
      {
      for (DWORD i = 0; i < count; ++i)
      {
          Win32Ex::System::UserAccountProcess process(sessionInfo[i].SessionId, "CMD", "/C QUERY SESSION");
          process.Run();
      }
      }
    • Tests standard output and standard input.

      Win32Ex::System::UserAccountProcess process("cmd /c more");
      process.RunAsync();
      process.StdIn() << "test 1\n";
      process.StdIn() << "test 2\ntest 3\n";
      process.StdIn().Close();
      std::cout << process.ExecutablePath();
      std::cout << process.StdOut().ReadAll();

UserAccountProcessW

UserAccountProcessT

SystemAccountProcess

SystemAccountProcessW

SystemAccountProcessT

  • Implements RunnableProcessT.

RunnableSessionProcessT<ProcessAccountType Type, class StringType = Win32Ex::StringT>

ElevatedProcess

  • ElevatedProcessT<Win32Ex::String>
  • Example
    • Creating a with elevated permissions UAC.

      #include <Win32Ex/System/Process.hpp>
      
      Win32Ex::System::ElevatedProcess process("notepad.exe");
      process.Run();

ElevatedProcessW

  • ElevatedProcessT<Win32Ex::StringW>

ElevatedProcessT<class StringType = Win32Ex::StringT>

  • Implements RunnableProcessT.

Namespaces

ThisProcess

  • Example
    • Enumerate parent processes.

      #include <Win32Ex/System/Process.hpp>
      
      Win32Ex::System::Process parent = Win32Ex::ThisProcess::Parent();
      while (parent.IsValid())
      {
          std::cout << parent.ExecutablePath() << '\n';
          parent = parent.Parent();
      }