簡體   English   中英

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

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

我正在使用 C# 處理服務,對於某些東西,我需要獲取站的 deepfreeze state(凍結或解凍),因為這在Faronic 的文檔中找到了這個,當我在命令提示符下使用以下命令時: C:\WINDOWS\syswow64\DFC.exe get /ISFROZEN它起作用並返回“THAWED”。 或“凍結”。 所以我決定在我的 C# 程序中運行命令提示符並重定向標准 output 以將命令的結果放入字符串變量中,但它沒有用,我嘗試了任何其他命令並且它有效,我不明白在哪里是問題所在。 如果不存在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();
 }

該命令仍然不起作用..但我找到了另一種方法來獲得 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;
    }

也許它會幫助某人。 另一方面,我仍然無法在我的 C# 程序上運行 deepfreeze 命令行,如果有人有答案,請幫助...

使用注冊表項獲取 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