2011-05-19 21 views
0

我假设有一种方法可以使这个子?我假设Do Until Loop是要走的路,我只是不知道如何构建一个。将文本文件中的行放在Shell CMD中。 VB.net

Sub Main() 
    'Declare Command 
    Dim sCommand As String 
    'Declare File where Users are Located 
    Dim strFile As String = "C:\TestDUsers.txt" 
    'Running from Admin Comptuer so permissions are fine 
    'Want to replace the ******** section with each username from text file 
    sCommand = "pushd \\*********\C$ && whoami.exe >> C:\File.txt" 

    'Load the File and perform the loop???? 

    Using sr As New StreamReader(File.Open(strFile, FileMode.Open)) 

    End Using 

    Console.WriteLine() 
    Console.Clear() 

    End Sub 

回答

1

事情是这样的,如果我明白你的问题正确:

Sub Main() 
    HandleJavaInfo() 
End Sub 

Sub HandleJavaInfo() 
    Dim strFile As String = "C:\Users\pseal2\Desktop\TestDUsers.txt" 
    Dim strCommand = "pushd \\*********\C$ && whoami.exe >> C:\Users\pseal2\Desktop\Javainfo." 

    Dim strLines() As String = IO.File.ReadAllLines(strFile) 
    For Each strUserName As String In strLines 

     'execute the command as shell or process 

     'Example using Shell (run the command whitout showing the window for the user) 
     Dim ThisCommand As String = strCommand.Replace("*********", strUserName) 
     Shell(ThisCommand, AppWinStyle.Hide) 

     'Example using process 
     Process.Start("pushd", "\\" & strUserName & "\C$ && whoami.exe >> C:\Users\pseal2\Desktop\Javainfo.") 

    Next 
End Sub 

现在,你只告诉我们你想要做什么,而不是你想要达到的目标。如果你确切地告诉我们目标是什么,那么它可能是一些其他的.Net方式来做你想做的事情,而不是脱壳成DOS命令,你可以得到更准确的答案。

+0

基本上无论如何,将插入每个用户名形式的TXT文件,并运行上述命令。我现在正在解决它的问题,并且很快就会编辑 – sealz 2011-05-19 19:45:09

+0

这很有效。我需要执行Shell(“cmd.exe/c”&ThisCommand)才不会引发错误。可能是我的错。 看来,当它试图移动到文件中的下一行时,它说文件已经在使用中。例如,我应该能够在USER文本文件中列出我的个人计算机两次,并让它返回两次结果。 – sealz 2011-05-19 20:10:13

相关问题