我正在Windows RT中开发应用程序。我确实需要在Windows RT(C#)中运行/调用PowerShell或CMD命令。请帮助我弄清楚。 在此先感谢Windows RT中的Powershell命令
3
A
回答
1
虽然无法直接针对Windows RT中的PowerShell .NET引擎编程,但可以通过套接字访问桌面。但是,这假定您有能力确保桌面套接字侦听器已安装&正在运行。但是,在运行&的情况下,您可以向其发出命令并让其调用cmd.exe(或通过EXE或in-proc引擎的powershell)。在WinRT中有什么好处是可以使用PowerShell远程端点连接到&的引擎组件。考虑到最终只是一个套接字,可以由微软以外的人来完成,但你必须通过很多WS-MAN协议来弄清楚它是如何工作的。我想通过套接字发送一个简单的字符串可能会更简单,例如'powershell -command "& { Get-Process }"'
或'cmd /c dir c:\'
。 :-)
下面是一些代码片段作为一个概念证明:
WinRT的代码片段:
private async void _button_OnClick(object sender, RoutedEventArgs e)
{
string content;
try
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("user-agent",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
var response = await client.GetAsync("http://localhost:54649/");
if (response.StatusCode == HttpStatusCode.OK)
{
content = await response.Content.ReadAsStringAsync();
}
else
{
content = response.StatusCode.ToString();
}
}
catch (Exception ex)
{
content = ex.Message;
}
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
_textBlock.Text = content;
});
}
在桌面端,这里有一个脑死亡MVC控制器的一个片段:
public class HomeController : Controller
{
//
// GET: /Home/
public string Index()
{
return "Hello World. The time is " + DateTime.Now;
}
}
+0
亲爱的基思谢谢你的回复。我搜索了网络为win rt创建桌面套接字,但徒劳无功。请指导我为Win rt创建桌面套接字 – sathia
相关问题
- 1. 在Windows中等效的Unix命令Powershell
- 2. Windows中的Linux Bash Shell命令Powershell
- 3. 新的对象上的Windows RT Powershell(PermissionDenied)
- 4. 在命令行和Windows PowerShell中Imagemagick命令
- 5. PowerShell中的IPython Shell命令
- 6. Powershell Subst命令
- 7. PowerShell命令让TFS2013
- 8. AWS CLI Windows Powershell命令错误
- 9. Windows PowerShell:更改命令提示符
- 10. Windows Powershell相当于bash命令
- 11. PowerShell - 远程运行Windows命令
- 12. Windows 10开始全屏PowerShell命令?
- 13. 从获取来自语音命令文本{*}在Windows Phone 8.1 RT
- 14. 在C#中的Powershell命令#
- 15. C#命令中的PowerShell
- 16. 如何从Windows命令行向SQL PowerShell发送多个命令?
- 17. Powershell Get-ChildItem命令
- 18. PHP PowerShell命令
- 19. PowerShell命令
- 20. Windows RT与Windows 8
- 21. Powershell命令查看命令行中显示的全部信息
- 22. Linux的PowerShell命令找不到命令
- 23. 下载Windows中大型文件的命令提示符/ PowerShell的
- 24. Windows RT和c#
- 25. 运行命令在PowerShell中
- 26. Powershell命令没有等待
- 27. PowerShell中相当于时间的命令
- 28. workon命令不会在Windows PowerShell中工作,以激活的virtualenv
- 29. 在Windows批处理文件中使用PowerShell命令的输出
- 30. 用于更改文件中文本的Windows PowerShell命令
你不能使用正常的C#API的PowerShell(未测试)?恩。 http://www.codeproject.com/Articles/18229/How-to-run-PowerShell-scripts-from-C –
Graimer谢谢你的回复。在发布此查询之前,我在codeproject中检查了文章,但名称空间system.management.automation在Win RT中受到限制。 – sathia