ShellExecute or WinExec!!
-
I am trying to call ShellExecute or WinExec in my Win NT service application. When i am running it as simple win32 application, both of the functions executes well but when it is run as service under LocalSystem account, both of them dont work. what to do??? How can i execute another .exe file from current program???? Muhammad Shoaib Khan http://geocities.com/lansolution
-
I am trying to call ShellExecute or WinExec in my Win NT service application. When i am running it as simple win32 application, both of the functions executes well but when it is run as service under LocalSystem account, both of them dont work. what to do??? How can i execute another .exe file from current program???? Muhammad Shoaib Khan http://geocities.com/lansolution
> I am trying to call ShellExecute or WinExec > in my Win NT service application. > ... both of them dont work.
ShellExecute
andWinExec
both work fine and your process gets created. You just don't see the window of your application because it's on a wrong desktop. To modify this tell your service to be interactive: Administrative Tools > Component Services > Services (local) > > double click your service > Tab: "Log On" > Check: "Allow service to interact with desktop" Although you will see the application now, it will still run under the local System account (often unwanted). To modify this behaviour useCreateProcessAsUser
rather thanShellExecute
orWinExec
:STARTUPINFO si;
PROCESS_INFORMATION pi;si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpTitle = NULL;
si.lpDesktop = "WinSta0\\Default";
si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;
si.dwFlags = 0;
si.wShowWindow = SW_SHOW;
si.lpReserved2 = NULL;
si.cbReserved2 = 0;CreateProcessAsUser(hToken,NULL, szMyApp, NULL, NULL, FALSE,
0, NULL, NULL, &si, &pi);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);How to get the security token of a logged-on user? There are several ways, but I usually simply *steal* it from explorer.exe (via
OpenProcessToken
). As an example check thenRunAsLoggedOnUser
function here[^] (=some handy service helper routines from CISCO). RK :)