i need to shell out a cmd.exe command and get the response

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • James King
    New Member
    • Aug 2010
    • 2

    i need to shell out a cmd.exe command and get the response

    i want to use the "SYSTEMINFO |find/i"Total Physical Memory:"" command and then get the response into a textbox(field) within access.

    I have a database of all MachineNames in the company and for each machine name i have a field for the Memory, CPU, WindowsInstallD ate etc etc but i want to be able to use a 'refresh/update' CmdButton on the form which will query the machine and update the relevant fields on the form.

    i have been able to write the reply into >C:\output.tx t and then read the contents of the output.txt file back into access and use that.... but ewwwww!!!! that's very messy!!!

    there must be a simple way to set it as a variable?

    like
    Code:
    StrTempMemory = shell(CMD.exe "SYSTEMINFO |find/i'Total Physical Memory:'")
    and then Textbox.Value = StrTempMemory
    i know it's the wrong code but (off the top of my head) it demonstrates what i mean...
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    • You may use program's StdOut stream to omit temporary file. However it isn't much more simpler.
    • You may use WinAPI GlobalMemorySta tus() function. However you may find it too much messy too.
    • You may accept this imperfect world and let your program do all messy job for you.

    Comment

    • James King
      New Member
      • Aug 2010
      • 2

      #3
      Damn :(
      that's a suprise :(
      shtoopid kompooterz

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        I do not believe that what you are requesting can easily be accomplished. What I have done is to create a Public Function that will accept a single Parameter representing the specific Information to be requested. The Function will then read the associated Value from your Output File and return it. The Control Sources of various Text Boxes can then be set to the Function, passing to it the appropriate Argument. I'll simply post the Code along with some sample Calls, and let you make the final determination as to its usefulness, since it still is 'kludgy'.
        Code:
        Public Function fRetrieveSystemInfo(strInfoParameter As String) As Variant
        Dim strLine As String
        Dim intPosOfSemiColon As Integer
        Const conPATH_TO_INFO_FILE As String = "C:\Test\Output.txt"
        
        Open conPATH_TO_INFO_FILE For Input As #1    ' Open file.
        
        fRetrieveSystemInfo = Null      'Initialize to NULL
        
        Do While Not EOF(1)             'Loop until end of file.
          Line Input #1, strLine        'Read entire Line into variable.
            If Left$(strLine, Len(strInfoParameter)) = strInfoParameter Then
              intPosOfSemiColon = InStrRev(strLine, ":")        'Where is the last Semi-Colon?
                If InStr(strLine, "Directory") > 0 Then         'Unique case
                  'Return the Value (Trimmed), given the specific Parameter
                  fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon - 1))
                Else
                  'Return the Value (Trimmed), given the specific Parameter
                  fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon + 1))
                End If
            End If
        Loop
        
        Close #1    ' Close file.
        End Function
        Code:
        Debug.Print fRetrieveSystemInfo("Host Name")
        ADEZII
        Code:
        Debug.Print fRetrieveSystemInfo("OS Name")
        Microsoft Windows XP Professional
        Code:
        Debug.Print fRetrieveSystemInfo("OS Version")
        5.1.2600 Service Pack 3 Build 2600
        Code:
        Debug.Print fRetrieveSystemInfo("OS Manufacturer")
        Microsoft Corporation
        Code:
        Debug.Print fRetrieveSystemInfo("OS Configuration")
        Member Workstation
        Code:
        Debug.Print fRetrieveSystemInfo("OS Build Type")
        Multiprocessor Free
        Code:
        Debug.Print fRetrieveSystemInfo("System Up Time")
        15 Days, 7 Hours, 13 Minutes, 32 Seconds
        Code:
        Debug.Print fRetrieveSystemInfo("BIOS Version")
        DELL   - 7
        Code:
        Debug.Print fRetrieveSystemInfo("Windows Directory")
        C:\WINDOWS
        Code:
        Debug.Print fRetrieveSystemInfo("System Directory")
        C:\WINDOWS\system32
        Code:
        Debug.Print fRetrieveSystemInfo("Total Physical Memory")
        1,790 MB
        Code:
        Debug.Print fRetrieveSystemInfo("Virtual Memory: In Use")
        52 MB
        Code:
        Debug.Print fRetrieveSystemInfo("Logon Server")
        \\RPACFSO2
        Code:
        Debug.Print fRetrieveSystemInfo("Nonsense String")
        Null
        Code:
        'As the Control Source of a Text Box displaying Total Physical Memory:
        =fRetrieveSystemInfo("Total Physical Memory")

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32662

          #5
          There is no interface I'm aware of that allows VBA code to interact with a command prompt or any of it's possible commands.

          You could screen-scrape from the Command Prompt window using the Windows API (Fish provides a link) or you can pipe the results to a file and read the contents later into memory. If I needed to do this I'd use the latter approach certainly.

          Comment

          Working...