Search code examples
c++runas

C++ Windows - fill password field of system("run as")


I know there are many other ways to do this but I want to know how to fill in the password question of the windows the run as command automatically.

system("runas /user:\"benedikt\" \"xy.exe\"");

is there any way to do this? I googled a long time but i only found a lot of tools doing wat I want to do and not a way to do this for myself. PS: I do not want to use any .Net functions.


Solution

  • OK, I'm going out on a limb here, because I'm not 100% sure that there isn't some (convoluted) way to achieve what you are looking for using stock runas. However, Why doesn't the RunAs program accept a password on the command line?, suggests there isn't - deliberately so to prevent "security issues" with plain-text passwords in command lines, batch files and tools that can view a command line (like Process Explorer).

    BTW, a simple echo <password> | runas /user:<user> <command> doesn't seem to work either (it skips over the prompt for the password, but the password itself is not read by runas it seems).

    So I guess you have to resort to some other means, like using the real API behind it all: CreateProcessWithLogin.