I need execute a command line in a Visual Basic Script

后端 未结 3 636
小蘑菇
小蘑菇 2020-12-16 01:43

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.

I tried this, but dont work:



        
3条回答
  •  清歌不尽
    2020-12-16 01:45

    Try something like this:

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

    EDIT:

    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
    

提交回复
热议问题