简体   繁体   English

如何在 c# 中使用命令提示符运行 deepfreeze 命令行

[英]How to run deepfreeze command line using command prompt in c#

i am working with services using C#, and for some stuff i need to get deepfreeze state of the station (frozen or thawed), for this found this on Faronic's documentation , when i use the following command in command prompt: C:\WINDOWS\syswow64\DFC.exe get /ISFROZEN it works and returns "THAWED."我正在使用 C# 处理服务,对于某些东西,我需要获取站的 deepfreeze state(冻结或解冻),因为这在Faronic 的文档中找到了这个,当我在命令提示符下使用以下命令时: C:\WINDOWS\syswow64\DFC.exe get /ISFROZEN它起作用并返回“THAWED”。 or "FROZEN."或“冻结”。 so i decided in my C# program to run a command prompt and redirect the Standard output to get the result of the command into a string variable, but it has not worked, i tried with any other commands and it works, i do not understand where is the problem.所以我决定在我的 C# 程序中运行命令提示符并重定向标准 output 以将命令的结果放入字符串变量中,但它没有用,我尝试了任何其他命令并且它有效,我不明白在哪里是问题所在。 there is the DFC.exe download link if it does not exists ( complete the captcha and click to download) It is my third day on it so i need help.. thank's for everyone, there is sample code:如果不存在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();
 }

the command still not works.. but i found another way to get deepfreeze state, using registry key该命令仍然不起作用..但我找到了另一种方法来获得 deepfreeze state,使用注册表项

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...另一方面,我仍然无法在我的 C# 程序上运行 deepfreeze 命令行,如果有人有答案,请帮助...

Another way to get Deepfreeze state using registry key使用注册表项获取 Deepfreeze state 的另一种方法

$path = 'HKLM:\SOFTWARE\WOW6432Node\Faronics\Deep Freeze 6'
$Key = 'DF Status'
$State = Get-ItemPropertyValue -path $path -name $Key -ErrorAction SilentlyContinue

if ($State='Frozen') {Echo "Deepfreeze is currently Frozen"} else {Echo "Deepfreeze is currently UN-Frozen"}

pause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM