vb.net - Running powershell scripts from within a .NET windows app -


I'm going to need to run the script from within a vb.net windows application.

I found the script background right;

  Runspace = RunspaceFactory.CreateRunspace () Using MyPipeline.Commands.AddScript MyRunSpace as using MyRunSpace.Open () MyPipeline pipeline = MyRunSpace.CreatePipeline (AS) ( "Import modules -name "& amp; moduleName & amp; vbCrLf & amp;" (the module -name "& amp; moduleName & amp;") .version ") with the use of the end result of lackluster results = MyPipeline.Invoke () ' Do something using MyRunSpace.Close () end  

However, I now need to be able to do powerhell runs (not in the background) such as When signs are found;

  set ExecutionPolicy unrestricted  

If you see I'm currently seeing in Microsoft.PowerShell.ConsoleHost name space I can use something like;

  dim config = RunspaceConfiguration.Create ConsoleShell.Start (config, "Windows PowerShell", "", New String () { ""})  

Can someone advise me ???

EDIT: I have fudged it a bit with this;

  public function RunPowershellViaShell (ByVal scriptText As String) Integer Dim execProcess New System.Diagnostics.Process dim as the psScriptTextArg = "-NoExit -Command" "& amp; get module -List "" "" retarded PsScriptTextArg = '-NoExit -Command "" & Amp; set executionPolicy unrestricted "" "" retarded psScriptTextArg = "" -NoExit -Command "" "& amp; scriptText & amp;" "" " ExecProcess.StartInfo.WorkingDirectory = Environment.SystemDirectory & amp; "\ WindowsPowershell \ v1.0 \" execProcess.StartInfo.FileName = "PowerShell.exe" execProcess.StartInfo.Arguments = psScriptTextArg execProcess .startInfo.UseShellExecute = True Return execProcess.Start Expiration Ceremony  

But there will be Is there a better way to do ??

There is a distinction between the powerchef engine and its host. Want to run the engine inside your app but to handle those signals, a different host (which is also hosting a PowerShell engine) sets fire to modify your application. To look at yourself as a host to work Please Then you take a look at the signal (feedback-host) and pop dialog box or whatever it is. See also.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -