从 Java 中创建 Windows 服务 [英] Create a Windows Service from within Java

查看:40
本文介绍了从 Java 中创建 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Java 程序,我需要从该 Java 程序中创建一个 Windows 服务.我想基本上运行命令行

I have a Java program and I need to create a Windows Service from within that Java program. I want to basically run the command line

sc create \"" + serviceName + "\" binPath= \"" + batFile + "\" start= auto

但是,当我从 Java 中运行此过程时,出现错误

However, when I run this process from within Java I get an error

[SC] OpenSCManager FAILED 5:

Access is denied.

如果用户是管理员,这个命令可以正常工作,但是我这个 Java 程序的用户不是管理员.如何在没有管理员权限的用户的情况下从 Java 内部(或通过运行外部程序)创建 Windows 服务?

This command works fine if the user is an administrator, however my users of this Java program will not be administrators. How do I create a Windows Service from within Java (or by running external programs) without the user having administrator privileges?

显然这是不可能的.除了通过 Windows 服务之外,Windows 中还有其他方法可以在机器启动时执行程序吗?

Apparently this isn't possible. Is there another way in Windows to execute a program at machine start up other than through a Windows Service?

推荐答案

没有管理员权限,无法在 Windows 中创建服务.

It is not possible to create service in windows without Administrator privileges.

这篇关于从 Java 中创建 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆