Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP.exe to different VFP.exe
Message
De
16/02/2021 10:57:19
 
 
À
16/02/2021 10:54:07
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01678195
Message ID:
01678269
Vues:
44
>>Update:
>>Now I remember that VFP6 has no empty object - so vfp6 users would have to change "empty" for "line" .
>
>Marco, I think that VFP6 support would require a different approach. There would certainly be conflicts with Line existing properties and the properties of Win32_ classes, starting with Name.

Hi Antonio..
Just tested.. It works with a simple workaround:
**************************************************************
* Marco Plaza, 2018,2021
* @nfoxDev
* https://github.com/nftools/wmiquery
**************************************************************
*
* WMI Query Tool : returns an object with item count & items array from wmiquery
*
* simple usage: wmiQuery( wmiQuery [, wmiClass] )
* ( wmiclass defaults to "CIMV2" )
*
* Returns: Object as #oWmiResult
*
*#oWmiResult:
*      .count = "i"
*      .items[]
*         -item = "v"
*
* sample procedure "testme" included below
*****************************************************************
Parameters wmiClass,wmiNameSpace

Private All

wmiClass	 = Evl(m.wmiClass,'')
wmiNameSpace = Evl(m.wmiNameSpace,'CIMV2')

emessage = ''

#If Version(5) > 7
	#Define EMPTYORLINE  'empty'
#Else
	#Define EMPTYORLINE 'line'
#Endif


Try
	objwmiservice = Getobject("winmgmts://./root/"+m.wmiNameSpace)
	oquery	= objwmiservice.execquery( 'SELECT * FROM '+m.wmiClass,,48)
	owmi		= processobject( m.oquery )
Catch To oerr
	emessage = m.oerr.Message
Endtry

If !Empty(m.emessage)
	Error ' Invalid WMI Class or NameSpace '
	Return .Null.
Else
	Return m.owmi
Endif

*-------------------------------------------------
Procedure processobject( oquery )
*-------------------------------------------------
Private All

owmi = Createobject(EMPTYORLINE)
AddProperty(owmi,'items(1)',.Null.)
nitem = 0

Try

	For Each oitem In m.oquery

		nitem = m.nitem + 1
		Dimension owmi.items(m.nitem)
		owmi.items(m.nitem) = Createobject(EMPTYORLINE)
		setproperties( m.oitem, owmi.items(m.nitem) )

	Endfor

Catch

Endtry

AddProperty(owmi,'count',m.nitem)

Return m.owmi

*--------------------------------------------------------
Procedure setproperties( oitem , otarget  )
*--------------------------------------------------------
Private All

For Each property In m.oitem.properties_
	Try
		Do Case
		Case Vartype( m.property.Value ) = 'O'
			thisproperty = Createobject(EMPTYORLINE)
			setproperties(m.property.Value, m.thisproperty )
			AddProperty( otarget ,m.property.Name,m.thisproperty)

		Case m.property.isarray

			AddProperty( otarget ,property.Name+'(1)',.Null.)
			thisarray = 'otarget.'+m.property.Name

			nitem = 0

			If !Isnull(m.property.Value)

				For Each Item In m.property.Value

					nitem = m.nitem+1
					Dimension &thisarray(m.nitem)

					If Vartype( m.item) = 'O'
						thisitem = Createobject(EMPTYORLINE)
						setproperties( m.item, m.thisitem )
						&thisarray(m.nitem) = m.thisitem
					Else
						&thisarray(m.nitem) = m.item
					Endif

				Endfor

			Endif

		Otherwise
			Try
				AddProperty( otarget ,m.property.Name,m.property.Value)
			Catch
				newName =  property.Name+'_'
				AddProperty( otarget ,m.newName,m.property.Value)
			Endtry

		Endcase

	Catch To oerr
		Messagebox( Textmerge('<<oerr.lineno>> <<oerr.message>> '),0)
		Exit
	Endtry
Endfor

*----------------------------------
Procedure testme
*----------------------------------
Public oinfo

oinfo = Create(EMPTYORLINE)

Wait 'Running WMI Query....please wait.. ' Window Nowait At Wrows()/2,Wcols()/2


AddProperty( oinfo, "monitors"  , wmiquery('Win32_PNPEntity where service = "monitor"') )
AddProperty( oinfo, "diskdrive" , wmiquery('Win32_diskDrive') )
AddProperty( oinfo, "startup" ,   wmiquery('Win32_startupCommand'))
AddProperty( oinfo, "BaseBoard" , wmiquery('Win32_baseBoard') )
AddProperty( oinfo, "netAdaptersConfig",  wmiquery('Win32_NetworkAdapterConfiguration') )


Messagebox( 'Please explore "oInfo" in debugger watch window or command line ',0)



*---------------------------------------------------------------------------------
Procedure testme_
* note:
* this code uses underscore ( _.prg ) as replacement for addproperty()
* available at https://raw.githubusercontent.com/nftools/underscore/master/_.prg
* the "addobject" version is below ( function testme_no_ )
*---------------------------------------------------------------------------------
Public oinfo

oinfo = Create(EMPTYORLINE)

Wait 'Running WMI Query....please wait.. ' Window Nowait At Wrows()/2,Wcols()/2


With _( m.oinfo )
	.monitors  =  wmiquery('Win32_PNPEntity where service = "monitor"')
	.diskdrive =  wmiquery('Win32_diskDrive')
	.startup   =  wmiquery('Win32_startupCommand')
	.BaseBoard =  wmiquery('Win32_baseBoard')
	.netAdaptersConfig = wmiquery('Win32_NetworkAdapterConfiguration')
Endwith


Messagebox( 'Please explore "oInfo" in debugger watch window or command line ',0)
@nfoxdev
github.com/nfoxdev
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform