Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to do windows service in c++ that can access and run .exe file
Posted
Comments
Richard MacCutchan 6-May-14 6:28am    
Fine, what part of the application are you having a problem with.
[no name] 6-May-14 6:42am    
Okay so go ahead and do that.
Mahmoud_Gamal 6-May-14 7:44am    
enta beda
[no name] 6-May-14 8:27am    
And that is supposed to mean what exactly?

The problem are the access rights of the service. It runs under an account which isnt granted to run exe files with UI.

If a service want to run exes than you need to impersonate for launching:

BOOL b = ::LogonUser( pszUser, NULL, password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hToken );
PROCESS_INFORMATION pi = {0};
BOOL b = ::CreateProcessAsUser( hToken, NULL, (LPTSTR) pszCommandLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, NULL, &pi);
 
Share this answer
 
Comments
Mahmoud_Gamal 7-May-14 7:34am    
if i create process like your code is it run or not due to i try this code and no action
KarstenK 7-May-14 8:32am    
you need to provide a full path and a valid user and password on the PC.
Mahmoud_Gamal 7-May-14 8:38am    
yes i do this and also i pass the full exe path in command line and parameter but don't work it should be work as console application not as windows service
KarstenK 7-May-14 8:55am    
it is more complicated, because it can be used for attack. The service has to be an "interactive service"

http://msdn.microsoft.com/en-us/library/ms683502(VS.85).aspx

This may help you:

http://stackoverflow.com/questions/267838/how-can-a-windows-service-execute-a-gui-application

But as I understand all, the proper solution is IPC of an app with the service
Mahmoud_Gamal 7-May-14 9:06am    
yes it is interactive services :D
Try the below link to make the window service in c++
Win service c++

Here you got an idea how to run exe
run exe via win service
 
Share this answer
 
Comments
Mahmoud_Gamal 7-May-14 7:33am    
it doesn't run with me , it run only when i run as console application not as windows service
If you just need to run executable files, why don't you use the Windows Task Scheduler[^]?
 
Share this answer
 
Comments
Mahmoud_Gamal 7-May-14 7:36am    
i want to run exe file from service due to if i restart machine the service automatic run exe file with no need from me to run it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900