简体   繁体   English

Powershell在新进程中和同一运行空间内调用脚本

[英]Powershell invoke script in new process and within the same runspace

I got within my application (process) an already configured c# Runspace v3. 我在应用程序(进程)中获得了一个已配置的c# Runspace v3。 I want to execute my PowerShell script in a new process, but within the same Runspace. 我想在一个新进程中但在同一Runspace中执行PowerShell脚本。 How could I accomplish this? 我该怎么做? I thought, when I start a PowerShell within an existing runspace, then that Runspace will be inherited to the new PowerShell: Unfortunately, this was not the case... 我以为,当我在现有运行空间中启动PowerShell时,该运行空间将继承到新的PowerShell:不幸的是,事实并非如此……

I have seen following interesting methods, but got no solution how these could help: RunspaceFactory.CreateOutOfProcessRunspace Invoke-Command 我看到了以下有趣的方法,但没有解决方案对它们的帮助: RunspaceFactory.CreateOutOfProcessRunspace Invoke-Command

PS: I can not change within my app the access from Runspace to a PowerShellProcessInstance and also I can not use PSRemoting PS:我无法在我的应用程序中更改从运行空间到PowerShellProcessInstance的访问权限,也无法使用PSRemoting

What you describe is impossible - a single runspace cannot span multiple processes. 您所描述的是不可能的-一个运行空间不能跨越多个进程。

Allow me to demonstrate the relevant hierarchical relationships with this state of the art graphic I whipped up in mspaint : 请允许我用在mspaintmspaint这种最先进的图形来演示相关的层次关系:

在此处输入图片说明

A runspace is bound to a single .NET AppDomain, and an AppDomain cannot span multiple processes. 一个运行空间绑定到一个.NET AppDomain,并且一个AppDomain无法跨越多个进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM