File Exception, Access is denied - prompting for administrator's rights
Dennis
dkorpel at gmail.com
Tue Jun 4 20:44:52 UTC 2019
On Tuesday, 4 June 2019 at 16:30:41 UTC, BoQsc wrote:
> Is there any way to prompt for administrator's rights, to save
> the additional effort of lots of clicks?
Looking at:
https://stackoverflow.com/questions/31844584/is-there-an-api-call-to-prompt-user-for-uac-elevation
You can try something like this:
```
import core.sys.windows;
SHELLEXECUTEINFO shex;
shex.cbSize = shex.sizeof;
shex.lpVerb = "runas"; // runas, open
shex.lpFile = "rdmd";
shex.lpParameters = `"--eval=copy("""test.txt""","""C:/Program
Files/test.txt""")"`;
shex.nShow = SW_SHOW; //SW_HIDE;
shex.fMask = SEE_MASK_NOCLOSEPROCESS;
BOOL retshx = ShellExecuteEx(&shex);
import core.Thread: Thread, msecs;
// Give it 5 seconds to finish
if (retshx) {
int count = 0;
DWORD exitCode;
do {
if (!GetExitCodeProcess(shex.hProcess, &exitCode)) break;
if (count++ < 50) {
Thread.sleep(100.msecs);
} else break;
}
while (exitCode != STATUS_WAIT_0); // STILL_ACTIVE
CloseHandle(shex.hProcess);
}
```
Here I use rdmd with --eval, but you can use any program that
does the file handling you want.
Note that lpParameters has weird escape rules: parameters are
space separated unless quoted with ", and to get actual quotes
you use three of them like """.
More information about the Digitalmars-d-learn
mailing list