Unable to launch executable through windows service but visible in task manager in Windos 7 OS.
Hi, I've a windows service through which i'm trying to open notepad using ShellExecute() API. Following is the code snippet ::ShellExecute(NULL, NULL,_T("C:\\Windows\\System32\\notepad.exe"), _T("C:\\Users\\testuser\\Desktop\\test.txt"), _T("C:\\Windows\\System32"), SW_SHOWNORMAL); After excution of application , notepad.exe is visible in processes in task manager but not launched. Can anybody please let me know why the notepad is not getting launched? Also, this problem occurs only in Windows 7 OS and it works fine in Windows XP OS. Thanks, Pooja Sethi
July 19th, 2011 2:01am

Try this... :) Retval = ShellExecute(Me.hwnd, "open", "C:\Windows\System32\notepad.exe", "C:\Users\testuser\Desktop\test.txt", "C:\Windows\System32", SW_SHOWNORMAL)
Free Windows Admin Tool Kit Click here and download it now
July 19th, 2011 2:56am

Thanks for your instant reply. I have tried in the way you told. but it did not work. Also additional to this I used ::ShellExecute() as below: ::ShellExcute(::GetDesktopWindow(), "open", "C:\Windows\System32\notepad.exe", "C:\Users\testuser\Desktop\test.txt", "C:\Windows\System32", SW_SHOWNORMAL); but still it not helped. Please see below details regarding my requirement and execution environment [Environment] OS - Windows 7 Development Env. -VS2008 (C++) (With admin privileges) Login: - Always as Administrator [Requirement] Create a service. When service is launched, through that service I would like to invoke an application say Notepad.exe. [Observation] In my sample application (Sample.exe) I have created an interactive windows service, which would launch the Notepad.exe. To invoke the Notepad.exe I used ::ShellExcute() API, which I think is the correct method to achieve my purpose. But I have certain observation: - The required application (Notepad.exe) is launched but it is not visible where as it is present in Task Manager. - The return value of ShellExecute() is zero (indicate SUCCESS). - In Task manager the Session ID of my Sample.exe has become Zero which initially was non-zero value. - The Session ID of the launched application (Notepad.exe) is also zero. Please let me know: 1. Why is the notepad not visible? 2. Is it related to session ID? 3. Why is the Session ID of Sample.exe has become zero? 4. Why is the Session ID of Notepad.exe is zero when launched through service? 5. Is this any kind of Window 7 authentication or environment issue? I also have tried with ::ShellExecuteEx(), CreateProcess() and CreateProcessAsUser() but the observation is same. Thanks in advance. Pooja
July 29th, 2011 9:36am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics