Windows services in java

i want to display window and asking to enter user name and passwrod
when windows startup,so tahat i can update the attendence table of the user in database.
to do this i need to wirte services ,could u pls tell me how to write services in java

There are frameworks that make this relatively easy (google "Java Service" and you'll find them). Alternatively, you can write the service DLL yourself and instantiate your Java objects using JNI.
If you are already familar with creating NT services, then JNI would be the way to go.
Given the requirements of your project, it sounds like you will have to go the JNI route - and learn quite a bit about how to hook into the Windows login dialogs...
- K

Similar Messages

  • Start and Stop a Windows Service From Java

    Is there any way to start and stop a Windows service from Java? The only post I found on it (http://forum.java.sun.com/thread.jspa?threadID=647509) had a link to one of the many aps that allow Java programs to be services, which is not what I am interested in doing.
    I am attempting to get data from performance counters from the Windows Performance Monitor into a Java ap without using JNI. I can get the data from C++ or a .net language pretty easily and was going to create a service that would listen for socket requests and feed back the data. However, I'd like to start and stop that service when my java code starts and stops. Is this possible? Would it make more sense to just use a .exe and Runtime.exec()?

    If it's only to start or stop a service then you could use the net command without any need for JNI.import java.io.*;
    public class MsWinSvc {
        static final String CMD_START = "cmd /c net start \"";
        static final String CMD_STOP = "cmd /c net stop \"";
        public static int startService(String serviceName) throws Exception {
            return execCmd(CMD_START + serviceName + "\"");
        public static int stopService(String serviceName) throws Exception {
            return execCmd(CMD_STOP + serviceName + "\"");
        static int execCmd(String cmdLine) throws Exception {
            Process process = Runtime.getRuntime().exec(cmdLine);
            StreamPumper outPumper = new StreamPumper(process.getInputStream(), System.out);
            StreamPumper errPumper = new StreamPumper(process.getErrorStream(), System.err);
            outPumper.start();
            errPumper.start();
            process.waitFor();
            outPumper.join();
            errPumper.join();
            return process.exitValue();
        static class StreamPumper extends Thread {       
            private InputStream is;
            private PrintStream os;
            public StreamPumper(InputStream is, PrintStream os) {
                this.is = is;
                this.os = os;
            public void run() {
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
                    String line;
                    while ((line = br.readLine()) != null)
                        os.println(line);
                catch (Exception e) {
                    e.printStackTrace();
    }Regards

  • Monitoring windows services from JavaI Know how to

    I know how to start and stop services in java, but how can I see if a process is already stared or is starting?
    Thx

    You'll need to make a call to a suitable Windows program using Runtime or ProcessBuilder methods, or use JNI (Java Native Interface.) From Wikipedia:
    (JNI) is a programming framework that allows Java code running in the Java virtual machine (JVM)
    to call and be called[1] by native applications (programs specific to a hardware and operating system
    platform) and libraries written in other languages, such as C, C++ and assembly.

  • Run windows services from java application

    can java application run a windows server
    i have a web server that runing using tomcat and mysql
    can i make a icon in the systray
    that give me the option to (using a menu)
    run the server ,wicth means : tomcat and mysql are runing
    stop the server
    get tomcat stacktrace in a window
    i was thinking about runing tomcat and mysql as services
    and write the systray application using java,
    the systray application should acces window services ,
    and run/stop requierd services.
    what happend on a machine thar runs linux?
    thanks
    shay

    Ok .so it's will be a diffrent way under linux..
    for systray i will use http://systray.sourceforge.net/
    and for services i'll use the
    "net start <Service>" and "net stop service"
    i need to keep track on the service status
    so my Systray status will be updated
    what is the command for getting the status of the proccess
    thanks shay

  • Getting windows services through java

    Hi,
    I just want to get the status of windows services( SERVICE_NAME: DWMRCS)
    and also i have to stop and start the services through java code is there any help?
    thanks

    Use "sc" util with Runtime.exec().

  • Windows services vs java

    Hi,
    I just want to get the status of windows services( SERVICE_NAME: DWMRCS)
    and also i have to stop and start the services through java code is there any help?
    thanks

    There are frameworks that make this relatively easy (google "Java Service" and you'll find them). Alternatively, you can write the service DLL yourself and instantiate your Java objects using JNI.
    If you are already familar with creating NT services, then JNI would be the way to go.
    Given the requirements of your project, it sounds like you will have to go the JNI route - and learn quite a bit about how to hook into the Windows login dialogs...
    - K

  • How to talk to a  Windows Service using java

    Hi,
    I've a ATL COM Service running on a specified port.
    At least I should be able to talk to an ordinary service
    Now I need to talk to the service through java.
    I need to call some functions in the service.
    Can somebody please help me....plzz
    If possible send me urls
    Thanks in advance

    Hi,
    How about something like this:
    $started = $false
    Do {
    $status = Get-Service alg
    If ($status.Status -eq 'Running') { $started = $true }
    Until ( $started )
    Don't retire TechNet! -
    (Don't give up yet - 12,575+ strong and growing)

  • Querying windows service from Java

    Hi All,
    i have a java web application running on jboss that does data collection by querying different windows processes like MSSQLSERVER, IIS availability etc.
    The problem i am facing is that my application is returning a negative result for the above services but when i run the query from command prompt i get a positive result. I dont understand why this happens.
    would really appreciate a response.

    Is query this from java Runtime.exec and from command prompt different? My code creates a string of sc \\<server> query W3SVC and calls this like:               String cmd = "sc "+ " \\\\ " + serverIPOrHostName + "query"+ service;
                   p = r.exec(cmd);
                   inp = p.getInputStream();
                byte[] dataInput = new byte[320];
                inp.read(dataInput);
                String inputData = new String(dataInput);
                //Logger added to read the service response.
                logger.info(inputData);
                //Checks for specified sequence of characters in the string and
                //returns boolean.
                if (inputData.contains(SERVICE_RUNNING)) {
                     result = 1;
                } else {
                     result = 0;
                }My reasoning is that if i cant do it in java because of some security policy then i should not be able to do it in command prompt too? But that is not the case. I can do it over command prompt but not from java code!
    If this is a windows related issue, how should i proceed to debug it? how can i provide access to my java code to do this?
    I happened to check out one site http://www.kbalertz.com/kb_Q323790.aspx where it says that "The File and Printer Sharing for Microsoft Networks component must be turned on for many remote-management functions to work. "
    But this looks like a very trivial (although i dont know much about windows security policies).
    thanks,
    Dilip
    PS: Thanks for looking into the mail and responding.

  • Running Java Applications as a Windows Service

    Hi,
    can any one help me to develop windows services in java.
    Running Java Applications as a Windows Service
    Any example or link please send me.
    Thanks and regards.
    Amit.

    See the Java Service Wrapper at
    http://wrapper.tanukisoftware.org/doc/english/introduction.html
    It's really good and easy to use.
    Bye.

  • JNI  --  Windows Service (Java Service Wrapper)  --  Winamp

    Hi!
    I'm developing an application to control Winamp player and this application is supposed to run as a Windows Service (via Java Service Wrapper). Winamp is
    handled via JNI (c library dll).
    The thing is:
    When I start the application as a service, my application tries to control Winamp (eg play, pause) but it doesn't work. I can see (prints) that my application is working but all the calls of the dll that interacts with Winamp don't answer. Instead, when I stop the service, I can see finaly all the prints (I introduced in the dll play, pause functions).
    Can anybody give a hand? It seems that the JNI is not working properly (in my humble opinion).
    Thanks for your attention.
    Best Regards
    Nuno

    In my java application:
    System.out.println("Before play!");
    play( ); //Native method...
    System.out.println("After play!");
    sleep(10*1000);
    System.out.println("Before pause!");
    pause ( ); //Native method...
    System.out.println("After pause!");
    In c file (dll lib):
    JNIEXPORT void JNICALL Java_WinampController_play
    (JNIEnv *env, jobject obj) {
              printf("-> cpp - Play \n");
    initWinampHandle();
    if (hwnd_winamp != NULL) {
    SendMessageA(hwnd_winamp, WM_COMMAND, WA_PLAY,
    WA_NOTHING);
              printf("<- cpp - Play \n");
    JNIEXPORT void JNICALL Java_WinampController_pause
    (JNIEnv *env, jobject obj) {
              printf("-> cpp - Pause \n");
    initWinampHandle();
    if (hwnd_winamp != NULL) {
    SendMessageA(hwnd_winamp, WM_COMMAND, WA_PAUSE,
    WA_NOTHING);
              printf("<- cpp - Pause \n");
    Result... (log file)
    Before play!
    After play!
    Before pause!
    After pause!
    And only after I stop the service, the cpp printf appear... :(
    -> cpp - Play
    <- cpp - Play
    -> cpp - Pause
    <- cpp - Pause
    Thanks

  • Socket Exception Invalid argument create on Windows service in process mode

    Please help , Iam getting SocketException Error on connecting with mysql using jdbc also when connect to Activemq jms. Strange thing is this is only
    happening on Windows Server(2008) and when i run the application as Windows service with 'jvm' (in-process) option. Program can connect
    when i run as Java exe in the Windows Service.
    Java JDK version - jdk1.6.0_26.
    Thanks in advance, please ask if any more info needed.
    -- mysql connect--
    Database Driver="com.mysql.jdbc.Driver" Host="jdbc:mysql://localhost:3306/mydb?useUnicode=true&amp;characterEncoding=UTF8" User="admin" Password="password"
    Java.net.SocketException
    MESSAGE: Invalid argument: create
    STACKTRACE:
    java.net.SocketException: Invalid argument: create
    at java.net.Socket.createImpl(Socket.java:397)
    at java.net.Socket.<init>(Socket.java:371)
    at java.net.Socket.<init>(Socket.java:189)
    at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:124)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:225)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:1779)
    at com.mysql.jdbc.Connection.<init>(Connection.java:450)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:185)
    at myapp.JDBCLoader.JDBCConnect(JDBCLoader.java:129)
    ----on activemq connect ---
    javax.jms.JMSException: Could not connect to broker URL: tcp://localhost:61616?connectionTimeout=0&keepAlive=true&wireFormat.maxInactivityDuration=0. Reason: java.net.SocketException: Invalid argument: create
    at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:35)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:286)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:230)
    at org.apache.activemq.ActiveMQConnectionFactory.createQueueConnection(ActiveMQConnectionFactory.java:193)
    at sen.connector.queue.ConnectionFactory.createQueueConnection(ConnectionFactory.java:60)
    at sen.connector.queue.ConnectionFactory.createQueueConnection(ConnectionFactory.java:36)
    at sen.connector.queue.HostConnection.connectToHost(HostConnection.java:147)
    at sen.connector.queue.HostConnection.run(HostConnection.java:127)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: java.net.SocketException: Invalid argument: create
    at java.net.Socket.createImpl(Socket.java:397)
    at java.net.Socket.connect(Socket.java:527)
    at org.apache.activemq.transport.tcp.TcpTransport.connect(TcpTransport.java:484)
    at org.apache.activemq.transport.tcp.TcpTransport.doStart(TcpTransport.java:447)
    at org.apache.activemq.util.ServiceSupport.start(ServiceSupport.java:53)
    at org.apache.activemq.transport.InactivityMonitor.start(InactivityMonitor.java:127)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.transport.WireFormatNegotiator.start(WireFormatNegotiator.java:72)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.transport.TransportFilter.start(TransportFilter.java:58)
    at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:266)
    Edited by: 891207 on Oct 12, 2011 8:14 PM
    Edited by: 891207 on Oct 12, 2011 8:17 PM

    I'm sure that exception can be caused by the firewall.The exception below is what is caused by a firewall. Anyway the OP said that it worked fine running as a windows service, so that would rule-out a firewall. Also connections to 'localhost' don't go through the firewall.
    Expecting people to know that 'try a different JVM' I already explained that
    my initial diagnosis was incorrectHave a nice day.
    - Mike
    java.sql.SQLException: IO Error: The Network Adapter could not establish the connection
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:512)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
    554)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:232)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:28)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:553)
    at java.sql.DriverManager.getConnection(DriverManager.java:582)
    at java.sql.DriverManager.getConnection(DriverManager.java:154)
    at JDBCTest4.main(JDBCTest4.java:53)
    Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:388)
    at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:430)
    at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:871)
    at oracle.net.ns.NSProtocol.connect(NSProtocol.java:264)
    at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1598)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:360)
    ... 7 more
    Caused by: java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:146)
    at oracle.net.nt.ConnOption.connect(ConnOption.java:129)
    at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:366)

  • Error 1053 comes out while starting oc4j service through windows services

    HI EVERYBODY
    I face some problem and I'll be very happy if i recieved any reply from u.
    here is my problem :
    I used the code which starts/stops OC4J-standalone as a Windows service using
    java service for install and uninstall the service(the code is shown down),however the code works well
    and the service install and uninstall successfully.
    but when I start the service throught the windows servecis manager this error comes out:
    * Error 1053: The service did not respond to the start or control request in a timely fashion"
    and the status of the service stay "starting"*
    I found solution by adding "DWORD Value" in the registry and modify it to 60000
    but it didn't work and still this error come out.
    Any help will be appreciated.
    the code is :
    install_OC4J_Service :
    Setlocal
    @rem Note that if JVM not found, service 'does not report an error' when startup fails, although event is logged
    if "%JAVA_HOME%" == "" set "JAVA_HOME"=C:\Program Files\Java
    REM set the display name of the service
    set JSNAME=OC4J_Service
    REM Set the Java server directory
    set JVMDIR=%JAVA_HOME%\jre1.6.0_01\bin\client
    REM Setting a bind directory for the software
    set JSBINDIR=%CD%
    REM Setting path and filename of the (renamed) javaservice executable
    set JSEXE=%JSBINDIR%\OC4J_Service.exe
    REM Stating the directory of the OC4J-home
    set OC4J_HOME=E:\DevSuiteHome_1\j2ee\home
    REM just to check the used version @echo . To install the service "%JSNAME%" the following version of JavaService executable is used: @ echo . %JSEXE% -version @echo .
    @echo Installing service OC4J_Service ... Press Enter to continu or press Control-C to abort installation
    @pause
    @echo
    %JSEXE% -install %JSNAME% %JVMDIR%\jvm.dll -Djdbc.debug=true java.class.path=%OC4J_HOME%\oc4j.jar –Xmx256M -start com.evermind.server.OC4JServer -params -config %OC4J_HOME%\config\server.xml -out %OC4J_HOME%\log\OC4J_service_stdout.log -err %OC4J_HOME%\log\OC4J_service_stderr.log -current %JSBINDIR% -manual -description "OC4JService"
    @echo
    @echo End of Installation
    @pause
    uninstall_OC4J_Service:
    @echo off
    @echo . Uninstall_OC4JService.cmd - de-install of JavaService executable using OC4J.jar
    @echo .
    setlocal
    @rem Note that if JVM not found, service 'does not report an error' when startup fails, although event logged
    if "%JAVA_HOME%" == "" set JAVA_HOME=c:\java\j2sdk142
    set JVMDIR=%JAVA_HOME%\jre1.6.0_01\bin\client
    set JSBINDIR=%CD%
    set JSEXE=%JSBINDIR%\OC4J_Service.exe
    @echo . Using following version of JavaService executable:
    @echo .
    %JSEXE% -version
    @echo .
    @echo Un-installing service OC4J_Service ... Press Control-C to abort
    @pause
    @echo .
    %JSEXE% -uninstall OC4J_Service
    @echo .
    @echo End of script
    @pause
    -------------------------------------------------------------------------

    Any recent change? Use below command to validate the opmn.xml file.
    opmnctl validate
    Replace the opmn.xml backup file in $ORACLE_HOME/opmn/conf and try starting opmn.
    Also ipm.log file in $ORACLE_HOME/opmn/log folder

  • Install of WAS 6.40 java on windows no windows services created

    We are trying to install a NW04 SR1 WAS on windows. The latest Install Master CD download now requires Oracle 10. The Oracle 10 install is the first part of the install process. The Note number 949116  says to use the procedure for the Oracle install in the NW 2004s SR1 install guide.
    We have followed these instructions and after running the Oracle installer via sapserver.cmd we get a successful completion with 0 byte error file.
    We are installing over Remote Desktop as a user who is a member of the local Admin group.
    But the only windows service created is iSQL.
    I tried using both mstsc & mstsc /console but the services are still not created.
    Has anyone had the same problem?
    Regards
    Chris

    Thanks for your help Gopal
    The documentation is very bad on this process so for anyone who is following the the upgrade of R/3 internet sales from J2EE Engine 6.20.
    Use the following;
    6.20/6.40 based products Installation Master (Edition Sept. 2006) Number 51032143
    Download IGS, SCS, Crypto Lib & SAP:J2EE-CD:640SR1:J2EE-CD::
    Download Oracle 10, 5 files rebuild cd by clicking on the.exe file
    Install Oracle 10 (Don't expect to see an operational RDBMS i.e no services)
    Install NW04s SR1 java via Install Master SAPInst
    Install CRM Component ISA R/3 via Install Master SAPInst
    Hope this helps
    Regards
    Chris

  • Creating Windows Based Service in Java

    Hey is there any way I can create windows based service in Java. My need is that no one has to log on to the machine to start a java application.
    Thanks in advance

    This can be done, although its been so long I forget the exact details. There are some utilities out there that will let you run any program as a service. I remember I created a batch file to run my java program in and then set the batch file up as a service.
    Hope that helps,
    Peter

  • Adding Java program as a Windows service

    Hi all,
    How can I run a Java program as a Windows service?

    There are free tools available...just google it.
    Try http://jslwin.sourceforge.net/

Maybe you are looking for

  • Sharing is enabled; nobody can see my library

    iTunes 7.4 for those wondering. I have sharing enabled (password protected), but nobody in my dorm hall network can see my library. I can see theirs, including the passworded one, but mine is getting lost somewhere. Can anybody help me out with this?

  • Eject button not working on dvd/cd tray

    You name it, I've tried it! Apples advice was to backup my work and wipe the dripe and reinstall the OS. Guess what - the eject button still doesn't work! Well done apple. That'll be 2 days wasted of precious production time. All this after a new pow

  • Background program running and can't figure out what it is...

    I have an IMAC desktop, I just purchased the Photoshop Elements 10 software for MAC, installed it, running fine. But now I have program that is contanstly running in the background that is slowing up all of my other applications I run while I'm worki

  • 11i Receivable Application

    Hi, I am currently trying to see if there is a way of using Oracle 11i to apply cash across multiple organizations/SOBs. I know that as of 11.5.7 there was no supported way of doing this without using the Lockbox or some customer form/code. I heard t

  • Downloading in excel from sqvi report format in the background

    Dear All, We have developed couple of report using SQVI format for couple of reports. Now for those reports my client wants to download them in excel sheet and attach to the email, when email is triggered automatically to the specified email id's. Th