这不应该引发“已经打开的错误”吗?当浏览文本文件时

发布于 2024-11-08 19:50:57 字数 803 浏览 0 评论 0原文

我正在域计算机上运行一些命令。我想在“更大的图景”中实际使用它之前对其进行测试。当我运行它时,它返回它可以连接到的计算机的数据(现在没有管理计算机)。

但例如,如果我在读取的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初相遇 2024-11-15 19:50:57

将其更改为:

Shell("cmd.exe /c" & ReplaceCommand, AppWinStyle.Hide, True, -1)

这将使其等待命令完成执行。 -1 意味着它不会超时,它将永远等待,因此您可以根据需要更改它。

更多信息:

http://msdn .microsoft.com/en-us/library/xe736fyk(v=vs.71).aspx?ppud=4

另外,我会更改:

 Dim sCommand = "pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"

为此,使用双引号,因为 cmd 字符串中的空格可能会很有趣。

Dim sCommand = """pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"""

Change it to :

Shell("cmd.exe /c" & ReplaceCommand, AppWinStyle.Hide, True, -1)

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:

 Dim sCommand = "pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"

To this, using double quotes, as cmd strings can be funny with spaces.

Dim sCommand = """pushd \\*\C$ && whoami.exe >> C:\JavaInfo.txt && java.exe -version 2>> C:\JavaInfo.txt"""
谜泪 2024-11-15 19:50:57

发生该错误是因为 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文