问题
OS: Windows Language: C
I have a requirement such as , I should not change the exe's manifest or the exe file's properties to run it as administrator. Is there any chance in doing my requirement with createprocess/createprocessasuser api. This can be done through shellexecute api, However I need to create my process in suspended state. this can only be done by createprocess or createprocessasuser api. It would be grateful,If some one can guide me in running a program as administrator through these api.
回答1:
I think you're out of luck. ShellExecute will launch the second app elevated either because it has a manifest or because you use the runas
verb. CreateProcess will not.
Perhaps you can use CreateProcess to launch your suspended second app and then that can use ShellExecute to launch the elevated third app that actually does the privileged action? Alternatively you could run the whole suite of apps elevated, or move the functionality into a service which is UAC-exempt.
回答2:
I think the easiest solution would be to route the process you're trying to launch though runas /user:administrator "yourprocess.exe"
or supply the runas
string literal to the second parameter of ShellExecute
. This seems to be an undocumented feature tough.
ShellExecute(
NULL,
_T("runas"),
_T("notepad.exe"),
_T(""), // params
NULL, // directory
SW_SHOW
);
回答3:
It's not possible because it would violate the whole purpose of such a restriction!
Allowing it, even for "good intentions", still constitutes a security breach.
Blockquote Oh come on. Two things: you completely underestimate the bad guys (many of them are quite smart and would not ask such a question), it seems. And also just because someone wants to do "hacky" things doesn't mean it's for malicious purposes. – STATUS_ACCESS_DENIED
来源:https://stackoverflow.com/questions/5744008/is-it-possible-to-run-as-administrator-only-through-code