System Information
In vbXzone API discussions, I usually provide just one or two API calls, and the whole article describes them and teaches how to use them. This
time it will be a little bit different. I will introduce you an application that I wrote that gathers various information about the system. However,
instead of explaining each API call, I am giving the source code for you to look at. The whole project is available here. Warning: Shutdown feature works the moment you select it. So unless you really want to shutdown the computer (or logoff, restart) don't select it.
Here is the screen shot of the application:
Let's look at each program's function seperately. It will help for you, as I go over the features, to refer to the code of the application.
First of let's start with obtaining windows and system directories. To do that, you use GetWindowsDirectory and GetSystemDirectory API calls. Notice that these functions require a string as a parameter. This string must be initialized like this: buf = Space$(255). This call allocates string called buf with 255 spaces. The rest is easy, call the API with buf passed to it and buf will be rewritten with the directory path that you are interested in.
Next on the list is GetVersionInfo API call. This call requires OSVERSIONINFO structure to be passed to it. Get the structure declaration either from the source code I provided, or from the web, or from API Viewer. This API call is rather easy to use. Make sure that you initialize dwOSVersionInfoSize member of OSVERSIONINFO structure to the length of the structure: osVer.dwOSVersionInfoSize = Len(osVer) . Call the function and read the results.
The purpose of GetComputerName and GetUserName calls should be pretty clear from the name. Make sure you initialize the string buffer that these functions require using Space function provided by VB like it was done for GetWIndowsDirectory call. Then call these functions and the information is provided by the OS to your program in the buffer string.
ExitWindowEx function call is something you should not jump to try it out. It will log you off or shut down you computer. This call is pretty powerful. The type of windows exit you wish can be adjusted using EWX_ constants that I defined in the source code Module1.
GlobalMemoryStatus and GetSystemInfo calls are probably the next coolest API calls after ExitWindowsEx call. The information these calls provide is something similar to pressing Ctrl+Alt+Delete in Win NTs and watching the info provided by the Task Manager. What I liked about GetSystemInfo is that it provids the page size (4k in the snapshot above) and the min and max address ranges that user programs can issue. That way you can see the memory limit that you have due to your RAM and virtual memory settings.
Please fill free to examine the source code for more detailed API usage and API declarations. Feel free to use the source code in the projects. If you are to include the whole module in your project, please leave the commenting section intact.