Anyone have a routine that works under
all versions of 32-bit Windows to get
the machine name?
all versions of 32-bit Windows to get
the machine name?
'This has only been tested using Windows 98SE FUNCTION ComputerName$ DIM lpBuffer AS ASCIIZ * 128 'should be long enough DIM nSize AS LONG nSize = 128 DIM RetCode AS LONG RetCode = GetComputerName(lpBuffer,nSize) ComputerName = lpBuffer END FUNCTION
FUNCTION ComputerName$ %BufferSize = 128 DIM lpBuffer AS ASCIIZ * %BufferSize DIM nSize AS LONG DIM RetCode AS LONG RetCode = GetComputerName(lpBuffer,%BufferSize) ComputerName = lpBuffer END FUNCTION
FUNCTION ComputerName AS STRING %BufferSize = 128 DIM sBuffer AS LOCAL STRING sBuffer = STRING$(%BufferSize,0) GetComputerName sBuffer,%BufferSize FUNCTION = sBuffer END FUNCTION
FUNCTION ComputerName AS STRING DIM sBuffer AS LOCAL STRING %BufferSize = 17 'MAX_COMPUTERNAME_LENGTH = 16, plus 1 sBuffer = STRING$(%BufferSize,0) GetComputerName BYVAL STRPTR(sBuffer),%BufferSize FUNCTION = EXTRACT$(sBuffer,CHR$(0)) END FUNCTION
' Any suggestions welcome ' How about this one. ' #COMPILE EXE #REGISTER NONE 'DECLARE FUNCTION GetComputerName LIB "KERNEL32.DLL" ALIAS "GetComputerNameA" _ '(lpBuffer AS ASCIIZ, nSize AS LONG) AS LONG DECLARE FUNCTION ComputerName AS STRING #INCLUDE "WIN32API.INC" FUNCTION PBMAIN AS LONG MSGBOX ComputerName END FUNCTION FUNCTION ComputerName AS STRING %MAX_COMPUTERNAME_LENGTH = 15 'not in Win32Api.inc DIM RetCode AS LONG DIM lpBuffer AS ASCIIZ * %MAX_COMPUTERNAME_LENGTH + 1 DIM nSize AS LONG nSize = %MAX_COMPUTERNAME_LENGTH + 1 'nSize returns RetCode = GetComputerName(lpBuffer,nSize) 'name length FUNCTION = lpBuffer END FUNCTION
#Compile Exe #Dim All #Register None #Include "Win32Api.Inc" CallBack Function DlgProc Select Case CbMsg Case %WM_INITDIALOG SetWindowPos CbHndl, 0, 50, 150, 300, 400, 0 Dim rc As Rect GetWindowRect CbHndl, rc MsgBox "R-L W" + Str$(rc.nRight - rc.nLeft), , Str$(rc.nRight) + Str$(rc.nLeft) MsgBox "B-T W" + Str$(rc.nBottom - rc.nTop), , Str$(rc.nBottom) + Str$(rc.nTop) End Select End Function Function PbMain() Dim hDlg As Long Dialog New 0, "", , , 0, 0 To hDlg Dialog Show Modal hDlg Call DlgProc End Function
#REGISTER NONE #COMPILE EXE #DIM ALL DECLARE FUNCTION NetUserName$ DECLARE FUNCTION NetMachineName$ #INCLUDE "WIN32API.INC" FUNCTION PBMAIN AS LONG #IF %DEF(%pb_cc32) PRINT "USER NAME: "; NetUserName PRINT "MACHINE NAME: "; NetMachineName PRINT "Press any key" WAITKEY$ #ELSE MSGBOX "USER NAME: " + NetUserName + $CRLF _ + "MACHINE NAME: " + NetMachineName NetMachineName #ENDIF END FUNCTION FUNCTION NetUserName AS STRING DIM wUser AS ASCIIZ * 50 DIM g_Result AS LONG g_Result = GetUserName(wUser, SIZEOF(wUser)) FUNCTION = wUser END FUNCTION FUNCTION NetMachineName AS STRING 'Netbios name = 16 chars, 15 useable max, add one for Asciiz Null DIM g_Result AS LONG DIM lpMachineName AS ASCIIZ * 17 g_Result = GetComputerName(lpMachineName, SIZEOF(lpMachineName)) FUNCTION = lpMachineName END FUNCTION
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment