如何通过批处理文件远程执行命令? [英] How to remotely execute a command via a batch file?
问题描述
所以基本上,所有我想要做的是100的服务器,其名称在一个文本文件server.txt被提及执行SC命令。我尝试以下和它不工作,因为它返回空的记事本文件。
FOR / F %%一中(servers.txt)做SC \\\\服务器查询|找到SERVICE_NAME>> servicecontroller.txt
我试过在本地上面的命令和它的工作就好了。我知道这个问题是在\\服务器名。不知道它是错的。我是否需要使用隐藏共享?
像这样的可能?
\\\\服务器\\ C $ /用户:域\\用户名密码
还是这样吗?
\\\\服务器\\ C $
如果你已经很难codeD \\\\服务器
,而不是有 %% A
,那么这就是你的问题。试试这个:
FOR / F %%一中(servers.txt)做SC \\\\%的查询|找到SERVICE_NAME>> servicescontroller.txt
编辑:
下面这行有助于所有服务器上获取管理员权限一致。这是我(OP)一直在寻找就行了。
NET USE \\\\服务器\\ IPC $ / U:域\\用户密码
So basically, all I want to do is execute an "sc" command on 100 servers whose names are mentioned in a text file "server.txt". I tried the following and it doesnt work as it returns empty notepad file.
for /f %%a in (servers.txt) do sc \\server_name query | find "SERVICE_NAME">>servicecontroller.txt
I tried the above command locally and it worked just fine. I know the issue is in the "\server_name". Not sure what about it is wrong. Do i need to use the hidden shares? Like this maybe?
\\server_name\c$ /user:domain\username password
Or like this?
\\server_name\c$
If you've hardcoded \\server_name
there rather than %%a
, then that's your problem. Try this instead:
for /f %%a in (servers.txt) do sc \\%a query | find "SERVICE_NAME">>servicescontroller.txt
EDIT : The following line helps in getting admin access consistently on all the servers. This is the line I(OP) was looking for.
net use \\servername\ipc$ /u:domain\user password
这篇关于如何通过批处理文件远程执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!