• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

System Information Examples

Started by José Roca, August 29, 2011, 02:48:53 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
The system information functions retrieve a variety of data. The system configuration information describes the computer hardware, computer name, and user name. The operating system configuration information describes the operating system version, key directories, and environment variables. The system parameters describe system attributes. The system metrics provide the dimensions of the elements in the display area.

José Roca

 
The following example illustrates the use of the GetUserName function.


#COMPILE EXE
#DIM ALL
#INCLUDE ONCE "windows.inc"
#INCLUDE ONCE "lmcons.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL bResult AS LONG
   LOCAL szUserName AS ASCIIZ * %UNLEN
   LOCAL nError AS LONG
   LOCAL nSize AS DWORD

   nSize = %UNLEN
   bResult = GetUserName(szUserName, nSize)
   nError = GetLastError
   IF bResult = 0 THEN
      ? "Error: &H" & HEX$(GetLastError)
   ELSE
      ? "Characters copied: " & STR$(nSize)
      ? "User name: " & szUserName
   END IF

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION


José Roca

 
The following example illustrates the use of the GetUserNameEx function.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"
#INCLUDE "secext.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL bResult AS BYTE
   LOCAL strUserName AS STRING
   LOCAL nError AS LONG
   LOCAL nSize AS DWORD

   bResult = GetUserNameEx(%NameSamCompatible, BYVAL %NULL, nSize)
   IF bResult = 0 THEN
      IF GetLastError = %ERROR_MORE_DATA THEN
         strUserName = SPACE$(nSize)
         bResult = GetUserNameEx(%NameSamCompatible, BYVAL STRPTR(strUserName), nSize)
         nError = GetLastError
         IF bResult = 0 THEN
            ? "Error: &H" & HEX$(nError)
         ELSE
            ? "User name: " & strUserName
         END IF
      ELSE
         ? "Error: &H" & HEX$(nError)
      END IF
   END IF

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION


José Roca

 
The following example uses the GetSystemInfo function to obtain hardware information such as the OEM identifier, processor type, page size, and so on. The example displays the information in the console.


' SED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "WIN32API.INC"

FUNCTION PBMAIN () AS LONG

   LOCAL siSysInfo AS SYSTEM_INFO
   
   ' Copy the hardware information to the SYSTEM_INFO structure.
   GetSystemInfo siSysInfo
   
   '  Display the contents of the SYSTEM_INFO structure
   PRINT "Hardware information:"
   PRINT "  OEM ID: "  siSysInfo.dwOemId
   PRINT "  Number of processors:" siSysInfo.dwNumberOfProcessors
   PRINT "  Page size: " siSysInfo.dwPageSize
   PRINT "  Processor type: " siSysInfo.dwProcessorType
   PRINT "  Minimum application address: " siSysInfo.lpMinimumApplicationAddress
   PRINT "  Maximum application address: " siSysInfo.lpMaximumApplicationAddress
   PRINT "  Active processor mask: " siSysInfo.dwActiveProcessorMask

   WAITKEY$

END FUNCTION


José Roca

 
The following example uses GetComputerName to retrieve the NetBIOS name of the local computer.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG
   LOCAL dwSize AS LONG
   LOCAL szComputerName AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1
   
   dwSize = %MAX_COMPUTERNAME_LENGTH + 1
   hr = GetComputerName(szComputerName, dwSize)
   ? szComputerName
   
   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION


José Roca

 
The following example uses GetComputerNameEx to retrieve the NetBIOS name of the local computer.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG
   LOCAL nError AS LONG
   LOCAL dwSize AS LONG
   LOCAL strComputerName AS STRING
   
   hr = GetComputerNameEx(%ComputerNameNetBIOS, BYVAL %NULL, dwSize)
   IF hr = 0 THEN
      IF GetLastError = %ERROR_MORE_DATA THEN
         strComputerName = SPACE$(dwSize)
         hr = GetComputerNameEx(%ComputerNameNetBIOS, BYVAL STRPTR(strComputerName), dwSize)
         nError = GetLastError
         IF hr = 0 THEN
            ? "Error: " & STR$(nError)
         ELSE
            strComputerName = LEFT$(strComputerName, LEN(strComputerName) - 1)
            ? strComputerName
         END IF
      END IF
   END IF
   
   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION


José Roca

 
The following example illustrates the use of the VerifyVersionInfo function.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG
   LOCAL osvi AS OSVERSIONINFOEX
   LOCAL dwlConditionMask AS QUAD
   LOCAL nError AS LONG
   
   osvi.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEX)
   osvi.dwPlatformId = %VER_PLATFORM_WIN32_NT
   
   dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_PLATFORMID, %VER_EQUAL)
   hr = VerifyVersionInfo(osvi, %VER_PLATFORMID, dwlConditionMask)
   nError = GetLastError
   IF hr = 0 THEN
      ? "Error: &H" & STR$(nError)
   ELSE
      ? "hr = " & STR$(hr)
   END IF

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION


José Roca

 
The following example illustrates the use of the VerSetConditionMask function.


#COMPILE EXE
#DIM ALL
#INCLUDE "windows.inc"

FUNCTION PBMAIN () AS LONG

   LOCAL hr AS LONG
   LOCAL osvi AS OSVERSIONINFOEX
   LOCAL dwlConditionMask AS QUAD
   LOCAL nError AS LONG
   
   osvi.dwOSVersionInfoSize = SIZEOF(OSVERSIONINFOEX)
   osvi.dwPlatformId = %VER_PLATFORM_WIN32_NT
   
   dwlConditionMask = VerSetConditionMask(dwlConditionMask, %VER_PLATFORMID, %VER_EQUAL)
   hr = VerifyVersionInfo(osvi, %VER_PLATFORMID, dwlConditionMask)
   nError = GetLastError
   IF hr = 0 THEN
      ? "Error: &H" & STR$(nError)
   ELSE
      ? "hr = " & STR$(hr)
   END IF

   #IF %DEF(%PB_CC32)
      WAITKEY$
   #ENDIF

END FUNCTION