2011-05-19 25 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

相關問題