start an .exe from windows service
-
Hi, I want to run an exe(say for eg: Calculator) from the windows service when it started. In the OnInit() I have used CreateProcess function, toget the exe path from the command line argument. My problem here is that, Exe and service is running in task manafer after I started the service, But I couldnt see the application window(Calculator) visible to user. After getting some valuable suggestion from this site, I replaced CreateProcess function with CreateProcessAsUser() function to get the window. But Still the same problem exists. Here is the code I place in the Init menthod 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); ----------------------- Thanks in advance. Rgds., Surendran N
-
Hi, I want to run an exe(say for eg: Calculator) from the windows service when it started. In the OnInit() I have used CreateProcess function, toget the exe path from the command line argument. My problem here is that, Exe and service is running in task manafer after I started the service, But I couldnt see the application window(Calculator) visible to user. After getting some valuable suggestion from this site, I replaced CreateProcess function with CreateProcessAsUser() function to get the window. But Still the same problem exists. Here is the code I place in the Init menthod 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); ----------------------- Thanks in advance. Rgds., Surendran N
I have been working with this problem recently, in Windows Server 2003. I started a GUI app as a service (with XYNTService), but I couldn't see the app window either. I found out that the only account that could interact with the desktop is (at least in 2003) is services running under Local Account. I tried it, but as expeced, the Local Account cannot access the network. I ended up with doing an autologin to the preferred user account, then autostart the GUI app. The biggest drawback is that if a user performs a logoff, the app is closed, so I had to make a Windows wallpaper saying: "Don't logoff, just do a "lock computer". I'm really interested in a better solution, I really hope you will get a better answer than this one.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
I have been working with this problem recently, in Windows Server 2003. I started a GUI app as a service (with XYNTService), but I couldn't see the app window either. I found out that the only account that could interact with the desktop is (at least in 2003) is services running under Local Account. I tried it, but as expeced, the Local Account cannot access the network. I ended up with doing an autologin to the preferred user account, then autostart the GUI app. The biggest drawback is that if a user performs a logoff, the app is closed, so I had to make a Windows wallpaper saying: "Don't logoff, just do a "lock computer". I'm really interested in a better solution, I really hope you will get a better answer than this one.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);
-
When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);
Thanks. I will check out if XYNTService does this as it is. But i think it does, since it has been working (with GUI apps) in other Windows versions. In the properties dialog in Windows 2003 Server, the "Interact with desktop" checkbox, is disabled unless "Local Account" is selected (for a service).
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
When you create your service via call to CreateService, be sure to include the SERVICE_INTERACTIVE_PROCESS. This will allow your service to interact with the desktop. ::CreateService( hSCM, m_szServiceName, m_szServiceName, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, szFilePath, NULL, NULL, _T("RPCSS\0"), NULL, NULL);
Yes in my program CreateService is mentioned like this only. One thing I have to mention here is that, I found that the application GUI is launching when the service starts from the local machine, if the same machine is accessed from remote as Remotedesktop connection to start the service, the GUI is running only in the background. GUI is not visible. Rgds., Surendran