Question : C# Return code error

I have an application that I am working on to grab the MAC address of a machine from a registry key value.  I then take that value and compare it to a text file that has 2 columns, MAC and Host name.  The idea is to take the MAC address from the registry, compare it to the file, and use the host name and construct a NETDOM command to be passed to join the computer to the domain with the proper host name.

The problem I have is in calling a function that will execute the command in a "cmd" shell, but is getting an error "not all code paths return a value".

Here is the code for the function:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
public static int ExecuteCommand(string Command, int Timeout)
        {
            try
            {
                int ExitCode;
                Process Process;
                ProcessStartInfo ProcessInfo;
                ProcessInfo = new ProcessStartInfo("cmd.exe", "/C" + Command);
                ProcessInfo.CreateNoWindow = false;
                ProcessInfo.UseShellExecute = false;
                Process = Process.Start(ProcessInfo);
                Process.WaitForExit(Timeout);
                ExitCode = Process.ExitCode;
                Process.Close();
                return ExitCode;
            }
            catch (TimeoutException objException)
            {
                MessageBox.Show(objException.ToString());
            }
        }


The base of the code is as follows.  I have not included the string calls that contain the structure of some of the calls, like the Registery.  Trust me that the myvar string contains the values of the Registry Key that holds the MAC address.  And that the value in MyVar will be the MAC addrese to compare to the values in the txt file.  That part is fine, it is the calling of the ExecuteCommand function that has the issue.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
 private void Form1_Load(object sender, EventArgs e)
        {
##################################
##################################
calling of varriables that you do not need to see :-)
##################################
##################################
            foreach (string line in File.ReadAllLines("C:\\IP_DATA.txt"))
            {

                string[] parts = line.Split(' ');
                foreach (string part in parts)
                {
                    string[] regreturn = myvar.Split(';');
                    foreach (string MyVal in regreturn)
                    {
                        if (MyVal.ToUpper().ToString() == part.ToUpper().ToString())
                        {
                            string NetDomCommand = "NETDOM ADD " + parts[1].ToUpper().ToString() + " /Domain:" +
                             TRDomain.ToString() + " /Userd:" + UserID.ToString() + " /Passwordd:" +
                             UserPW.ToString() l";
                            
                            try
                            {
                                ExecuteCommand(NetDomCommand.ToString(), 0);
                            }
                            catch (Exception trs)
                            {
                                MessageBox.Show("{0}} Second exception caught.", trs.ToString());
                            }
                        }
                    }
                    i++;
                }
            }
}


The error is :  Error      1      'Name_Changer_1.Form1.ExecuteCommand(string, int)': not all code paths return a value      ###path to executable####      84      27      Name_Changer2

Any advise is appreciated.

Answer : C# Return code error

This option is for using MS word but you aslso need to reference the particular printer for 2 sided printing

http://www.associatedcontent.com/article/343395/how_to_print_a_book_from_microsoft.html?cat=59
Random Solutions  
 
programming4us programming4us