سؤال

In my application I have one service which is launching one exe.

In service code I am launching exe with ShellExecuteEx command as :

BOOL bLaunched = false;



       SHELLEXECUTEINFO ex;
       memset(&ex, 0, sizeof(ex));
       ex.cbSize       = sizeof(ex);
       ex.fMask        = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
       ex.hwnd         = ::GetDesktopWindow();
       ex.lpVerb       = _T("open");
       ex.lpParameters = params;
       ex.lpDirectory  = path;
       ex.nShow        = SW_SHOWNORMAL;
       ex.lpFile       = appName;

       bLaunched = ShellExecuteEx(&ex);
       return bLaunched;

After ShellExecuteEx call I can see that exe in task manager and when I try to attach that exe to VS debugger and break it ,it show me message "the process appears to be deadlocked(or is not running any user-mode code).All threads have been stopped"

VS debugger shows green arrow pointed to first line in winMain funciton.

This only happening when I try to launch that exe from a service. When I try to launch that exe from sample application with same set of params it works fine .

Any suggestion why its not working in case of service.

Updates: I figured it out.I was calling MessageBox in the exe.I removed MessageBox and it executed fine. It looks like calling windows related functions caused that issue. Actually service was running in Local System account and exe launched from that service .So can we not call window functions from Local system account.

One more issue I am facing now.In the exe it is not able to open registry to read values.I am trying to open HKCU but it failed.

هل كانت مفيدة؟

المحلول

You are attempting to launch an executable that interacts with the desktop. Services run in session 0 which is a non-interactive session. You'll need to make sure that any processes that you start in that session do not interact with the desktop.

As an aside, you should never ever pass the desktop window as an owner window: http://blogs.msdn.com/b/oldnewthing/archive/2004/02/24/79212.aspx.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top