Launching file from service..

delphi package - easy access to kernel objects etc.
Post Reply
Jeff_Lawton
Posts: 7
Joined: Tue Jul 20, 2004 8:20 pm
Location: Sacramento, CA
Contact:

Launching file from service..

Post by Jeff_Lawton »

I have a small little service running that waits for a user to log in then launches my application.

Code: Select all

  If TrayWindow.Enabled then 
  begin 
    if not ProcessActive('project1.exe') then  // look to find process
      NewProcess('c:\project1.exe');
  end;
Everything runs fine.. But if the user does a "START / Log Off / Switch User" and they choose a new user. The app will never launch in the new session of windows.

Is there a way to get a process listing for the current session of windows?

I have tried the follwing :

process('project1.exe').isvalid;

Looping through all Processes.ItemCount and checking them, and I have also looped through the TaskbarWindows. All of those methods seem to still see that the exe is running in the other session.

Oddly if I stop the sevice, log in as the second user, then start the service while on as the second user the program gets launched, but on the first users account, so when I switch back to the first user the program is running.

How do I get the app to lauch under the correct user, and scan through processes that are for the current user session?

Regards,

Jeff Lawton
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Right now madKernel doesn't give you the possibility to ask for session IDs. I should really add a property like "IProcess.SessionID" (have added that to my to do list).

For now you can help yourself by using madRemote.EnumProcesses. This gives you the session ID of each process. Furthermore you can use madCodeHook.GetCurrentSessionId and madCodeHook.GetInputSessionId to get more information about the session situation.

About your other question: The service will probably start whatever process it starts in the same user context as it is running itself in. You should probably use LogonUser + CreateProcessAsUser, or maybe CreateProcessWithLogonW to start a process in the context of a different user context. I don't know the details, though...
gemini
Posts: 5
Joined: Wed Dec 14, 2005 4:40 pm

Post by gemini »

Dear Madshi/Jeff,

Have u guys found out about the solution to this problem???
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Which problem do you mean exactly?
Post Reply