P
P
Pavel Kaptur2016-12-01 20:38:33
C++ / C#
Pavel Kaptur, 2016-12-01 20:38:33

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

1 answer(s)
K
kalapanga, 2016-12-01
@kalapanga

Is Windows 64-bit? Then notepad notepad strife!
There is C:\Windows\System32\notepad.exe and there is C:\Windows\SysWOW64\notepad.exe
Which one runs ShellExecuteEx? If it's 32-bit, then runas might not work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question