Author Topic: System Information Examples  (Read 6896 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
System Information Examples
« on: August 29, 2011, 02:48:53 AM »
 
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.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: GetUserName Function
« Reply #1 on: August 29, 2011, 02:50:12 AM »
 
The following example illustrates the use of the GetUserName function.

Code: [Select]
#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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: GetUserNameEx Function
« Reply #2 on: August 29, 2011, 02:51:12 AM »
 
The following example illustrates the use of the GetUserNameEx function.

Code: [Select]
#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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: GetSystemInfo Function
« Reply #3 on: August 29, 2011, 02:52:21 AM »
 
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.

Code: [Select]
' 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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: GetComputerName Function
« Reply #4 on: August 29, 2011, 02:54:23 AM »
 
The following example uses GetComputerName to retrieve the NetBIOS name of the local computer.

Code: [Select]
#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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: GetComputerNameEx Function
« Reply #5 on: August 29, 2011, 02:55:17 AM »
 
The following example uses GetComputerNameEx to retrieve the NetBIOS name of the local computer.

Code: [Select]
#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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: VerifyVersionInfo Function
« Reply #6 on: August 29, 2011, 03:25:56 AM »
 
The following example illustrates the use of the VerifyVersionInfo function.

Code: [Select]
#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

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
SYSINFO: VerSetConditionMask Function
« Reply #7 on: August 29, 2011, 03:27:29 AM »
 
The following example illustrates the use of the VerSetConditionMask function.

Code: [Select]
#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