How to create a process in C++ on Windows?

regasm.exe(Assembly Registration Tool) makes changes to the Windows Registry, so if you want to start regasm.exe as elevated process you could use the following code: #include “stdafx.h” #include “windows.h” #include “shellapi.h” int _tmain(int argc, _TCHAR* argv[]) { SHELLEXECUTEINFO shExecInfo; shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shExecInfo.fMask = NULL; shExecInfo.hwnd = NULL; shExecInfo.lpVerb = L”runas”; shExecInfo.lpFile = L”regasm.exe”; shExecInfo.lpParameters … Read more

Print PDF document with python’s win32print module?

I ended up using Ghostscript to accomplish this task. There is a command line tool that relies on Ghostscript called gsprint. You don’t even need Acrobat installed to print PDFs in this fashion which is quite nice. Here is an example: on the command line: gsprint -printer \\server\printer “test.pdf” from python: win32api.ShellExecute(0, ‘open’, ‘gsprint.exe’, ‘-printer … Read more

DoEvents equivalent for C++?

DoEvents basically translates as: void DoEvents() { MSG msg; BOOL result; while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE ) ) { result = ::GetMessage(&msg, NULL, 0, 0); if (result == 0) // WM_QUIT { ::PostQuitMessage(msg.wParam); break; } else if (result == -1) { // Handle errors/exit application, etc. } else { ::TranslateMessage(&msg); :: DispatchMessage(&msg); } … Read more

How can I read a child process’s output?

There are a few bugs in your code, but the most important is that you’ve specified FALSE for the bInheritHandles argument to CreateProcess. The new process can’t use the pipe if it doesn’t inherit the handle to it. In order for a handle to be inherited, the bInheritHandles argument must be TRUE and the handle … Read more

Getting a list of user profiles on a computer in C++ Win32

Before going the undocumented route like flokra suggests, I would try NetUserEnum() or NetQueryDisplayInformation() If you want to go into undocumented land, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList has a (incomplete) list of accounts (It’s missing special accounts like ASPNET, HelpAssistant and SUPPORT_xxxx) It also has the path to the profile folder, which is a lot safer than using … Read more

Windows Media Foundation recording audio

I apologize for the late response, and I hope you can still find this valuable. I recently completed a project similar to yours (recording webcam video along with a selected microphone to a single video file with audio). The key is to creating an aggregate media source. // http://msdn.microsoft.com/en-us/library/windows/desktop/dd388085(v=vs.85).aspx HRESULT CreateAggregateMediaSource(IMFMediaSource *videoSource, IMFMediaSource *audioSource, IMFMediaSource … Read more

C++ Win32 keyboard events

Key logger applications use mechanisms such as Win32 Hooks. Specifically you need to set a WH_KEYBOARD hook. There are move advanced techniques, like creating your own keyboard driver but for a start hooks are a good choice. Edit: To get an idea of how a hook procedure looks like, I post a fragment from my … Read more

Handling AeroSnap message in WndProc

I’m guessing there aren’t any special messages here; Aero is likely just using the plain Win32 APIs – ShowWindow(SW_MAXIMIZE) and similar. The thing to uderstand with the SC_ messages are that those are requests from a menu asking the window to resize/restore/etc itself, but that is not the only mechanism for changing the windows’s size. … Read more

Waiting for grandchild processes in windows

Create a Job Object with CreateJobObject. Use CreateProcess to start UninstallA.exe in a suspended state. Assign that new process to your job object with AssignProcessToJobObject. Start UninstallA.exe running by calling ResumeThread on the handle of the thread you got back from CreateProcess. Then the hard part: wait for the job object to complete its execution. … Read more