VB.NET Help with outputting Method Parameters -


i trying print (to text file) fragmentation information give win32_volume class using defraganalysis method , have come following vb.net code:

dim objreader streamwriter         objreader = new streamwriter(folderbrowserdialog.selectedpath + "\fraginfo" + "_" + creationdate + ".txt")          dim colitemsfraginfo new managementobjectsearcher("root\cimv2", "select * win32_volume drivetype = 3")          each queryobj managementobject in colitemsfraginfo.get()             objreader.writeline("analyzing volume " + queryobj("driveletter"))              dim inparams managementbaseobject = queryobj.getmethodparameters("defraganalysis")             dim outparams managementbaseobject = queryobj.invokemethod("defraganalysis", inparams, nothing)              msgbox(outparams("volumesize"))             objreader.writeline(" volume size: " + outparams("volumesize"))         next          objreader.close()      catch err managementexception         messagebox.show("an error occurred while trying execute wmi method: " & err.message)     end try 

the thing cannot head around how parameter info (i.e. "volumesize") method "defraganalysis". above code returns "method not found error".

thank you

-edit works when executed in wmi code creator:

imports system imports system.management imports system.windows.forms  namespace wmisample      public class mywmiquery          public overloads shared function main() integer              try              dim colitemsvolinfo new managementobjectsearcher("root\cimv2", "select * win32_volume drivetype = '3'")              each queryobj managementobject in colitemsvolinfo.get()                  dim outparams managementbaseobject = queryobj.invokemethod("defraganalysis", nothing, nothing)                 console.writeline(" volume size: {0}mb", math.round(outparams("defraganalysis")("volumesize")) * (9.53674316 * 10 ^ -7))                 console.writeline(" cluster size: {0}mb", math.round(outparams("defraganalysis")("clustersize")) * (9.53674316 * 10 ^ -7))                  if outparams("defragrecommended") = true                     console.writeline("you should defragment volume.")                 else                     console.writeline("you not need defragment volume.")                 end if                     next          catch err managementexception             messagebox.show("an error occurred while trying execute wmi method: " & err.message)          end try         end function     end class end namespace 

wmi output: volume size: 40857.9960763451mb cluster size: 0.003906249998336mb not need defragment volume.

however executing in visual studio returns below: volume size: mb cluster size: mb not need defragment volume.

the point here though not work under windows server 2008 r2, work under windows server 2003 (when executed in visual studio), wmi code work regardless of platform.

nb: have played "console.writeline" , changed "debug.writeline" output value immediate window.

there no property volumesize.

when call defraganalysis() returns status of function , outs parameters boolean defragrecommended , object defraganalysis.

defraganalysis class contains property volumesize.

console.writeline("defragrecommended: {0}", outparams("defragrecommended")) console.writeline("volumesize: {0}", outparams("defraganalysis")("volumesize")) console.writeline("returnvalue: {0}", outparams("returnvalue")) 

you should read documentation instead of making guess.

i suggest nice tool called wmi code creator v1.0. tool tool allows generate vbscript, c#, , vb .net code uses wmi complete management task such querying management data, executing method wmi class, or receiving event notifications using wmi.

i hope helps. : )


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -