Running an exe from Windows Services
-
Hi All, I wrote a C++ program which will create a service in windows. By starting that service I want to run a particular .exe The issue here is that, after starting that service, that .exe is running in the task manager but the application window is not visible. I am giving the .exe path as a command line argument while executing the C++ exe. rgds., Surendran
-
Hi All, I wrote a C++ program which will create a service in windows. By starting that service I want to run a particular .exe The issue here is that, after starting that service, that .exe is running in the task manager but the application window is not visible. I am giving the .exe path as a command line argument while executing the C++ exe. rgds., Surendran
If the service is running under a system account (SYSTEM, LocalService, etc.) then its child processes do too and they aren't visible by default on the interactive desktop. I believe the recommended way to run an app interactive is
CreateProcessAsUser()
. You shouldn't run the EXE as interactive and running in the service's account because that a) won't work in Vista and b) opens you up to elevation of priv attacks in pre-Vista.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
If the service is running under a system account (SYSTEM, LocalService, etc.) then its child processes do too and they aren't visible by default on the interactive desktop. I believe the recommended way to run an app interactive is
CreateProcessAsUser()
. You shouldn't run the EXE as interactive and running in the service's account because that a) won't work in Vista and b) opens you up to elevation of priv attacks in pre-Vista.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Mike, Thanks for the info. In the CreateProcessAsUser( hToken, NULL, "cmd.exe" or cmdline args, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi ) This I got from one site, I want to know, apart from calling this function, anyotherfunction needs to be called?And for the "htoken" parameter any objects or assignments needs to be done? and FYI is now I am using CreateProcess method in the program Thanks N.Surendran
-
Mike, Thanks for the info. In the CreateProcessAsUser( hToken, NULL, "cmd.exe" or cmdline args, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi ) This I got from one site, I want to know, apart from calling this function, anyotherfunction needs to be called?And for the "htoken" parameter any objects or assignments needs to be done? and FYI is now I am using CreateProcess method in the program Thanks N.Surendran
I ran across this blog post[^] yesterday, which has some info about using
CreateProcessAsUser()
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
-
I ran across this blog post[^] yesterday, which has some info about using
CreateProcessAsUser()
--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
Hi , Thanks for the info. I wrote the code like below. In that ArgPBU is command line args (exe name to run) cwd is current working directory path BOOL b; HANDLE hToken; HANDLE hNewToken; b = OpenProcessToken(GetCurrentProcess(), TOKEN_ASSIGN_PRIMARY|TOKEN_DUPLICATE, &hToken); b = DuplicateTokenEx(hToken, TOKEN_ASSIGN_PRIMARY|TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &hNewToken); b = CreateProcessAsUser(hNewToken, NULL,ArgPBU,NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE, NULL, Cwd, &si, &m_piPBU); CloseHandle(hNewToken); ------------- After executing this I am getting same result. Can you help me in this regards? Surendran N