1. How do I get system information such as the disk size etc?
Many items of system information are available to your programs. This includes such things as
the version of Windows, the amount of installed memory and the free disk space. The following
window shows the system information:

The information was generated by the following program:
// Pcinfo.cls
Ubercode 1 Class Pcinfo
uses commdlgs timeutil
private function GetInfo(out InfoStr:string[*])
var
DiskName : string[*]
DiskId : integer(0:MAXINT)
OsName : string[*]
OsMajor : integer(0:MAXINT)
OsMinor : integer(0:MAXINT)
code
call Dirlabel("\", DiskName, DiskId)
call Systeminfo(OsName, OsMajor, OsMinor)
InfoStr <-
"Application directory = " + Dirstart() + NL +
"Application name = " + Appname() + NL +
"Command processor = " + Environ("COMSPEC") + NL +
"Current disk and directory = " + Dirpath() + NL +
"Date/Time = " + FormatTime(Time(),FMT_GENERAL) + NL +
"Disk free space = " + Str(Int(Dirsize("\")/1e6)) + " MB" + NL +
"Disk label = " + DiskName + NL +
"Disk serial number = " + Hexstr(DiskId,8,"0") + NL +
"Memory (physical) = " + Str(Int(Meminfo(3)/1024)) + " KB" + NL +
"Memory (stack space) = " + Str(Int(Meminfo(1)/1024)) + " KB" + NL +
"Memory (total available) = " + Str(Int(Meminfo(2)/1024)) + " KB" + NL +
"Operating system = " + OsName + " (v" + Str(OsMajor) + "." + Str(OsMinor) + ")" + NL +
"Program arguments = " + Arguments + NL +
"Screen size = " + Str(GetPagewidth(Sysscreen)) + " x " + Str(GetPageheight(Sysscreen)) + NL +
"Windows directory = " + Environ("WINDIR") + NL
end function
public function main()
code
call PlayMicrosoftSound()
call Msgbox("PcInfo program", GetInfo())
end function
end class
The program starts at function main above. It plays the Microsoft startup sound, then it
calls GetInfo. The GetInfo function obtains all the system information, and neatly
formats it into a string which it then returns. Back in main the system information is shown
in a message box.
2. Is there a list of system information functions?
This table shows the different types of system information available to your programs:
Description |
Function name |
Details |
Application directory |
Dirstart |
Get the directory / folder storing the application's main EXE file. The folder returned by
Dirstart does not change as the application runs. |
Application name |
Appname |
Get the name of the application. This is the same as the filename, but without the ".exe"
element. |
Command processor |
Environ("COMSPEC") |
Get the name of the command processor (command window or DOS prompt). This is command.com or
cmd.exe depending on the version of Windows. |
Current disk and directory |
Dirpath |
Get the full path of the current logged disk drive. This is the place relative to which files
are stored, except where specified using a full path name. The path returned by Dirpath can
change as the application runs. |
Date/Time |
Time |
Get the current date and time. This is returned in the format YYYY-MM-DD hh:mm:ss.dddd
where YYYY MM DD are the year, month and date, and hh mm ss dddd are hours, minutes,
seconds and decimal places. This is the international standard ISO 8601 for Date and Time
representation. |
Disk free space |
Dirsize |
Get the total amount of free disk space in bytes. |
Disk label / Disk serial number |
Dirlabel |
Get the name and serial number of the disk drive. |
Memory (physical) |
Meminfo(3) |
Get the amount of free stack space available to the running application. |
Memory (stack space) |
Meminfo(1) |
Get the amount of memory physically installed in the computer. |
Memory (total available) |
Meminfo(2) |
Get the total amount of memory available to the application. This includes physical installed
memory and virtual memory. |
Operating system |
SystemInfo |
Get the version of Windows (2000, XP etc) and the Windows version number. |
Printer list |
Printers |
Get the list of printers attached to the computer (it is possible for there to be no attached
printers). |
Program arguments |
Arguments (constant) |
Get the arguments passed to the application. Arguments are passed either on the command line,
or as a result of calling the application from another program or script. |
Screen resolution |
GetDpiX / GetDpiY |
Get the number of pixels per inch on the screen. These functions also work with the printed
page. |
Screen size |
Pageheight / Pagewidth |
Get the size (measured in pixels) of the computer screen. These functions also work with the
printed page. |
Windows directory |
Environ("WINDIR") |
Get the directory containing the Windows operating system. |
3. How do I get the Windows version?
Use the Systeminfo function:
// Info.cls
Ubercode 1 Class Info
public function main()
var
name : string[*]
major : integer(0:MAXINT)
minor : integer(0:MAXINT)
code
call Systeminfo(name, major, minor)
call Msgbox("Systeminfo", name+" "+Str(major)+"."+Str(minor))
end function
end class
The Systeminfo function returns the name of the operating system, and the major and minor
version numbers. For example if the Windows version is 4.0 the major version number is 4 and the
minor version number is 0. The Msgbox function displays the name of the operating system and
converts the version numbers to strings. The example program above can be compiled and run to get
the Windows version.
4. How do I read environment variables?
Use Environ which can return the value of any environment variable. For example
Environ("COMSPEC") returns the path of the Windows command processor (command.com or
cmd.exe).
|