Background: We have a Control Panel applet written in C, and a windows service. The applet writes values to the registry that are read by the service. Because it's a service the registry entries are in HKEY_LOCAL_MACHINE, which means the applet needs admin rights to write them. The workaround is to run Control Panel as administrator, but it's annoying to have to explain to customers how to do this (and why).
Attempted solution: After extensive reading the only solution I can find is for the applet to use ShellExecute to run a second session of itself with admin rights, thus:
HINSTANCE result = ShellExecute(NULL, _T("runas"), _T("C:\\Windows\\SysWOW64\\rundll32.exe"), _T("shell32.dll,Control_RunDLL C:\\...\\applet.CPL"), NULL, SW_SHOW);
However, the call to ShellExecute simply hangs.
As a test, I tried replacing the above line with:
HINSTANCE result = ShellExecute(NULL, _T("open"), _T("C:\\Windows\\System32\\notepad.exe"), NULL, NULL, SW_SHOW);
but that hangs as well.
Any suggestions gratefully received.