We help IT Professionals succeed at work.

VB6 - Get Powershell script result via VB6

Hi, I normally use below Powershell script to pull the Windows Update status.

get-service wuauserv | select Displayname,Status,ServiceName,Can*

Open in new window


Now what i would like to do is to run that script via my VB6 application.
So by clicking on a button, it give me the result in a msgbox.

I'm able to do it for the "ipconfig" but not able for "wuauserv"

This is what i have so far:
Private Sub Command1_Click()
'get-service wuauserv | select Displayname,Status,ServiceName,Can*

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("ipconfig")

Do While oExec.Status = 0
     'WScript.Sleep 100
Loop
MsgBox oExec.StdOut.ReadAll
End Sub

Open in new window


Thanks for your help
Comment
Watch Question

Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This should give you the idea:

Test

Private Sub Test()
    'get-service wuauserv | select Displayname,Status,ServiceName,Can*

    Dim WshShell, oExec, sCommandLine

    sCommandLine = "ipconfig"

    Set WshShell = CreateObject("WScript.Shell")


    Set oExec = WshShell.Exec(sCommandLine)

    Do While oExec.Status = 0
         'WScript.Sleep 100
    Loop

    MsgBox oExec.StdOut.ReadAll


    sCommandLine = "powershell -executionpolicy bypass -Command ""get-service wuauserv | select Displayname,Status,ServiceName,Can*"""

    Set oExec = WshShell.Exec(sCommandLine)

    Do While oExec.Status = 0
         'WScript.Sleep 100
    Loop

    MsgBox oExec.StdOut.ReadAll

End Sub

Open in new window


»bp