請問,我想用按鈕事件輸入
Powershell中的以下命令,我應該如何做,請教各位,謝謝。
$Credential =New-Object System.Management.Automation.PSCredential 'administrator',(convertto-securestring $("qwe123!@#") -asplaintext -force)
Enter-PSSession 192.168.200.128 -credential $Credential
netsh advfirewall firewall set rule name = 'rdp' new action = allow
請問以上代碼,我應該如何在C# 桌面版 button_click 事件做到以上代碼,謝謝
uj5u.com熱心網友回復:

有沒有大神能幫幫。。。
uj5u.com熱心網友回復:
親測可用private static string command = "$Credential =New-Object System.Management.Automation.PSCredential 'administrator',(convertto-securestring $('qwe123!@#') -asplaintext -force) ; " +
"Enter-PSSession 192.168.200.128 -credential $Credential ;" +
"netsh advfirewall firewall set rule name = 'rdp' new action = allow";
static void Main(string[] args)
{
using (PowerShell ps = PowerShell.Create(RunspaceMode.NewRunspace)) {
using (var pip = ps.Runspace.CreatePipeline())
{
pip.Commands.AddScript(command);
foreach (var res in pip.Invoke())
{
Console.WriteLine(res);
}
foreach (var str in pip.Error.ReadToEnd())
{
Console.WriteLine(str);
}
}
}
Console.ReadKey();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/36384.html
標籤:C#
上一篇:請問在VB.Net中如何觸發DataGridView.CellValidating事件的方法
下一篇:請教大佬們一個問題:別人共享一個sharepoint的檔案夾給我,我希望通過c#代碼操作這個檔案夾,怎么連接這種secure link?
