Hi,

I've developed an application for my company which auto-downloads DSS files from FTP location. My problems lies in File Conversion.
Currently, I'm using switch to convert DSS to WAV, code is given in below. But the problem is that even if I try using "-hide" args in the code a small windows (which says DECODING & has progress bar and a cancel button) still remains opens which enables a user to cancel/hamper the process of conversion.

Is their any way I can hide that? Or any other way I can convert DSS files to WAV without using Switch Software(http://www.NCH.com.au)?
My current code is as follows :

private void GenerateWavFiles()
        {
            RegistryKey key = Registry.LocalMachine.OpenSubKey("Software");
            if (SearchSubKey(key, "NCH Swift Sound") == true)
            {
                btnStartProcess.Enabled = false;
                Process proc = new Process();
                proc.StartInfo.FileName = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + @"\NCH Swift Sound\Switch\switch.exe";
                proc.StartInfo.Arguments = "-hide -clear -exit";
                proc.Start();
                lblStatus.Text = "Convert dss to wav. Please wait.....";
                sw.Write(Environment.NewLine + "Start convert dss to wav." + Environment.NewLine);
                while (!proc.HasExited)
                {
                    Application.DoEvents();
                }
                if (proc.HasExited)
                {
                    proc.StartInfo.Arguments = "-hide -convert -addfolder \"" + sDSSFolder + "\" -format .wav -outfolder \"" + sDSSFolder + "\" -overwrite ALWAYS -hide -exit";
                    proc.Start();
                    while (!proc.HasExited)
                    {
                        Application.DoEvents();
                    }
                }
                sw.Write("End convert dss to wav." + Environment.NewLine);
                lblStatus.Text = "Conversion finished.";
                btnStartProcess.Enabled = true;
            }
        }

You will need to include the statement: using System.Diagnostics;

You can use the ProcessStartInfo class to set many atributes including the setting the ProcessWindowStyle to Hidden.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;

Because C# dose not alow for default arguments I have writen several LaunchApp methods to alow for overloding.

#region LaunchApp
// You will need to include the statement: using System.Diagnostics;

static void LaunchApp(string sFileName,
                                         string sWorkingDirectory)
        {
            LaunchApp(sFileName, sWorkingDirectory, "", ProcessWindowStyle.Normal);
        }

        static void LaunchApp(string sFileName,
                                         string sWorkingDirectory,
                                         string Arguments)
        {
            LaunchApp(sFileName, sWorkingDirectory, Arguments, ProcessWindowStyle.Normal);
        }

        static void LaunchApp(string sFileName,
                                         string sWorkingDirectory,
                                         string Arguments,
                                         ProcessWindowStyle WindowStyle)
        {

            // Use ProcessStartInfo class to set many atributes
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;    // If false a new window will be created
            startInfo.UseShellExecute = false;   //When UseShellExecute is false, the WorkingDirectory property is not used to find the executable.
            startInfo.WindowStyle = WindowStyle; //Specified how a new window should appear when the system starts a process.
            if (sFileName.Length > 0) startInfo.FileName = sFileName;
            if (sWorkingDirectory.Length > 0) startInfo.WorkingDirectory = sWorkingDirectory;
            if (Arguments.Length > 0) startInfo.Arguments = Arguments;

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch
            {
                // Log error.
            }
        }


        static void LaunchApp(string sFileName,
                                         string sWorkingDirectory,
                                         string Arguments, 
                                         ProcessWindowStyle WindowStyle, 
                                         string sUserName, 
                                         System.Security.SecureString sPassword)
        {

            // Use ProcessStartInfo class to set many atributes
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = false;     // If false a new window will be created
            startInfo.UseShellExecute = false;    // When UseShellExecute is false, the WorkingDirectory property is not used to find the executable.
            startInfo.WindowStyle = WindowStyle;  // Specified how a new window should appear when the system starts a process.
            if (sFileName.Length > 0) startInfo.FileName = sFileName;
            if (sWorkingDirectory.Length > 0) startInfo.WorkingDirectory = sWorkingDirectory;
            if (Arguments.Length > 0) startInfo.Arguments = Arguments;
            if (sUserName.Length > 0) startInfo.UserName = sUserName;
            if (sPassword.Length > 0) startInfo.Password = sPassword;

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch
            {
                // Log error.
            }
        }
        #endregion LaunchApp

I hope this helps.

Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

This article has been dead for over six months. Start a new discussion instead.