Criar serviço Windows

1 resposta
C

Preciso criar um serviço no windows. Toda vez que iniciar tera que ter permissao de administrador independente do usuario que logar, porem estou tendo problema pra criar o serviço. Estou utilizando o JavaService, porem na hora de iniciar o serviço da o seguinte errro : “O serviço testeService em computador local foi iniciado e interrompido. Alguns serviços sao interrompidos automaticamente
se nao estiverem sendo usados por outros serviços ou programas.”

O comando para criar o serviço é:
javaservice -install testeService “C:\Program Files\Java\jdk1.7.0_04\jre\bin\server\jvm.dll” -Djava.class.path=“c:\ManipulaSpool.jar” -start ManipulaSpool

Esse é meu codigo:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manipulaspool;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author teste
 */
public class ManipulaSpool {

    public static void log(String msg) throws IOException{
        BufferedWriter br = new BufferedWriter(new FileWriter(new File("C:\\log.txt")));
        br.write(msg);
        br.close();
    }
    
    
    public static void iniciaSpool() throws Exception {
        Process StartSpool;

        StartSpool = Runtime.getRuntime().exec("net.exe start spooler ");
        try {
            if (StartSpool.waitFor() == 0) {
                log("Spool Iniciado com sucesso.");
            } else {
                log("Erro Iniciar Spool");
                
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(ManipulaSpool.class.getName()).log(Level.SEVERE, null, ex);
        }


    }

    public static void ParaSpool() throws IOException  {
        Process StopSpool;

        Runtime.getRuntime().exec("net.exe stop lpdsvc ");
        StopSpool = Runtime.getRuntime().exec("net.exe stop spooler ");
        try {
            if (StopSpool.waitFor() == 0) {
                log("Spool Parado com sucesso.");
            } else {
                log("Erro Parar Spool");
                
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(ManipulaSpool.class.getName()).log(Level.SEVERE, null, ex);
        }


    }

    public static void main(String[] args) throws Exception {
    
        ParaSpool();
        iniciaSpool();

    }
}

1 Resposta

C

Ninguem? Já pesquiseo um monte e nao consegui, fiz varios testes mudando o parametro do -start e nao consegui

Criado 18 de outubro de 2012
Ultima resposta 19 de out. de 2012
Respostas 1
Participantes 1