Program Resource

Resource libraries for programmers and developers

[C++]Run command within program without showing window / Takeown example

When developing simple tool or doing automation, calling shell command might be easy and fast. However, calling “cmd /c” with ShellExecute brings up shell window, and might return to code before command completes. In such case, use CreateProcess to call cmd. You can hide shell window and wait for process to complete, and even get return value by using CreateProcess API. Below is simple sample code for calling takeown command, which is a command to take ownership of system files which can’t be modified even with Administrator privilege.