Answer the question
In order to leave comments, you need to log in
What is the difference between launches?
Good evening! There is the code below, and it allows you to run a program, in this case notepad, as an administrator, but there is a slight difference. If I run the program like this, notepad will open for me, but I won't be able to edit SystemRoot%\system32\drivers\etc\hosts. If I select notepad at the start and run it as administrator, through the right button, then I can edit this file. What is the difference? And how to programmatically get the behavior like "run as administrator" on the right button.
#include <windows.h>
int WINAPI wWinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nShowCmd)
{
SHELLEXECUTEINFO shExInfo = { 0 };
shExInfo.cbSize = sizeof(shExInfo);
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExInfo.hwnd = 0;
shExInfo.lpVerb = TEXT("runas");
shExInfo.lpFile = TEXT("notepad.exe"); // Application to start
shExInfo.lpParameters = TEXT(""); // Additional parameters
shExInfo.lpDirectory = 0;
shExInfo.nShow = SW_SHOW;
shExInfo.hInstApp = 0;
ShellExecuteEx(&shExInfo);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question