Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Looking for a way to find all network shares
Message
 
 
To
13/05/2004 11:44:27
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00901701
Message ID:
00903671
Views:
23
>Worked like a charm. Thank you. Seems incredible that a program with such a major flaw would get posted in such a conspicuous place for general use. I had wondered about those lines of code, but assumed it was just that I didn't fully understand the workings of the classes involved.

I wouldn't be so quick to judge. Ed was the most knowleable person I knew in UT community and he selflessly shared his knowledge and expirience with the rest of us. It's just a demo which doesn't and as such requires understanding and adjustment for use in an application.
Anyway, for interested, here's simplified working version of GetAllShare program and some adjustments to NetRsc.prg
* GetAllShare
SET PROCEDURE TO CLSHEAP ADDITIVE
SET PROCEDURE TO NETRSC ADDITIVE
*	We need some API definitions
DECLARE INTEGER WNetOpenEnum IN WIN32API ;
	INTEGER dwScope, ;
	INTEGER dwType, ;
	INTEGER dwUseage, ;
	STRING @ lpNetResource, ;
	INTEGER @ lphEnum

DECLARE INTEGER WNetEnumResource IN WIN32API ;
	INTEGER hEnum, ;
	INTEGER @lpcCount, ;
	INTEGER lpBuffer, ;
	INTEGER @ lpBufferSize

DECLARE INTEGER WNetCloseEnum IN WIN32API INTEGER hEnum

LOCAL oHeapObj, oNetRsc, hEnum, nResult, nBuff, cBuff, nCnt, i

CREATE CURSOR crsShares ( ;
	Scope C(32), ;
	Type C(32), ;
	DisplayType C(32), ;
	Usage C(32), ;
	LocalName C(32), ;
	RemoteName C(60), ;
	Provider C(60))

*  Set up a Heap and a NetResource Object
oHeapObj=CREATEOBJ('Heap')
PRIVATE pnProcessed, pnAdded
STORE 0 TO pnProcessed, pnStored

=GetMoreShare(0, oHeapObj)
RETURN
*------------------------------

PROCEDURE GetMoreShare
LPARAMETERS cNetRsc, oHeap
LOCAL oNR, hEnum
LOCAL nResult, nBuffPtr, nBufSize, nCnt, cBuff, i
oNR = CREATEOBJ('NETRESOURCE',oHeap)
hEnum = 0
*	Open the container referenced by the NETRESOURCE passed in
nResult = 0
nResult = WNetOpenEnum(2,0,0,cNetRsc,@hEnum)
nBuffPtr = oHeap.Alloc(4000)
DO WHILE nResult = 0
	oHeap.CopyTo(nBuffPtr, SPACE(4000))
	nCnt = 25
	nBufSize = 4000
	nResult = WNetEnumResource(@hEnum, @nCnt, nBuffPtr, @nBufSize)
	cBuff = oHeap.CopyFrom(nBuffPtr)
	FOR i = 0 TO nCnt-1
		oNR.cNETRESOURCE = SUBST(cBuff,(32 * i + 1),32)
		oNR.ParseNETRESOURCE()
		pnProcessed = pnProcessed + 1
		WAIT WINDOW NOWAIT "Processed/Stored Shares: " + ;
				TRANSFORM(pnProcessed) + " / " + TRANSFORM(pnStored)
		IF NOT ISNULL(oNR.GetRemoteName()) AND NOT EMPTY(oNR.GetRemoteName())
			SELECT crsShares
			SCATTER NAME oRec

			oRec.Scope = oNR.GetScope()
			oRec.type = oNR.GetType()
			oRec.DisplayType = oNR.GetDisplayType()
			oRec.Usage = oNR.GetUseage()
			oRec.LocalName = oNR.GetLocalName()
			oRec.RemoteName = oNR.GetRemoteName()
			oRec.Provider = oNR.GetProviderName()
			
			INSERT INTO crsShares FROM NAME oRec   && VFP8 specific
			
			pnStored = pnStored + 1
			*? oNR.GetLocalName(), oNR.GetRemoteName(), oNR.GetProviderName(), ;
					oNR.GetUseage(), oNR.GetType()
			IF 'CONTAINER' $ oNR.GetUseage()
				=GetMoreShare(oNR.cNETRESOURCE, oHeap)
			ENDIF
		ENDIF
	ENDFOR
ENDDO
=WNetCloseEnum(hEnum)
oHeap.DeAlloc(nBuffPtr)
RETURN

*----------------------------------------------------------------------------
* NetRsc.prg
...
	PROTECTED FUNCTION UseageConvert
	* Convert freely between Numeric and Character string
		LPARAMETER uUseageValue
		LOCAL uReturnValue, cParms
		IF TYPE('uUseageValue') = 'N'
			cParms = ''
			IF uUseageValue = 31
				uReturnValue = 'ALL'
			ELSE
				*	Bitmapped - build the string for each bit set
				IF BITAND(uUseageValue,1) # 0
					cParms = 'CONNECTABLE+'
				ENDIF
				IF BITAND(uUseageValue,2) # 0
					cParms = cParms + 'CONTAINER+'
				ENDIF
				IF BITAND(uUseageValue,4) # 0
					cParms = cParms + 'NOLOCALDEVICE+'
				ENDIF
				IF BITAND(uUseageValue,8) # 0
					cParms = cParms + 'SIBLING+'
				ENDIF
				IF BITAND(uUseageValue,16) # 0
					cParms = cParms + 'ATTACHED+'
				ENDIF
				IF BITAND(uUseageValue, 0x80000000) # 0
					cParms = cParms + 'RESERVED+'
				ENDIF
				IF BITAND(uUseageValue,0x7FFFFFE0) # 0
					cParms = cParms + 'UNKNOWN ' + ;
                                          TRANSFORM(BITAND(uUseageValue,0x7FFFFFE0),'@0') + '+'
				ENDIF
				IF LEN(cParms) > 0
					uReturnValue = LEFT(cParms, LEN(cParms) - 1)
				ELSE
					uReturnValue = 'NONE'
				ENDIF
			ENDIF
		ELSE
			cParms = UPPER(uUseageValue)
			uReturnValue = 0
			IF cParms = 'ALL'
				uReturnValue = 31
			ELSE
				*	Bitmapped - add the proper number for each bit set
				IF 'CONNECTABLE' $ cParms
					uReturnValue = uReturnValue + 1
				ENDIF
				IF 'CONTAINER' $ cParms
					uReturnValue = uReturnValue + 2
				ENDIF
				IF 'NOLOCALDEVICE' $ cParms
					uReturnValue = uReturnValue + 4
				ENDIF
				IF 'SIBLING' $ cParms
					uReturnValue = uReturnValue + 8
				ENDIF
				IF 'ATTACHED' $ cParms
					uReturnValue = uReturnValue + 16
				ENDIF
				IF 'RESERVED' $ cParms
					uReturnValue = BITOR(uReturnValue, 0x80000000)
				ENDIF
			ENDIF
		ENDIF
		RETURN uReturnValue
	ENDFUNC
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform