Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: NetWkstaGetInfo DllCall Unicode Domain Remote Computer Name Major Minor ChrStringToUnicode udfGetStrAtwAddress IntControl 32 Address
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction udfGetStrAtwAddress(Address) nOffset = 0 strResult = "" While @TRUE wChar = IntControl(32, Address+nOffset, "WORD", 0, 0) If wChar == 0 Then Break strResult = strResult:Num2Char(wChar) ;; !IMPORTANT! can't convert all Unicode characters!!!!! nOffset = nOffset + 2 EndWhile Return strResult ; // ANSI string returned #EndFunction ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #DefineFunction udfNetWkstaGetInfo(computername) ; NOTE: You must have Administrators group membership or Print/Server operator privilege level = 100 ;typedef struct _WKSTA_INFO_100 { ;4 DWORD wki100_platform_id; ;30 LMSTR wki100_computername; ;30 LMSTR wki100_langroup; ;4 DWORD wki100_ver_major; ;4 DWORD wki100_ver_minor; ;}WKSTA_INFO_100, *PWKSTA_INFO_100, *LPWKSTA_INFO_100 ; Allocated output buffer bufptr = BinaryAlloc(4) BinaryPoke4(bufptr, 0, 0) ; Convert computername to Unicode string wstrComputerName = ChrStringToUnicode(computerName) ; Check for local computername then call NetWkstaGetInfo If StrTrim(computername) == "" ; assume local computer retcode = DllCall(DirWindows(1):"NETAPI32.DLL",long:"NetWkstaGetInfo",lpnull,long:level,lpbinary:bufptr) Else retcode = DllCall(DirWindows(1):"NETAPI32.DLL",long:"NetWkstaGetInfo",lpwstr:wstrComputerName,long:level,lpbinary:bufptr) EndIf lasterr = DllLastError() If retcode > 0 ; Check for error Message("NetWkstaGetInfo failed",retcode:@CRLF:lasterr) DllCall(DirWindows(1):"NETAPI32.DLL",long:"NetApiBufferFree",lpbinary:addrBuf) BinaryFree(bufptr) Exit EndIf ; Get then set the 'end of data ' ; Use BinaryEODSet to update the EOD value. This can be done when data at the end of a buffer is to be discarded, ; or when the buffer has been modified by an external program - such as via a DllCall. eod = BinaryEodGet(bufptr) BinaryEodSet(bufptr,eod) ; Read results from output struct addrBuf = BinaryPeek4(bufptr,0) ; read address of the memory location. platformid = IntControl(32, addrBuf, "LONG", 0, 0) addrCompName = IntControl(32, addrBuf + 4, "LONG", 0, 0) computername = udfGetStrAtwAddress(addrCompName) addrDomain = IntControl(32, addrBuf + 8, "LONG", 0, 0) domain = udfGetStrAtwAddress(addrDomain) MAJOR = IntControl(32, addrBuf + 12, "LONG", 0, 0) MINOR = IntControl(32, addrBuf + 16, "LONG", 0, 0) ; Call NetApiBufferFree to free buffer DllCall(DirWindows(1):"NETAPI32.DLL",long:"NetApiBufferFree",lpbinary:addrBuf) ; Clean up BinaryFree(bufptr) Return platformid:@TAB:computername:@TAB:domain:@TAB:MAJOR:@TAB:MINOR #EndFunction computer = '\\Myserver' ; or '' for the local computer result = udfNetWkstaGetInfo(computer) AskItemlist('udfNetWkstaGetInfo Results for : ': computer, result, @TAB, @UNSORTED, @SINGLE )
Article ID: W18378
Filename: NetWkstaGetInfo UDF.txt
File Created: 2010:04:02:14:49:48
Last Updated: 2010:04:02:14:49:48