文本文件中主机名的服务状态
我有以下代码,它在名为 find.txt 的文本文件(见下文)中的所有主机名上启动名为 uvnc_service 的服务。我想添加某种检查来测试服务是否已在其上运行,如果是,则不执行任何操作并向屏幕输出一条消息,说明其已在运行,或者是否未在查找中的主机之一上运行.txt 文件 - 启动服务,然后将主机名输出/附加到该文件。
有人可以帮我吗?
谢谢
find.txt
pc1
pc2
pc3
……
set service = uvnc_service
for /F %%a in (c:\temp\find.txt) do sc \\%%a start %service% && >> out.txt echo %%a
I have the following code that starts a service called uvnc_service on all hostnames I have in a text file called find.txt (see below). I want to add some sort of check to test if the service is already running on it so if it is - do nothing and output a message to the screen saying that its already running or if its not running on one of the hosts in the find.txt file - start the service and then output/append the hostname to this file.
Can someone help me please?
Thanks
find.txt...
pc1
pc2
pc3
...
set service = uvnc_service
for /F %%a in (c:\temp\find.txt) do sc \\%%a start %service% && >> out.txt echo %%a
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用服务控制来查询机器并查看服务的状态,即它是否正在运行
http://ss64 .com/nt/sc.html
试试这个,
我无法在我的机器上测试它,而且我有一段时间没有完成批处理,所以它可能不完美
You can use Service control to query the machine and see the status of the service ie is it running
http://ss64.com/nt/sc.html
Try this
I cant test it on my machine and i haven't done batch in a while so it might not be perfect