当前位置: 动力学知识库 > 问答 > 编程问答 >

windows - Trying to create a batch file that opens CMD in working directory and calls a command to see who is logged into servers

问题描述:

what I know works;

open cmd in working directory: cmd /k

command to return logged in users: for /f %s in (servers.txt) do (echo %s & qwinsta /server:%s )

as servers.txt is a list of servers

I can't get this to work together; and i'd like to have it print to a text file when finished.

网友答案:

When you use FOR in a batch file, you have to double-up the % on the FOR variables.

for /f %%s in (servers.txt) do (echo %%s & qwinsta /server:%%s )
网友答案:

That will work if you're running it from a command prompt but if you you want to run it from a batch file, you have to double your %%'s on your for variables. Here is how you do it writing to a file from a batch file.

@echo off
setlocal
(for /f %%s in (servers.txt) do (echo %%s & qwinsta /server:%%s ))>output.txt
type output.txt
分享给朋友:
您可能感兴趣的文章:
随机阅读: