I need to run Chrome as admin from plugin dll code(VC++).
But if a chrome window is active ,newly created window didn’t get admin privileges.
I’m calling plugin dll code from JavaScript. After creating new window I closed previous window,but same happens.
I want help, because my plugin needs admin privileges.same in case of Firefox.
(now I’m using shellExecute for creating a new window as admin).
code snippet:
Here I create an instance of Firefox( need similar for all browsers)
StartNewInstance(BSTR Address)
{
// TODO: Add your implementation code here
MessageBox(0,L"Inside",L"ParentName",0);
TCHAR szEXEPath[2048];
GetModuleFileName ( NULL, szEXEPath, 2048 );
SHELLEXECUTEINFO Shex;
ZeroMemory( &Shex, sizeof( SHELLEXECUTEINFO ) );
Shex.cbSize = sizeof( SHELLEXECUTEINFO );
Shex.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
Shex.lpVerb = L"runas";
Shex.lpFile = L"C:\\Program Files\\Mozilla Firefox\\firefox.exe";
Shex.nShow = SW_SHOWNORMAL;
Shex.lpParameters = Address;
ShellExecuteEx( &Shex );
return true;
}
You cannot solve this easily in the way you are trying to. Most browser executables will check for an existing instance and reuse that one if found. There are browser-specific ways to tweak or skip that check via command-line options in order to allow you to spawn a second process, but they are browser-specific, and even some of those browsers are more stuck up than others.
For example, invoking
chrome.exe(as administrator) with--user-data-dir=c:\some\pathwill create a new (elevated) instance the first time it is called, and reuse it on subsequent times provided you give that same user data dir on the command line (even if another (non-elevated)chromeis running all this time with defaults.) The path in question can be anything provided that it exists (you can create it as an empty directory if it doesn’t), and it should be yours, not shared with other applications. It can be temporary.Similarly, invoking
firefox.exe(as administrator) with-no-remote -profile c:\some\pathwill create a new (elevated) instance when called even when an instance with a standard profile is already running, though subsequent invocations must use a different profile path or else Firefox (unlike Chrome) will interactively complain that you are essentially trying to run more than one instances from the same profile directory.You can see from the above that it is possible, but troublesome and error-prone to spawn a new browser window with elevation, which begs the question: what exactly do you need to execute with elevation in that new browser? Does the entire browser really need to run with elevation, or can you delegate “need elevation” functionality to a helper process (that you can easily spawn “as admin” and talk to via the loopback or via named pipe, irrespective of what your host browser is?)