我需要在Visual Basic脚本中执行命令行 [英] I need execute a command line in a Visual Basic Script

查看:433
本文介绍了我需要在Visual Basic脚本中执行命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的vbs中执行命令ver以查看我的操作系统的版本,我不知道如何make它。

I need to execute the command "ver" in my vbs to see the version of my Operating System, and i don't know how make it.

尝试这个,但不工作:

Function ExecuteWithTerminalOutput(cmd)
Set shell = WScript.CreateObject("WScript.Shell")
Set Exec =  shell.Exec("ver")
End Function


推荐答案

尝试这样:

Dim objShell
Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "cmd /c ver"
Set objShell = Nothing

编辑:

那么你可以将输出重定向到一个文件,然后阅读文件:

Well then you can redirect output to a file and then read the file:

return = WshShell.Run("cmd /c ver > c:\temp\output.txt", 0, true)

Set fso  = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("c:\temp\output.txt", 1)
text = file.ReadAll
file.Close

这篇关于我需要在Visual Basic脚本中执行命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆