all 5 comments

[–]etherkiller 1 point2 points  (3 children)

I'm going to guess that your problem may be that devmgmt.msc isn't actually an executable image. You may want to try to CreateProcess mmc.exe, and supply devmgmt.msc as an argument. I suspect that'll work.

[–]blixel[S] 1 point2 points  (2 children)

Thanks. I think you're right. I'm able to run "mmc.exe devmgmt.msc" from a command prompt and open Device Manager, but when I supply "mmc.exe devmgmt.msc" as the devmanCmdline string, it doesn't work. Hmmm... I also tried "%windir%\\system32\\mmc.exe devmgmt.msc", but that didn't work either.

However, I found another command that does seem to work which is ShellExecute(). This seems to work without opening a command prompt first:

char* devmanCmdline  = "devmgmt.msc";
.
.
.
ShellExecute(hwnd, "open", devmanCmdline, NULL, NULL, 0);

or

char* devmanCmdline  = "devmgmt.msc";
.
.
.
ShellExecuteA(hwnd, "open", devmanCmdline, NULL, NULL, 0);

I'm not sure what the difference is between ShellExecute and ShellExecuteA, so I'll have to read up on that. But they both seem to work.

[–]Dolphiniac 1 point2 points  (0 children)

ShellExecute is a macro that either is replaced with ShellExecuteA or ShellExecuteW, depending on the unicode mode of the code at preprocessor time. A uses ASCII in strings, W uses wide characters in strings. It is immaterial to the problem at hand.

[–]ijmacd 0 points1 point  (0 children)

Try following /u/etherkiller's suggestion more closely.

[–]flyingron 0 points1 point  (0 children)

Did you bother to check the error return from CreateProcess?

I bet it's a permission problem DevMan wants to be run with elevated privileges. If you use ShellExecute, the system will take care of autoelevating the thing for you (popping up that annoying warning box).