1     public static class ShareFolder
 2     {
 3         /// <summary>
 4         /// 自动为用户创建及设置共享目录,以方便用户。
 5         /// </summary>
 6         public static void SetShareFolder()
 7         {
 8             const string shareFolderPath = @"C:\SML\ShareFolder";
 9 
10             string proFolderPath = Path.Combine(shareFolderPath, "PRO");
11 
12             if (!Directory.Exists(shareFolderPath))
13             {
14                 Directory.CreateDirectory(shareFolderPath);
15             }
16 
17             if (!Directory.Exists(proFolderPath))
18             {
19                 Directory.CreateDirectory(proFolderPath);
20             }
21 
22             string args = string.Format(@"net share FlexiPrintShareFolder={0} /grant:everyone,full", shareFolderPath);
23          
24             var psi = new ProcessStartInfo("netsh", args);
25             psi.UseShellExecute = true;
26             psi.Verb = "runas";
27             psi.CreateNoWindow = true;
28             psi.WindowStyle = ProcessWindowStyle.Hidden;
29             psi.UseShellExecute = true;
30             Process.Start(psi).WaitForExit();
31         }
32     }

 

posted on 2016-08-05 10:37  JustYong  阅读(158)  评论(0编辑  收藏  举报