get the return value executed in dos command

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxoulmate
    New Member
    • May 2007
    • 77

    get the return value executed in dos command

    how to execute a command in dos in vb 6.,

    example:

    ping a computer on dos
    and then
    print the return value on a listbox.,

    tnx a lot.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Probably depends on what version of VB you're using. But you should be able to use Shell or ShellExecute to run the command, and use a batch file to determine the return code and write it to a file. Then read that file when you get back to your VB code.

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Killer has a great idea.

      I have been playing about with batch files lately, try:

      Code:
      REM Pinging...
      
      Ping [ipaddress] > Log.txt
      The results will then be output to Log.txt in the directory where your batch file is located.

      Now open this file in VB and process the data to find what you require.
      --------------------------------------------------------------
      <do you know how to create batch files?>
      Open Notepad > enter text above > save as > extension .bat not .txt
      Last edited by Killer42; Oct 29 '07, 01:42 AM. Reason: Added CODE tag

      Comment

      • xxoulmate
        New Member
        • May 2007
        • 77

        #4
        How to send the default value of ipaddress on the bat., file

        Do I need to edit the content of .bat.,
        example:
        open the batch file in vb then
        changes its content then save
        and run the batch file.,

        Thanks.
        Last edited by Killer42; Oct 30 '07, 03:25 AM.

        Comment

        • shrimant
          New Member
          • Sep 2007
          • 48

          #5
          Below is a working code which would run from VB or VBA on a Windows machine to execute any DOS command and display the result in a message box. I have used a Ping example, but any other command should work. Batch files are almost obsolete, although the DOS gurus still do a lot with it. The Windows scripting can do a lot more than the batch files.
          [CODE=vb]
          ExecuteDos "Ping sunrisetelecom. com"

          Function ExecuteDos(Comm As String)
          Set objShell = CreateObject("W Script.Shell")
          Set objExecObject = objShell.Exec(" %comspec% /c " & Comm)
          MsgBox objExecObject.S tdOut.ReadAll()
          End Function[/CODE]
          Last edited by Killer42; Oct 30 '07, 07:06 AM.

          Comment

          • xxoulmate
            New Member
            • May 2007
            • 77

            #6
            -----------------------------------------------
            i got a runtime error when i run the script.,
            runtime err: 438
            "object doesn't support this property or method"

            is there any reference i must include.,
            i am using OS 98

            tnx

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Which line produces the error?

              Comment

              • xxoulmate
                New Member
                • May 2007
                • 77

                #8
                Originally posted by Killer42
                Which line produces the error?
                the error points to line 5.,

                Comment

                • shrimant
                  New Member
                  • Sep 2007
                  • 48

                  #9
                  Originally posted by xxoulmate
                  the error points to line 5.,
                  Sorry xxoulmate...I don't even have a 98 installation around to re-produce the error, I have XP and 2003 servers around me.

                  Try Putting a set statement in your AutoExec.bat file something like below make sure the path of the Command.com file is correct:
                  Set COMSPEC=C:\WIND OWS\COMMAND.COM

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    Hm... so from the sound of it, the WScript.Shell object doesn't support the Exec method. Perhaps you have an old version of the scripting runtime. Have you tried Windows Update?

                    Comment

                    • sparklesasi
                      New Member
                      • Mar 2009
                      • 1

                      #11
                      Executing but command prompt is opening a second

                      Hi, the above code is working fine. But before executing the command, command prompt is opening for a second and after that only we'r getting the values. Instead of that how to hide the command prompt that is showing for one sec/ upto the result.

                      Cheers,
                      Sasi A

                      Comment

                      Working...