如何从C#windows programe调用powershell脚本? [英] How to call to powershell script from C# windows programe?

查看:121
本文介绍了如何从C#windows programe调用powershell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的驱动器中有powershell脚本,我需要从c#windows programe执行它。我试过下面但不是.success



我是什么尝试过:



I have powershell script in my d drive and i need to execute it from c# windows programe .I tried below but not .success

What I have tried:

tring filepath = "D:\\JournalImport";
                String cmd = "-Command ";
                System.Diagnostics.Process process = new System.Diagnostics.Process();
              
                process.StartInfo.FileName = "D:\\JournalImport\\JrnlImport.ps1";
                
                process.StartInfo.WorkingDirectory = filepath;
                process.StartInfo.Arguments = cmd;
                process.Start();
                process.WaitForExit(15000000);
                process.Close();

推荐答案

这里有一个演练:从C#执行PowerShell脚本 - Keith Babinec的开发博客 [ ^ ]。
Here a walkthrough: Executing PowerShell scripts from C# – Keith Babinec's Development Blog[^].


这篇关于如何从C#windows programe调用powershell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆