vb.net - wmi to xml using for each -



vb.net - wmi to xml using for each -

guys time , help have function installed software on pc have list of string add: software name, software version, software install date problem in each need add together 2 sec xml tags illustration have software name:

dim xmlelement xmlnode = xnode.appendchild(xdoc.createelement("softwarename"))

y need more tags software version , instalation date in same each

dim xmlelement xmlnode = xnode.appendchild(xdoc.createelement("softwareversion")) dim xmlelement xmlnode = xnode.appendchild(xdoc.createelement("softwareinstalldate"))

how can that?

seek dim strsoftware new list(of string) dim regkey, subkey microsoft.win32.registrykey dim softwarename string dim softwarever string dim includes boolean dim softwareinstalldate string dim xdoc new xmldocument dim xnode xmlnode = xdoc.appendchild(xdoc.createelement("computerinfo")) dim xmlmasterelement xmlnode = xnode.appendchild(xdoc.createelement("software")) dim regpath string = "software\microsoft\windows\currentversion\uninstall" regkey = my.computer.registry.localmachine.opensubkey(regpath) dim subkeys() string = regkey.getsubkeynames each subk string in subkeys subkey = regkey.opensubkey(subk) softwarename = subkey.getvalue("displayname", "").tostring softwarever = subkey.getvalue("displayversion", "").tostring softwareinstalldate = subkey.getvalue("installdate", "").tostring if softwarename <> "" includes = true if softwarename.indexof("hotfix") <> -1 includes = false if softwarename.indexof("security update") <> -1 includes = false if softwarename.indexof("update for") <> -1 includes = false if includes = true strsoftware.add(softwarename.tostring) strsoftware.add(softwarever.tostring) strsoftware.add(softwareinstalldate.tostring) end if next each element string in strsoftware dim xmlelement xmlnode = xnode.appendchild(xdoc.createelement("softwarename")) xmlelement.innertext = element.tostring() next xnode.appendchild(xdoc.createelement("software")) dim xwriter new io.stringwriter() dim xml_writer new xmltextwriter(xwriter) xdoc.writeto(xml_writer) dim xmssoftinfo string = xwriter.tostring() homecoming xmssoftinfo grab ex exception writeeventlogerror("error module getsoft" + ex.message) throw new exception(ex.message) end seek

your code more readable if utilize 3 separate lists store each type of info : software name, version, , install date (or maybe improve if create proper model). illustration :

dim softwarename new list(of string) dim softwareversion new list(of string) dim softwareinstalldate new list(of string) ...... ...... 'store each info in proper list variable' softwarename.add(softwarename) softwareversion.add(softwarever) softwareinstalldate.add(softwareinstalldate) ...... ...... 'add info above 3 lists xml' dim size = softwarename.count integer = 0 size - 1 dim name xmlnode = xnode.appendchild(xdoc.createelement("softwarename")) dim version xmlnode = xnode.appendchild(xdoc.createelement("softwareversion")) dim installdate xmlnode = xnode.appendchild(xdoc.createelement("softwareinstalldate")) name.innertext = softwarename(i) version.innertext = softwareversion(i) installdate.innertext = softwareinstalldate(i) next

xml vb.net string list

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -