invoke an external program in most programming languages is no problem. Not so in Java. In Java, which basically looks like this:
. exec ( "/pfad/zum/program" ) ; Runtime ".) GetRuntime. Exec (" / path / to / program;
Now, however, one must also keep in mind the boundary conditions. Is it, for example, Java within Tomcat that has an application with surface effects, of course. In principle, Tomcat is run as a service, whether that is now under Linux or Windows, should play no role for the basic problem.
Tomcat as a service or the client process is not simply the rights to run a GUI, apart from the fact that it is not ensured on a server that has a graphical interface. Here, the maintenance of a Windows server via Remote Desktop should be mentioned in comparison to SSH / console maintenance of a Linux system as an example.
That is, is the external (graphical) application launch from a desktop Java process is not a problem, it looks on a server also different.
Linux can access another user (under which the service process) to allow the X server with xhost (that was from memory). In this case, however, a service under Windows.
Also Windows keeps ready for this board means: In the Services Manager, you can edit the properties of the service. Under the "Login" is the point "service to interact with desktop" permit. To enable the hook, even a process server, a graphical application, such as Word or Excel start.
Often these hooks, but not the drug of choice will be. For example, because the appearance of the graphical interface of the application is not desired or the server simply no one is logged / should be (on a logical server not uncommon). In this situation we have reached with java its own funds at the end. In C # example, you can start an application is not visible as invisible. This possibility is not Java. To achieve this we must make do with a wrapper. For Windows program, there are the so called exe-header, in this you can also add, that the application should be visible. There is also the SW_HIDE flag is used. The following C + + code calls, on an application and sets for them the SW_HIDE flag. To ensure that this does, but must be set in each case, the dwFlag STARTF_USESHOWWINDOW.
_tmain ( int argc, TCHAR * argv [ ] ) { STARTUPINFO si ; PROCESS_INFORMATION pi ; ZeroMemory ( & si, sizeof ( si ) ) ; si. cb = sizeof ( si ) ; si. wShowWindow = SW_HIDE ; si. dwFlags = STARTF_USESHOWWINDOW ; ZeroMemory ( & pi, sizeof ( pi ) ) ; if ( argc ! = 2 ) { printf ( "Usage: %s [cmdline] \n " , argv [ 0 ] ) ; return ; } // Start the child process. if ( ! CreateProcess ( NULL , // No module name (use command line) argv [ 1 ] , // Command line NULL , // Process handle not inheritable NULL , // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE CREATE_NO_WINDOW, // No creation flags NULL , // Use parent's environment block NULL , // Use parent's starting directory & si, // Pointer to STARTUPINFO structure & pi ) // Pointer to PROCESS_INFORMATION structure ) { printf ( "CreateProcess failed (%d). \n " , GetLastError ( ) ) ; return ; } // Wait until child process exits. WaitForSingleObject ( pi. hProcess , INFINITE ) ; // Close process and thread handles. CloseHandle ( pi. hProcess ) ; CloseHandle ( pi. hThread ) ; } # Include # include # include <windows.h> <tchar.h> void _tmain (int argc, TCHAR * argv []) {STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory (& si, sizeof (si)) , si. "cb = sizeof (si); Usage si. wShowWindow = SW_HIDE:; si. dwFlags = STARTF_USESHOWWINDOW; ZeroMemory (& pi, sizeof (pi)); argc if (= 2) {printf (% s [cmdline ] \ n ", argv [0]) return;} / / Start the child process. if / (! CreateProcess (NULL, / / No module name (use command line) argv [1], / / Command line NULL / Process handle not inheritable NULL, / / Thread handle not inheritable FALSE, / / Set handle inheritance to FALSE CREATE_NO_WINDOW, / / No creation flags NULL, / / Use parent's environment block NULL, / / Use parent's starting directory & si, / / Pointer to STARTUPINFO structure & pi) / / Pointer to PROCESS_INFORMATION structure) {printf ("failed (% d). CreateProcess \ n", GetLastError ()) return;} / / Wait until child process exits hProcess. WaitForSingleObject (pi. , INFINITE); / / Close process and thread handles;. CloseHandle (pi. hProcess) CloseHandle (hThread pi.);}
This C + + snippets can, for example with the free Borland C + + compiler translate and thus obtains a universal wrapper to the SW_HIDE flag to start programs.
However, it is possible that not the last. For inexplicable reasons, it was not necessary for me the desired application on the Windows system user under which Tomcat is running by default, but from a different local user to allow. The same can be adjusted but also illustrated in the above dialogue.
By this means it was possible for me to start from Java using the C + + wrapper is a graphical application without requiring a user to be logged.
Tags: c + + , coding , java , tomcat , wrapper










Caution. Other users have potentially different (higher) rights. That a Tomcat running in a chroot type has for a reason.
I said yes not to any other user, but rather an established specifically for the Tomcat. That this is not the optimal solution, it is clear, but unfortunately not been otherwise resolved.
"In C # example, you can start an application as the invisible visible / not" - thanks! * G *