Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
PCs on the local network
Message
De
05/12/2007 13:49:51
 
 
À
05/12/2007 09:02:01
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01273253
Message ID:
01273357
Vues:
22
This message has been marked as the solution to the initial question of the thread.
>
>On win9x and NT systems we had some solutions (as getmachines of ED) to enumerate the pcs under a local network..
>
>Those solutions is yet the best deal to run that job?? Or, is it something more uptodate?? ..Something a little closer to those news features of winxp sp2??

searching in my own one library I found: (here working fine)

thanks all
Do Decl

* Specifies the type of software the computer is running
#Define SV_TYPE_WORKSTATION 1
#Define SV_TYPE_SERVER 2
#Define SV_TYPE_SQLSERVER 4
#Define SV_TYPE_DOMAIN_CTRL  8
#Define SV_TYPE_PRINTQ_SERVER 0x200
#Define SV_TYPE_SERVER_UNIX 0x800
#Define SV_TYPE_SERVER_NT 0x8000
#Define SV_TYPE_DOMAIN_MASTER 0x80000
#Define SV_TYPE_WINDOWS 0x400000
#Define SV_TYPE_ALL 0xFFFFFFFF

* testing various server lists
= EnumServers (SV_TYPE_ALL)
*    = EnumServers (SV_TYPE_SERVER)
*    = EnumServers (SV_TYPE_SQLSERVER)
*    = EnumServers (SV_TYPE_SERVER_NT)
*    = EnumServers (SV_TYPE_DOMAIN_CTRL)
*    = EnumServers (SV_TYPE_ALL)

Procedure  EnumServers (lnServerType)
	#Define MAX_PREFERRED_LENGTH -1
	#Define SINFO_101_SIZE       24

	*| typedef struct _SERVER_INFO_101 {
	*|   DWORD     sv101_platform_id;     4
	*|   LPWSTR    sv101_name;            4
	*|   DWORD     sv101_version_major;   4
	*|   DWORD     sv101_version_minor;   4
	*|   DWORD     sv101_type;            4
	*|   LPWSTR    sv101_comment;         4
	*| } SERVER_INFO_101, *PSERVER_INFO_101, *LPSERVER_INFO_101;

	Local lnBuffer, lnCountRead, lnCountTotal, lnResult
	Store 0 To lnBuffer, lnCountRead, lnCountTotal

	Wait Window "Requesting data..." Nowait
	lnResult = NetServerEnum (0, 101, @lnBuffer, MAX_PREFERRED_LENGTH,;
		@lnCountRead, @lnCountTotal, lnServerType, 0, 0)
	Wait Clear

	If lnResult <> 0
		*  87 = The parameter is incorrect
		* 234 = More data is available
		? "Error code:", lnResult
	Else
		Local lcBuffer, lnBufLen, lnEntry, lnPlatformId, lnNamePtr,;
			lnMajorVer, lnMinorVer, lnSofttype, lnMemoPtr,;
			lcServerName, lcServerMemo

		* creating resulting cursor
		Create Cursor csResult (platformid N(12), ServerName C(30),;
			majorver N(12), minorver N(12), softtype N(12), Comment C(250))

		* copying the resulting array of SERVER_INFO_101 structures
		* to a VFP string
		lnBufLen = lnCountRead * SINFO_101_SIZE
		lcBuffer = Repli (Chr(0), lnBufLen)
		= Heap2String (@lcBuffer, lnBuffer, lnBufLen)

		* scanning resulting array
		For lnEntry = 1 To lnCountRead
			lcServerInfo = Substr (lcBuffer,;
				(lnEntry-1)*SINFO_101_SIZE+1, SINFO_101_SIZE)

			lnPlatformId = buf2dword (Substr (lcServerInfo,  1,4))
			lnNamePtr    = buf2dword (Substr (lcServerInfo,  5,4))
			lnMajorVer   = buf2dword (Substr (lcServerInfo,  9,4))
			lnMinorVer   = buf2dword (Substr (lcServerInfo, 13,4))
			lnSofttype   = buf2dword (Substr (lcServerInfo, 17,4))
			lnMemoPtr    = buf2dword (Substr (lcServerInfo, 21,4))

			lcServerName = getStrFromMem (lnNamePtr)
			lcServerMemo = getStrFromMem (lnMemoPtr)
			Wait Window lcServerName Nowait

			Insert Into csResult Values (lnPlatformId, lcServerName,;
				lnMajorVer, lnMinorVer, lnSofttype, lcServerMemo)
		Endfor
		Wait Clear
	Endif

	* releasing the memory block allocated regardless of the result
	* by OS within NetServerEnum call
	= NetApiBufferFree (lnBuffer)

	If Used ("csResult")
		Select csResult
		Go Top
		Browse Normal Nowait
	Endif
	Return

Function getStrFromMem (lnMemBlock)
	* converting memory allocated Unicode string to a VFP string
	#Define StrBufferLength   250
	Local lcBuffer
	lcBuffer = Space(StrBufferLength)
	Try
		= Heap2String (@lcBuffer, lnMemBlock, StrBufferLength)
		lcBuffer = Substr (lcBuffer, 1, At(Chr(0)+Chr(0),lcBuffer)-1)
	Catch
		lcBuffer = ""
		[ FINALLY]
		lcBuffer = ""
	Endtry

Return  Strtran(lcBuffer, Chr(0),"")

Function buf2dword (lcBuffer)
	Return Asc(Substr(lcBuffer, 1,1)) + ;
		Asc(Substr(lcBuffer, 2,1)) * 256 +;
		Asc(Substr(lcBuffer, 3,1)) * 65536 +;
		Asc(Substr(lcBuffer, 4,1)) * 16777216

Procedure Decl
	Declare Integer NetServerEnum In netapi32;
		INTEGER ServerName, Integer Level, Integer @ bufptr,;
		INTEGER prefmaxlen, Integer @ entriesread, Integer @ totalentries,;
		INTEGER servertype, Integer domain, Integer resume_handle

	Declare Integer NetApiBufferFree In netapi32 Integer Buffer

	Declare RtlMoveMemory In kernel32 As Heap2String;
		STRING @ Destination, Integer Source, Integer nLength
"Now to him who is able to do immeasurably more than all we ask or imagine, according to his power that is at work within us, Ephesians 3:20
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform