C# 为什么exe没有在程序文件中运行?

C# 为什么exe没有在程序文件中运行?,c#,exe,system.diagnostics,grib,C#,Exe,System.diagnostics,Grib,我正在开发wpf应用程序。我正在使用以下代码运行degrib.exe public static void GenerateCsvFile(string fileName) { try { MessageBox.Show("Csv Error"); MessageBox.Show("File Name : " + fileName);

我正在开发wpf应用程序。我正在使用以下代码运行degrib.exe

 public static void GenerateCsvFile(string fileName)
        {
            try
            {
                MessageBox.Show("Csv Error");
                MessageBox.Show("File Name : " + fileName);
                MessageBox.Show("WorkingDirectory" + new FileInfo(fileName).DirectoryName);

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
                startInfo.Arguments = @"" + fileName + "" + " -C -msg 1 -Csv";
                startInfo.UseShellExecute = true;
                startInfo.WorkingDirectory = new FileInfo(fileName).DirectoryName;
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
                process.Close();

                System.Diagnostics.Process process1 = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo1 = new System.Diagnostics.ProcessStartInfo();
                startInfo1.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo1.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
                startInfo1.Arguments = @"" + fileName + "" + " -C -msg all -nMet -Csv";
                startInfo1.UseShellExecute = true;
                startInfo1.WorkingDirectory = new FileInfo(fileName).DirectoryName;
                process1.StartInfo = startInfo1;
                process1.Start();
                process1.WaitForExit();
                process1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Degrib Error");
                Utility.ShowErrorMessage(ex);
            }
        }

degrib.exe从grib文件生成csv文件。这里
http://www.nws.noaa.gov/mdl/degrib/index.php
是对degrib的解释。在上述函数中,
fileName
是grib文件的路径。如果grib文件放置在程序文件以外的任何文件夹中,则上述功能会从grib文件中装箱csv文件。如果我已将grib文件放置在程序文件或程序文件中的任何其他文件夹中,则相同的函数将不会生成csv文件。同样的函数也不适用于AppData文件夹。为什么会这样?您能为我提供上述问题的解决方案吗?

默认情况下
Vista
中的
UAC
Win7
不授予应用程序在程序文件中的写入权限,除非它们以提升的访问权限启动。 您可以通过添加以下内容来完成此操作:

startInfo.Verb = "runas";
然而,阅读
degrib
手册时,我注意到它接受输入和输出参数。 因此,在您的情况下,建议您为生成的csv文件使用预定义的位置。


用户权限。以管理员身份运行该进程。你必须向编写degrib的人询问此问题…@leppie:AppData,据我所知,即使没有管理员权限,也必须工作。你是否使用过类似工具来确定进程是否已启动?大多数程序都有一个参数,允许你设置输出路径,也许grib也有一个参数。在比Vista更新的Windows中,程序文件不是您应该更改或存储数据的地方(顺便说一句,微软建议不要在Vista之前很久使用此位置)。我使用的是Windows xp,因为Windows xp具有类似的行为,只是默认情况下权限编辑是隐藏的。转到工具>文件夹选项>查看并取消选中“使用简单文件共享[推荐]”。检查您的WPF应用程序是否具有写入权限。未选中“使用简单文件共享[推荐]”。我的WPF应用程序具有写入权限。我正在成功地对应用程序数据文件夹中的其他文件执行写入操作。我能够在应用程序数据文件夹中执行所有必需的功能。我无法使用上述功能删除grib文件如果您的应用程序在应用程序数据中具有写入权限,但degrib.exe没有写入权限,您可以通过直接在degrib文件夹中生成csv文件并使用System.IO.file.move(sourceFile,destinationFile)将其移动到您的AppData文件夹中来绕过此问题。这不是一个最佳解决方案,但它将帮助您完成工作。
   -in [File]
     You can provide the file to read the GRIB message from either:
     1) right after "degrib",
     2) using the "-in [File]" option,
     3) on standard input.
   -out [File]
      Name of the file to store the results.  Must have 1 and only 1 dot in
      the name, and the extension must be 3 characters.  The extension will
      be replaced depending on file format.
   -namePath [Path]
      Name of a directory to put the files in.
      Only applicable if -out is NOT Specified.