EventWaitHandle "No handle of the given name exists" Vagrant 远程虚拟机 C# PowerShell
EventWaitHandle "No handle of the given name exists" Vagrant remote Virtual Machine C# PowerShell
我在 Vagrant Hyper-V 虚拟机上有一些代码 运行ning,等待它在启动前被联系。我试图告诉 EventWaitHandler 继续通过远程 PowerShell 会话。等待的代码是C#,激活的代码是PowerShell。这是等待的代码:
var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);
var security = new EventWaitHandleSecurity();
security.AddAccessRule(rule);
bool created;
var wh = new EventWaitHandle(false, EventResetMode.AutoReset, "EventName", out created, security);
Console.WriteLine("Waiting to be started...");
wh.WaitOne();
我遇到的问题是,当我尝试通过远程 powershell 会话获取 eventwaithandler 时,它告诉我它不存在。这是获取 waithandler 的 powershell 代码:
Enter-PSSession -ComputerName MyVm
# This works unless it is run in a remote session
$Mutex = [System.Threading.EventWaitHandle]::OpenExisting("EventName")
当我在远程会话中 运行 这段代码时,出现以下错误:
Exception calling "OpenExisting" with "1" argument(s): "No handle of the given name exists."
然后它给了我失败的代码,它指向上面的 "OpenExisting" 行。
只是想补充一点,它在同一台机器上工作得很好,所以我知道它应该 工作,但不能通过远程会话。
任何help/pointers将不胜感激。
谢谢
找到答案,我想 post 在这里:
我唯一需要做的就是在进程名称前加上 "global\"
像这样初始化(C#):
var wh = new EventWaitHandle(false, EventResetMode.AutoReset, "Global\EventName", out created, security);
并像这样通过 PowerShell 访问它:
$Mutex = [System.Threading.EventWaitHandle]::OpenExisting("Global\EventName")
即使在远程会话中也能正常工作...
我在 Vagrant Hyper-V 虚拟机上有一些代码 运行ning,等待它在启动前被联系。我试图告诉 EventWaitHandler 继续通过远程 PowerShell 会话。等待的代码是C#,激活的代码是PowerShell。这是等待的代码:
var users = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);
var rule = new EventWaitHandleAccessRule(users, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow);
var security = new EventWaitHandleSecurity();
security.AddAccessRule(rule);
bool created;
var wh = new EventWaitHandle(false, EventResetMode.AutoReset, "EventName", out created, security);
Console.WriteLine("Waiting to be started...");
wh.WaitOne();
我遇到的问题是,当我尝试通过远程 powershell 会话获取 eventwaithandler 时,它告诉我它不存在。这是获取 waithandler 的 powershell 代码:
Enter-PSSession -ComputerName MyVm
# This works unless it is run in a remote session
$Mutex = [System.Threading.EventWaitHandle]::OpenExisting("EventName")
当我在远程会话中 运行 这段代码时,出现以下错误:
Exception calling "OpenExisting" with "1" argument(s): "No handle of the given name exists."
然后它给了我失败的代码,它指向上面的 "OpenExisting" 行。
只是想补充一点,它在同一台机器上工作得很好,所以我知道它应该 工作,但不能通过远程会话。
任何help/pointers将不胜感激。
谢谢
找到答案,我想 post 在这里:
我唯一需要做的就是在进程名称前加上 "global\" 像这样初始化(C#):
var wh = new EventWaitHandle(false, EventResetMode.AutoReset, "Global\EventName", out created, security);
并像这样通过 PowerShell 访问它:
$Mutex = [System.Threading.EventWaitHandle]::OpenExisting("Global\EventName")
即使在远程会话中也能正常工作...