Working on a helper windows process in Win7 with VC++ 10.0. I want the service to start a process if it's not started, but both CreateProcess() and ShellExecute() fail. I thought, it's fine as long as I could create a startup entry in the registry, but no luck. I know it works because the line right before it begins the registry line, creates a file called 'hello.txt' in C:, and it does.
Is there a reason it cannot execute or create processes, or write to the registry (HKLM)? I'm an admin so i don't think it's a priviledge thing.
If it is so, then you cannot launch child processes in interactive desktop. There is a way by "stealing" autentication token from a process that already runs there (explorer.exe for example or winlogon.exe if you want administrator rights without UAC intervention) and then spawn the child process as usual using CreateProcessAsUser().
So Modoran, how would I use that technique using CreateProcessAsUser() to spawn a process? Would I just use the admin user or what? I don't want users to have to change a bunch of settings to get it to work.
Would I just use the admin user or what? I don't want users to have to change a bunch of settings to get it to work.
The sample code uses the same access level as winlogon.exe (administrator privileges). Just use HKEY LOCAL MACHINE to store the settings you need if you don't want other users to change them.
Beginning to think it's not possible on Windows7
It is perfectly possible in windows 7.
Put ALL your code inside child.exe, NOT inside the service itself.
I'm reading through the source and can't tell, since the author says it's communicating between a client and service, does it require any messages sent between the service and app?
Well, a service is always running, even if no user is logged on.
It all depends of what you want to do, tehnically it is no required to communicate between a service and client app, but for most practical cases this is almost the case.
What else do you need a service in the first place if you don't want/need to communicate with it ?
You say in your first post:
I want the service to start a process if it's not started,
Yes, but in what conditions ? At user logged on ? Why not use Run registry key or Startup folder then ?
I just need a helper service. I'm going to have the service check periodically to see if a process is running, for example, test.exe. If test.exe is not in the list of running process, it creates the process again. That's all I need it to do.
EDIT: Hell yea I think I got it, I just used the function from the code you sent me. Well, I got it open a process finally (notepad.exe).
Question for you, should the service be able to check if a process is running or not? I haven't implemented the code yet, but right now there's no communication between the processes, which I don't really need, like I said above.