这不应该引发“已经打开的错误”吗?当浏览文本文件时
我正在域计算机上运行一些命令。我想在“更大的图景”中实际使用它之前对其进行测试。当我运行它时,它返回它可以连接到的计算机的数据(现在没有管理计算机)。
但例如,如果我在读取的 txt 文件中列出“我的个人电脑”两次,它会说“文件已被使用”并跳过我。
这是一个错误,因为它是同一台计算机吗?我希望它能够在遇到重复项时继续编写副本。
Sub HandleInfo()
'Declare Command
Dim sCommand = "pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"
'declare File where Users are Located
Dim strFile As String = "C:\TestDUsers.txt"
'declare Lines in User.Txt File
Dim strLines() As String = IO.File.ReadAllLines(strFile)
For Each strUserName As String In strLines
Dim ReplaceCommand As String = sCommand.Replace("*", strUserName)
Shell("cmd.exe /c" & ReplaceCommand)
Next
I am running a few commands on the domain computers. I would like to test it before I actually use it in the "bigger picture". When I run this it returns data for the computers that it can connect to (no admin machine right now).
But for example if I list My personal Computer twice in the txt file it reads from, it says File is already being used and skips me.
Is this an error because its the same computer? I would like it to be able to just go ahead and write the duplicate if it comes across one.
Sub HandleInfo()
'Declare Command
Dim sCommand = "pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"
'declare File where Users are Located
Dim strFile As String = "C:\TestDUsers.txt"
'declare Lines in User.Txt File
Dim strLines() As String = IO.File.ReadAllLines(strFile)
For Each strUserName As String In strLines
Dim ReplaceCommand As String = sCommand.Replace("*", strUserName)
Shell("cmd.exe /c" & ReplaceCommand)
Next
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其更改为:
这将使其等待命令完成执行。 -1 意味着它不会超时,它将永远等待,因此您可以根据需要更改它。
更多信息:
http://msdn .microsoft.com/en-us/library/xe736fyk(v=vs.71).aspx?ppud=4
另外,我会更改:
为此,使用双引号,因为 cmd 字符串中的空格可能会很有趣。
Change it to :
This will make it wait until the command has finished executing. The -1 means it will not timeout, it'll wait forever, so you can change that as you wish to suit.
More info:
http://msdn.microsoft.com/en-us/library/xe736fyk(v=vs.71).aspx?ppud=4
Also, I'd change:
To this, using double quotes, as cmd strings can be funny with spaces.
发生该错误是因为 javainfo.txt 已在使用中。
要确认相同,只需在文件名中添加 * 即可。例如 javainfo*.txt
如果确认从文件名中删除 * 并在 shell 函数中设置 wait= true ,您的代码将正常工作
The error occurs because javainfo.txt ia already in use.
To confirm the same just add * to file name. e.g. javainfo*.txt
If its confirmed remove * from file name and set wait= true in shell function and your code will work