开发者

Place Line from Text File in a Shell CMD. VB.net

I am assuming there is a way to have this sub in? I am assuming Do Un开发者_高级运维til Loop is the way to go, I just do not know how to contruct one.

    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


Something like this if I understand your question correct:

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

Now, you have only told us what you want to DO, not what you want to achieve. If you tell us exactly what the goal is, then it may be some other .Net ways to do what you want, instead of shelling out to a DOS-command, and you can get more accurate answers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜