Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从Azure VM内部访问数据?_C#_Asp.net_Azure_Virtual Machine_Azure Virtual Machine - Fatal编程技术网

C# 如何从Azure VM内部访问数据?

C# 如何从Azure VM内部访问数据?,c#,asp.net,azure,virtual-machine,azure-virtual-machine,C#,Asp.net,Azure,Virtual Machine,Azure Virtual Machine,假设我有一个在微软Azure上运行的虚拟机windows。 假设我在虚拟机上有程序Y和Z,它们正在记录一些关键数据。假设我在VM中还有一个程序X,它接受一些参数并根据过滤器返回一些关键数据 现在,我正在构建一个前端webapp,一个ASP.NET网站,上面提到的VM的所有者可以在这里登录并查看程序X可以提供的数据 我已经在VM中运行了日志程序,并安装了程序X。如何访问VM中的可执行文件、向其传递参数、运行它并将结果返回给我?这可行吗?有人能建议我如何做到这一点吗 谢谢 您可以使用System.D

假设我有一个在微软Azure上运行的虚拟机windows。 假设我在虚拟机上有程序Y和Z,它们正在记录一些关键数据。假设我在VM中还有一个程序X,它接受一些参数并根据过滤器返回一些关键数据

现在,我正在构建一个前端webapp,一个ASP.NET网站,上面提到的VM的所有者可以在这里登录并查看程序X可以提供的数据

我已经在VM中运行了日志程序,并安装了程序X。如何访问VM中的可执行文件、向其传递参数、运行它并将结果返回给我?这可行吗?有人能建议我如何做到这一点吗


谢谢

您可以使用System.Diagnostic.Process类运行另一个可执行文件:

抄袭自:

如果您的程序X不涉及GUI,您可以尝试在PS远程会话上运行它。下面是一个关于如何配置powershell remote的好方法

此外,以下是有关需要在防火墙上打开的端口的信息

默认情况下,PowerShell将使用以下端口进行通信 它们是与WinRM相同的端口

TCP/5985=HTTP

TCP/5986=HTTPS

如果它涉及GUI,据我所知,唯一的解决方案是使用RDP远程处理VM

此外,在internet上公开WinRM或RDP端口不是一个好主意。我建议您在Azure上创建一个VPN,并通过VPN使用WinRM或RDP

// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "X.exe";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();