All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#中使用net,share命令时要注意的问题_.net资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/11 8:29:44 Browse times: 345 Comment times: 0

C#中使用net,share命令时要注意的问题_.net资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

C#中使用net share命令时要注意的问题_.net资料_编程技术-你的首页-uuhomepage.com

  最近的这个项目中有一要求就是要将数据放在局域网上共享,使其它机器来访问。这样就必须要将文件夹共享,本来是考虑用API来实现共享,不过后发现太繁琐,所以采用了NET SHARE这条WINDOWS命令。

System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = " /c net share " + shareName + "=" + sharePath;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.Start();

p.WaitForExit();

  shareName:可以是任何有效的共享名。sharePath:是要共享的完整路径。

  项目制作过程没有发现任何不对,但到了安装到program files目录下就出现问题了,不能正确的共享,排查发现是路径中有空格的原因。在网上找了一些文章,解决办法是加上引号即可:

p.StartInfo.Arguments = " /c net share " + shareName + "=\"" + sharePath + "\"";






There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.