C# Command Prompt

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastian Silva
    New Member
    • Feb 2012
    • 6

    C# Command Prompt

    Hi all,

    Why when i create ProcessStartInf o to execute "cmd.exe" with arguments "nbstat -a 192.168.1.2" gives me a error " nbstat is not recognized as internal or external command" but in a normal(not a cmd executed by c#) command prompt it works!

    Any ideas?

    Many thanks,
    Sebastian
  • Sebastian Silva
    New Member
    • Feb 2012
    • 6

    #2
    sorry the command is "nbtstat".. .

    Comment

    • PsychoCoder
      Recognized Expert Contributor
      • Jul 2010
      • 465

      #3
      Show us how you're calling the process, seeing it may help get you a solution faster because then we'll be able to see how you're doing it.

      Comment

      • Sebastian Silva
        New Member
        • Feb 2012
        • 6

        #4
        Hi, thanks for the answer,
        the code;

        System.Diagnost ics.Process process1;
        process1 = new System.Diagnost ics.Process();
        process1.Enable RaisingEvents = false;
        string strCmdLine;
        strCmdLine = "/C nbtstat -a 192.168.2.110 | find \"Endereço MAC\" > teste.txt";
        System.Diagnost ics.Process.Sta rt("CMD.exe", strCmdLine);
        process1.Close( );


        Thanks,
        Sebastian

        Comment

        • GaryTexmo
          Recognized Expert Top Contributor
          • Jul 2009
          • 1501

          #5
          Wow, I get the same result. That makes no sense either... I can run notepad.exe just fine and it's in the exact same folder location.

          What are you trying to do? I googled around and it seems like people using nbtstat are usually trying to find a MAC address. If this is the case for you there are apparently other ways to do this that you may want to look into.

          Definitely messed up behaviour though. I couldn't find any explanations over google... I'm as boggled as you are.

          Comment

          • PsychoCoder
            Recognized Expert Contributor
            • Jul 2010
            • 465

            #6
            I used the following code and got no error at all, show us the cose you're using.

            Code:
            public static void Process()
            {
                var process1 = new System.Diagnostics.Process {EnableRaisingEvents = false};
                const string strCmdLine = "/C nbtstat -a 192.168.2.110 | find \"Endereço MAC\" > teste.txt";
                System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
                process1.Close();
            
            }

            Comment

            • Sebastian Silva
              New Member
              • Feb 2012
              • 6

              #7
              I'll try your solution PhysoCoder thank you for your answer i'll give the feedback...

              by the way Gary Texmo i did it in console application (not windows form) and it worked... i understand the difference but...

              thank you all for the answer...

              Sebastian

              Comment

              • Sebastian Silva
                New Member
                • Feb 2012
                • 6

                #8
                didn't work in windows form... maybe some kind of configuration of Visual studio...

                thank you again!

                Comment

                • GaryTexmo
                  Recognized Expert Top Contributor
                  • Jul 2009
                  • 1501

                  #9
                  See that's extra weird because I was doing mine in a console application and it was still telling me it couldn't find nbtstat. As I mentioned, I tried notepad (which is in the exact same folder) and it worked fine. My code was roughly equivalent to PsychoCoder's.

                  Glad it works magically for you though!

                  Comment

                  • Sebastian Silva
                    New Member
                    • Feb 2012
                    • 6

                    #10
                    Yeah really weird...

                    my come in console is the similar or the same...
                    above is listed my code:


                    Code:
                    
                    public void cmdFunc(string ip)
                            {
                                System.Diagnostics.Process process1;
                                process1 = new System.Diagnostics.Process();
                                process1.EnableRaisingEvents = false;
                                string strCmdLine;
                                strCmdLine = "/C nbtstat -A "+ip+" | find \"Endereço MAC\" > teste.txt";
                               
                                System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
                                process1.Close();
                                MessageBox.Show(strCmdLine);
                    
                    
                            }

                    Hope you find a solution!

                    Comment

                    Working...