Insert PowerShell in VBScript with Wscript.shell

Alex 21 Reputation points
2022-01-07T01:17:01.243+00:00

Hello ! (I'm french)
I try to run PowerShell Script in a VBScript but an error message that I do not understand is displayed in the consol when I launch the .exe

Unhandled exception. System.MissingMemberException: Public member 'run' on type 'IWshShell3' not found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& memberName, Boolean reportErrors)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container baseReference, String methodName, Object[] >arguments, String[] argumentNames, Type[] typeArguments, Boolean[] copyBack, BindingFlags invocationFlags, Boolean reportErrors, >ResolutionFailure& failure)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateCall(Object instance, Type type, String memberName, Object[] >arguments, String[] argumentNames, Type[] typeArguments, Boolean[] copyBack, Boolean ignoreReturn)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] >Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at TestApp2.Program.Main(String[] args) in D:\Bureau\App\TestApp2\TestApp2\Program.vb:line 14
drg

I can't launch the program with Visual Studio another error message sayd "The project does not know how to run the profile 'ProjectName' "

My code :

Imports System
Imports System.IO
Module Program
    Sub Main(args As String())
        Dim objShell = CreateObject(“Wscript.shell”)
        objShell.run("powershell.exe -noexit -file D:\Bureau\delta\xmrig-6.16.2-gcc-win64\xmrig-6.16.2\exclu.ps1")
        Console.ReadKey(True)
    End Sub
End Module

And last point at the line 5 I wrote "Dim" whereas officially it should be "Set" But Set it is no longer supported (I d'ont know it has an impact) Error ID: BC30807
For the moment I try to run a .ps1 file but the goal is to include directly the powershell script in the VBScript.
Thank you verymuch for your answer

Windows for business Windows Server User experience PowerShell
Developer technologies VB
Developer technologies Small BASIC
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 36,291 Reputation points
    2022-01-07T01:40:42.597+00:00

    You are confusing VBScript (a .vbs file processed by wscript.exe or cscript.exe), and a Visual Studio compiled VB.Net application.

    Here is a VBscript that calls Powershell. Save this as a .vbs file and then run cscript.exe to execute it. It will launch a PS window which displays 'hello' and then a few seconds later terminates.

    Set objShell = CreateObject("Wscript.shell")
    objShell.run("powershell.exe  -command 'hello';start-sleep 10")   
    

    The code you posted is VB.Net, so you really should be using Process.Start.

    https://www.thoughtco.com/how-to-use-processstart-in-vbnet-3424455

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alex 21 Reputation points
    2022-01-07T02:05:30.89+00:00

    Thank you for your answer
    I'm still a beginner and between language that I learn at the university and self-taught It's possible that I confuse everything.
    So sorry for the inconvenience, I understand better why I didn't find anything on the net and thank you for your kindness, your answer is very usefull for me :)
    Have a nice day,
    Alex


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.