473,387 Members | 1,388 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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, WindowsInstallDate 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.txt 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
Expand|Select|Wrap|Line Numbers
  1. StrTempMemory = shell(CMD.exe "SYSTEMINFO |find/i'Total Physical Memory:'")
  2.  
and then Textbox.Value = StrTempMemory
i know it's the wrong code but (off the top of my head) it demonstrates what i mean...
Aug 27 '10 #1

✓ answered by ADezii

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'.
Expand|Select|Wrap|Line Numbers
  1. Public Function fRetrieveSystemInfo(strInfoParameter As String) As Variant
  2. Dim strLine As String
  3. Dim intPosOfSemiColon As Integer
  4. Const conPATH_TO_INFO_FILE As String = "C:\Test\Output.txt"
  5.  
  6. Open conPATH_TO_INFO_FILE For Input As #1    ' Open file.
  7.  
  8. fRetrieveSystemInfo = Null      'Initialize to NULL
  9.  
  10. Do While Not EOF(1)             'Loop until end of file.
  11.   Line Input #1, strLine        'Read entire Line into variable.
  12.     If Left$(strLine, Len(strInfoParameter)) = strInfoParameter Then
  13.       intPosOfSemiColon = InStrRev(strLine, ":")        'Where is the last Semi-Colon?
  14.         If InStr(strLine, "Directory") > 0 Then         'Unique case
  15.           'Return the Value (Trimmed), given the specific Parameter
  16.           fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon - 1))
  17.         Else
  18.           'Return the Value (Trimmed), given the specific Parameter
  19.           fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon + 1))
  20.         End If
  21.     End If
  22. Loop
  23.  
  24. Close #1    ' Close file.
  25. End Function
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Host Name")
  2. ADEZII
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Name")
  2. Microsoft Windows XP Professional
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Version")
  2. 5.1.2600 Service Pack 3 Build 2600
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Manufacturer")
  2. Microsoft Corporation
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Configuration")
  2. Member Workstation
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Build Type")
  2. Multiprocessor Free
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("System Up Time")
  2. 15 Days, 7 Hours, 13 Minutes, 32 Seconds
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("BIOS Version")
  2. DELL   - 7
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Windows Directory")
  2. C:\WINDOWS
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("System Directory")
  2. C:\WINDOWS\system32
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Total Physical Memory")
  2. 1,790 MB
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Virtual Memory: In Use")
  2. 52 MB
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Logon Server")
  2. \\RPACFSO2
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Nonsense String")
  2. Null
Expand|Select|Wrap|Line Numbers
  1. 'As the Control Source of a Text Box displaying Total Physical Memory:
  2. =fRetrieveSystemInfo("Total Physical Memory")

4 4939
FishVal
2,653 Expert 2GB
  • You may use program's StdOut stream to omit temporary file. However it isn't much more simpler.
  • You may use WinAPI GlobalMemoryStatus() 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.
Aug 27 '10 #2
Damn :(
that's a suprise :(
shtoopid kompooterz
Aug 27 '10 #3
ADezii
8,834 Expert 8TB
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'.
Expand|Select|Wrap|Line Numbers
  1. Public Function fRetrieveSystemInfo(strInfoParameter As String) As Variant
  2. Dim strLine As String
  3. Dim intPosOfSemiColon As Integer
  4. Const conPATH_TO_INFO_FILE As String = "C:\Test\Output.txt"
  5.  
  6. Open conPATH_TO_INFO_FILE For Input As #1    ' Open file.
  7.  
  8. fRetrieveSystemInfo = Null      'Initialize to NULL
  9.  
  10. Do While Not EOF(1)             'Loop until end of file.
  11.   Line Input #1, strLine        'Read entire Line into variable.
  12.     If Left$(strLine, Len(strInfoParameter)) = strInfoParameter Then
  13.       intPosOfSemiColon = InStrRev(strLine, ":")        'Where is the last Semi-Colon?
  14.         If InStr(strLine, "Directory") > 0 Then         'Unique case
  15.           'Return the Value (Trimmed), given the specific Parameter
  16.           fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon - 1))
  17.         Else
  18.           'Return the Value (Trimmed), given the specific Parameter
  19.           fRetrieveSystemInfo = Trim(Mid$(strLine, intPosOfSemiColon + 1))
  20.         End If
  21.     End If
  22. Loop
  23.  
  24. Close #1    ' Close file.
  25. End Function
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Host Name")
  2. ADEZII
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Name")
  2. Microsoft Windows XP Professional
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Version")
  2. 5.1.2600 Service Pack 3 Build 2600
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Manufacturer")
  2. Microsoft Corporation
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Configuration")
  2. Member Workstation
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("OS Build Type")
  2. Multiprocessor Free
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("System Up Time")
  2. 15 Days, 7 Hours, 13 Minutes, 32 Seconds
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("BIOS Version")
  2. DELL   - 7
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Windows Directory")
  2. C:\WINDOWS
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("System Directory")
  2. C:\WINDOWS\system32
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Total Physical Memory")
  2. 1,790 MB
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Virtual Memory: In Use")
  2. 52 MB
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Logon Server")
  2. \\RPACFSO2
Expand|Select|Wrap|Line Numbers
  1. Debug.Print fRetrieveSystemInfo("Nonsense String")
  2. Null
Expand|Select|Wrap|Line Numbers
  1. 'As the Control Source of a Text Box displaying Total Physical Memory:
  2. =fRetrieveSystemInfo("Total Physical Memory")
Aug 27 '10 #4
NeoPa
32,556 Expert Mod 16PB
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.
Aug 27 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andreas Paasch | last post by:
According to the manual for PHP, I should be able to run a shell command within php. I'm trying to copy some php files from one location to another one using exec() but fail. ...
4
by: Yann.K | last post by:
Hello. Using Tkinter, i would create a widget which display a shell command return. This return is long, and i would display a real time display (like with the tail -f commande on Linux) I...
8
by: Siemel Naran | last post by:
Hi. I'm writing a command shell that reads commands from standard input. At this point I have the command in a std::string. Now I want to execute this command in the shell. From the Borland...
8
by: zhiwei wang | last post by:
I remember that there is a function that could invoke shell command such as "rm" "cp", directly in .c file. But I could not recall its name, and I googled with nothing meaningful. I vaguely...
9
by: Tommy Lu | last post by:
Hi, wondering if there is a way to interact the shell command with the C# program? For example, if I type c:\>ver it then suppose to return the version of the OS I am currently using... or ...
2
by: nyousfi | last post by:
Hi I have a Client Control that works absolutely beautifully but I need to popup a browser window using this control but cant. I thought the easiest way to do this would be to Run a Shell...
2
by: jcrouse | last post by:
I apologize for starting another thread but the old one had a weird subject line. Anyways...here is the code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As...
4
by: Kevin Mansel via .NET 247 | last post by:
Ok, basically this is my problem. I'm building a console app tocall a dos program. So i'm using the Shell command to call theprogram, now depending on what happens, I want to read theoutput that...
2
by: ¹é¿ø¼® | last post by:
Hello, everybody. I want to call any shell command from php script using shell_exec(). The problem is that the next line of the php script would not be run until a few minutes after running the...
3
by: davidholmes | last post by:
I need to load a csv file into excel with the shell command. My code works fine as long as excel is not already running but if there is another instance of excel open the shell command opens a new...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.