问题描述
|
可以说我们将其作为Command1
Dim Command1 = \"whoami.exe >> C:\\Hello.Txt\"
该程序将从文本文件中读取用户列表,然后对每个用户执行操作。如果该用户不存在,或者他们是受密码保护的计算机的一部分,那么我希望在我的打印输出中看到该用户。
我有这个但是不确定如何编写If If语句(如果那是最简单的方法)
For Each strUserName as String in strLines
Shell(\"cmd.exe /c\" & Command1)
If Command1 = fail??
Then msgbox(\"Oops\") ???
解决方法
如果要将\'whoami.exe \'的输出重定向到您自己的控制台,则可以执行以下操作:
Dim startInfo As New ProcessStartInfo()
startInfo.Arguments = \"c:\\Hello.txt\"
startInfo.FileName = \"c:\\whoami.exe\"
startInfo.RedirectStandardOutput = True
startInfo.UseShellExecute = False
Using process As Process = Process.Start(startInfo)
Using stream As StreamReader = process.StandardOutput
Console.Write(stream.ReadToEnd())
End Using
End Using
您将需要导入System.Diagnostics命名空间。如果\'whoami.exe \'返回您可以使用的退出代码,您还可以使用Process类通过调用以下代码进行检查:
process.WaitForExit()
Dim code As Integer = process.ExitCode
If code = 1 Then
\' success
Else
\' other
End If
希望这可以帮助。
,您需要在一行或以lines5ѭ结尾的多行中编写If Then
语句
If Command1 = fail Then msgbox(\"Oops\")
要么
If Command1 = fail Then
msgbox(\"Oops\")
End If
这是if语句的msdn文档。