如果是,则让用户知道命令的语句无法执行?

问题描述

| 可以说我们将其作为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文档。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...