简体   繁体   中英

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." 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. 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:

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

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...

Another way to get Deepfreeze state using registry key

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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