Public Function cmd(ByVal argm As String) As Boolean
'开始创建文件
Dim p As Process = New Process()
p.StartInfo.FileName = /"cmd.exe/"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
Try
p.Start()
p.StandardInput.WriteLine(argm)
p.StandardInput.WriteLine(/"exit/")
p.StandardOutput.ReadToEnd()
p.Close()
Return True
Catch
Return False
End Try
End Function
'开始创建文件
Dim p As Process = New Process()
p.StartInfo.FileName = /"cmd.exe/"
p.StartInfo.UseShellExecute = False
p.StartInfo.RedirectStandardInput = True
p.StartInfo.RedirectStandardOutput = True
p.StartInfo.RedirectStandardError = True
p.StartInfo.CreateNoWindow = True
Try
p.Start()
p.StandardInput.WriteLine(argm)
p.StandardInput.WriteLine(/"exit/")
p.StandardOutput.ReadToEnd()
p.Close()
Return True
Catch
Return False
End Try
End Function
博客展示了一段VB代码,定义了名为cmd的函数,该函数接收一个字符串参数。函数内创建了一个新的进程来执行cmd.exe,通过该进程执行传入的命令并退出,最后根据执行情况返回布尔值,实现了创建文件的功能。
1604

被折叠的 条评论
为什么被折叠?



