2024年1月29日发(作者:)
获得系统基本信息
当一个应用program在工作时,会不可避免地和操作系统发生数据交换,虽然在PB中提供了Environment对象来获得系统的一些信息,然而这些信息往往是不够的,例如CPU、本机IP地址等,这些内容只有用Windows API来获得了.
1、建立一个工作空间(workspace),取名为:systeminfo.
2、建立一个应用(application),取名为:systeminfo.
3、创建用户对象u_sysinfo,并添加Microsoft Winsock OCX Control .
4、定义u_sysinfo的实例变量.
public:
string cpuid,cpuprovider
string filesystem,volumename
ulong VolumeSerialNumber,MaxComponentLength,FileSystemFlags
long dlength,dmemoryload,dtotalphys,davailphys,dtotalpagefile
long davailpagefile,dtotalvirtual,davailvirtual
ulong
dwoemid,dwpagesize,lpminappaddress,lpmaxappaddress,dwactiveprocessormask
ulong
dwnumberofprocessors,dwprocessortype,dwallocationgranularity,dwreserved
ulong
sectorspercluster,bytespersector,numberoffreeclusters,totalnumberofclusters
ulong mbtotal,mbfree
5、定义u_sysinfo的局部外部函数
PUBLIC FUNCTION ulong GetComputerName(ref string lpBuffer,ref ulong
nSize) LIBRARY ""
ALIAS FOR "GetComputerNameA"
PUBLIC FUNCTION ulong GetDriveType(string nDrive) LIBRARY ""
ALIAS FOR "GetDriveTypeA"
FUNCTION ulong GetDiskFreeSpace(ref string lpRootPathName,ref
ulong lpSectorsPerCluster,ref ulong
lpBytesPerSector,ref ulong lpNumberOfFreeClusters,ref ulong
lpTtoalNumberOfClusters)
LIBRARY "" ALIAS FOR "GetDiskFreeSpaceA"
PUBLIC FUNCTION ulong GetTickCount() LIBRARY ""
PUBLIC Subroutine GetSystemInfo(ref ws_info lpSystemInfo) LIBRARY
""
PUBLIC FUNCTION ulong waveOutGetNumDevs() LIBRARY ""
PUBLIC FUNCTION ulong WNetGetUser(ref string lpName,ref string
lpUserName,ref ulong lpnLength)
LIBRARY "mpr" ALIAS FOR "WNetGetUserA"
PUBLIC FUNCTION ulong GetSystemMetrics(ulong nIndex) LIBRARY
""
PUBLIC FUNCTION ulong GetWindowsDirectory(ref string lpBuffer,ulong
nSize) LIBRARY ""
ALIAS FOR "GetWindowsDirectoryA"
PUBLIC FUNCTION ulong GetSystemDirectory(ref string lpBuffer,ulong nSize)
LIBRARY ""
ALIAS FOR "GetSystemDirectoryA"
PUBLIC FUNCTION ulong GetTempPath(ulong nBufferLength,ref string
lpBuffer) LIBRARY ""
ALIAS FOR "GetTempPathA"
PUBLIC FUNCTION ulong GetKeyboardType(ulong nTypeFlag) LIBRARY
""
PUBLIC FUNCTION ulong QueryPerformanceFrequency(ref double lpFrequency)
LIBRARY ""
PUBLIC FUNCTION ulong QueryPerformanceCounter(ref ulong
lpPerformanceCount) LIBRARY ""
//PUBLIC FUNCTION ulong EnumPrinterDrivers(ref string pName,ref string
pEnvironment,ulong Level,ref
Byte pDriverInfo,ulong cdBuf,ref ulong pcbNeeded,ref ulong pcRetruned)
LIBRARY
"" ALIAS FOR "EnumPrinterDriversA"
PUBLIC Subroutine GlobalMemoryStatus(ref ws_memory lpBuffer) LIBRARY
""
//FUNCTIONon ulong GlobalReAlloc(ulong hMem,ulong dwBytes,ulong wFlags)
LIBRARY ""
PUBLIC FUNCTION ulong RegOpenKey(ulong hKey,ref string lpSubKey,ref
ulong phkResult) LIBRARY
"" ALIAS FOR "RegOpenKeyA"
PUBLIC FUNCTION ulong RegCloseKey(ulong hKey) LIBRARY ""
PUBLIC FUNCTION ulong RegQueryValueEx(ulong hKey,ref string
lpValueName,ulong lpReserved,ref ulong
lpType,ref long lpData,ref ulong lpcbData) LIBRARY "" ALIAS
FOR
"RegQueryValueExA"
//Function ulong EnumDisplaySettingsA(ulong xx,ulong modenum,ref
DEVMODE
lpdevmode)Library""
//PUBLIC FUNCTION ulong DeviceCapabilities(ref string lpDeviceName,ref
string lpPort,ulong
iIndex,ref string lpOutput,ref DEVMODE lpDevMode) LIBRARY ""
ALIAS FOR
"DeviceCapabilitiesA"
PUBLIC FUNCTION ulong GetVolumeInformation(string lpRootPathName,ref
string lpVolumeNameBuffer,
ulong nVolumeNameSize,ref ulong lpVolumeSerialNumber,ref ulong
lpMaximumComponentLength,
ref ulong lpFileSystemFlags,ref string lpFileSystemNameBuffer,ulong
nFileSystemNameSize)
LIBRARY "" ALIAS FOR "GetVolumeInformationA"
FUNCTION long GetMACAddress(long lana,ref long addr[6]) Library
""
FUNCTION long GetLanaID(ref long lana[254]) LIBRARY ""
Function ulong GetMHZ()Library""
6、用户对象级函数
1)、of_GetComputerName(),获得计算机的标识(即计算机名).
ulong ll_comsize
ulong ll_flag
ll_comsize = 256
string ls_computerName
//获得计算机的名称
ll_flag = GetComputerName(ls_computerName,ll_comsize)
If ll_flag <> 1 then
return "Get Computer Failure"
else
return ls_computerName
End if
2)、of_GetCpuInfo(),获得CPU一些基本信息.
ws_cpuinfo lstr_cpu
string ls_temp
RegistryGet("HKEY_LOCAL_MACHINEHardwareDescriptionSystemCentralProcessor0","Identifier",RegString!,ls_temp)
lstr_ = ls_temp
cpuid = ls_temp
RegistryGet("HKEY_LOCAL_MACHINEHardwareDescriptionSystemCentralProcessor0","VendorIdentifier",RegString!,ls_temp)
lstr_vider = ls_temp
cpuprovider = ls_temp
3)、of_GetCpuStatus(),获得CPU当前的使用频率,是从0%到100%之间的一个常数.
ulong ls_username,lpcbData,lpType
lpcbData = 4
lpType = 4
ulong phkResult
ls_username = 0
string lbSubkey
long lpData
lbSubkey = "PerfStatsStatData"
ls_username
= RegOpenKey(16*16*16*16*16*16*16*8+6,lbSubKey,phkResult)//The first
parameters is HKEY_DYN_DATA = &80000006(HANDLE)
string lpValueName
lpValueName = "KERNELCPUUsage"
ls_username =
RegQueryValueEx(phkResult,lpValueName,0,lpType,lpData,lpcbData)
ls_username = RegCloseKey(phkResult)
return lpdata
4)、of_GetDiskVolume(),获得磁盘空间大小.
ulong ll_MBFree
ulong ll_MBTotal
ulong ll_sectorspercluster // Sectors/Cluster
ulong ll_bytespersector // Bytes/Sector
ulong ll_numberoffreeclusters // Number of Free Clusters
ulong ll_toalnumberofclusters // Total Number of Clusters
GetDiskFreeSpace(as_driver, ll_sectorspercluster,
ll_bytespersector,ll_numberoffreeclusters,
ll_toalnumberofclusters)
sectorspercluster=ll_sectorspercluster
bytespersector=ll_bytespersector
numberoffreeclusters=ll_numberoffreeclusters
totalnumberofclusters=ll_toalnumberofclusters
mbfree = (ll_sectorspercluster * ll_bytespersector *
(ll_numberoffreeclusters / 1024)) / 1024
mbtotal = (ll_sectorspercluster * ll_bytespersector *
(ll_toalnumberofclusters / 1024)) / 1024
5)、of_GetDriverType(),获得各个磁盘的种类.
ulong ul_drivetype
string ls_drive
ul_drivetype = GetDriveType(a_drivename)
choose case ul_drivetype
case 0
ls_Drive = "Unknown Driver"
Case 1
ls_Drive = "Drive Does Not exist"
Case 2
ls_Drive = "Floppy driver"
Case 3
ls_Drive = "HardDisk driver"
Case 4
ls_Drive = "Network driver"
Case 5
ls_Drive = "CD-ROM driver"
Case 6
ls_Drive = "RAM driver"
End choose
Return ls_drive
8)、GetMhz:
sle_ = String(uo__GetMhz())
9)、GetOSVersion:
sle_ = uo__getosversion()
10)、GetServicePack:
sle_ = uo__GetServicePack()
11)、GetSystemDir:
sle_ = uo__getSystemDir()
12)、GetTempDir:
sle_ = uo__gettemppath()
13)、GetSystemInfo:
uo__GetsystemInfo()
ddlb_m("OemID = "+string(uo_d))
ddlb_m("PageSize = "+string(uo_size))
ddlb_m("MinAppAddress =
"+string(uo_ppaddress))
ddlb_m("MaxAppAddress =
"+string(uo_ppaddress))
ddlb_m("ActiveProcessorMask =
"+string(uo_veprocessormask))
ddlb_m("NumberofProcessors =
"+string(uo_erofprocessors))
ddlb_m("ProcessorType =
"+string(uo_essortype))
ddlb_m("AllocationGranularity =
"+string(uo_cationgranularity))
ddlb_m("Reserved = "+string(uo_rved))
ddlb_item(5)
14)、GetTickCount:
sle_ = uo__GetTickCount()
15)、GetKeyBoardType:
choose case uo__GetKeyboardType()
case 1
sle_ = "IBM PC/XT( ) or compatible (83-key) keyboard"
case 2
sle_ = "Olivetti 'ICO' (102-key) keyboard"
case 3
sle_ = "IBM PC/AT (84-key) or similar keyboard"
case 4
sle_ = "IBM enhanced (101- or 102-key) keyboard"
case 5
sle_ = "N搞定ia 1050 and similar keyboards"
case 6
sle_ = "N搞定ia 9140 and similar keyboards"
case 7
sle_ = "Japanese keyboard"
case else
sle_ = "Hardware dependent and specified by the OEM"
End choose
16)、GetWindowMode:
sle_ = uo__getwindowmode()
17)、GetWindowDir:
sle_ = uo__getwindowdir()
18)、GetWaveDevice:
sle_ = string(uo__getwavedevice())
19)、GetIPAddress:
sle_ = uo__getipaddress()
20)、GetNetCard:
sle_ = uo__getnetcard()
21)、GetDiskInfo:
lv_columns()
lv_items()
lv_umn("Driver",Left!,250)
lv_umn("FileSystem",Left!,350)
lv_umn("VolumeName",Left!,400)
lv_umn("VolumeSerialNumber",Left!,650)
lv_umn("MaxComponentLength",Left!,650)
lv_umn("FileSystemFlags",Left!,500)
lv_umn("SectorsPerCluster",Left!,600)
lv_umn("BytesPerSector",Left!,500)
lv_umn("NumberofFreeClusters",Left!,700)
lv_umn("TotalNumberofClusters",Left!,750)
lv_umn("FreeDiskVolume",Left!,600)
lv_umn("TotalDiskVolume",Left!,650)
lv_umn("Used Ratio",Left!,350)
String ls_drive,ls_status
ls_drive = "abcdefghijklmnopqrstuvwxyz"
Integer li_i
For li_i = 1 to 26
ls_status = uo__getdrivetype(mid(ls_drive,li_i,1)+":")
if ls_status <>"Drive Does Not exist" Then
uo__getvolumeInfo(mid(ls_drive,li_i,1)+":")
uo__getdiskvolume(mid(ls_drive,li_i,1)+":")
Choose case lower(ls_status)
case "floppy driver"
if uo_l = 0 Then
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+"0%",1)
else
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_
erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+String(Long(((uo_l -
uo_)/uo_l)*100))+"%",1)
End if
Case "harddisk driver"
if uo_l = 0 Then
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+"0%",2)
else
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+String(Long(((uo_l -
uo_)/uo_l)*100))+"%",2)
End if
case "cd-rom driver"
if uo_l = 0 Then
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+"0%",3)
else
lv_m(mid(ls_drive,li_i,1)+":"+"~t"+trim(string(uo_stem))+"~t"+trim(string(uo_Name))+"~t"+string(uo_SerialNumber)+"~t"+string(uo_ponentLength)+"~t"+string(uo_stemFlags)+"~t"+string(uo_sPerCluster)+"~t"+string(uo_erSector)+"~t"+string(uo_ofFreeClusters)+"~t"+string(uo_umberofClusters)+"~t"+string(uo_)+"MB"+"~t"+string(uo_l)+"MB"+"~t"+String(Long(((uo_l -
uo_)/uo_l)*100))+"%",3)
End if
End Choose
End If
End For
//FileSystem= lpFileSystemNameBuffer
//VolumeName = lpVolumeNameBuffer
//VolumeSerialNumber=lpVolumeSerialNumber
//MaxComponentLength = lpMaximumComponentLength
//FileSystemFlags=lpFileSystemFlags


发布评论