.net cmd Proces.Start()无法更改目录 [英] .net cmd Proces.Start() Can't Change Directory

查看:68
本文介绍了.net cmd Proces.Start()无法更改目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我的问题标题已经很清楚了.

I think my question title is already crystal clear.

我通过传递"cmd.exe"作为参数来调用 Process.Start()方法.但是以某种方式执行程序时,出现的命令提示符在我的项目文件夹中将我的 .../bin/debug/作为其目录.我希望它改为 C:.

I am invoking Process.Start() method by passing, "cmd.exe" as parameter. But somehow when I execute the program the command prompt that appeared has my .../bin/debug/ in my project folder as its directory. I wanted it to change to C: instead.

有人可以建议我吗?

推荐答案

这是为任何类型的进程设置指定工作目录的正确方法:

This is the proper way to set a specified working directory for any kind of process:

var processStartInfo = new ProcessStartInfo();
processStartInfo.WorkingDirectory = @"c:\";
processStartInfo.FileName = "cmd.exe";

// set additional properties     
Process proc = Process.Start(processStartInfo);

这篇关于.net cmd Proces.Start()无法更改目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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