0

我正在使用 C# 处理服务,对于某些东西,我需要获取工作站的深度冻结状态(冻结或解冻),因为这在Faronic 的文档中找到了这一点,当我在命令提示符下使用以下命令时:C:\WINDOWS\syswow64\DFC.exe get /ISFROZEN 它可以工作并返回“解冻。” 或“冻结”。所以我决定在我的 C# 程序中运行命令提示符并重定向标准输出以将命令的结果转换为字符串变量,但它没有工作,我尝试了任何其他命令并且它工作,我不明白在哪里是问题所在。如果DFC.exe 不存在,则有下载链接(完成验证码并单击下载)这是我的第三天,所以我需要帮助..谢谢大家,有示例代码:

string pathDf = @"C:\WINDOWS\syswow64\DFC.exe";
string cmdline = string.Format("{0} get /ISFROZEN ", pathDf);
string msg = "";
if (File.Exists(pathDf))
{
   Process cmd = new Process();
   ProcessStartInfo startInfo = new ProcessStartInfo();
   startInfo.WindowStyle = ProcessWindowStyle.Normal;
   startInfo.FileName = "cmd.exe";
   startInfo.CreateNoWindow = false;
   startInfo.RedirectStandardInput = true;
   startInfo.RedirectStandardOutput = true;
   startInfo.UseShellExecute = false;
   cmd.StartInfo = startInfo;
   cmd.Start();
   cmd.StandardInput.WriteLine(cmdline);
   cmd.StandardInput.Flush();
   cmd.StandardInput.Close();
   cmd.WaitForExit();
   Console.WriteLine(cmd.StandardOutput.ReadToEnd());
   Console.ReadKey();
 }
4

1 回答 1

0

the command still not works .. but i found another way to get deepfreeze state , using registry key

private static string GetDeepFreezeState()
    {
        string result = "";
        try
        {     
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Faronics\Deep Freeze 6");
            if (key != null)
            {
                Object o = key.GetValue("DF Status");
                if (o != null)
                {
                    result = o.ToString();                      
                }
            }
        }
        catch (Exception ex)  
        {
            //react appropriately
            FilesUtilities.WriteLog(ex.Message,FilesUtilities.ErrorType.Error); 
        }
        return result;
    }

Maybe it will help someone. On the other hand i still not able to run deepfreeze command line on my C# program, if someone has an answer , please help...

于 2020-12-13T07:16:12.360 回答