Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help cleaning up C# Code (WMI code) - Neewbie

Help cleaning up C# Code (WMI code) - Neewbie

Scheduled Pinned Locked Moved C#
xmlquestioncsharpsharepointdatabase
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Buck_Murdock
    wrote on last edited by
    #1

    I'm not a programmer by any measure so I'm turning to you all for help. I'm creating an InfoPath form which is housing some C# code to run WMI queries when the form is entered. The user will then enter in a few bits of information about them self and submit the form to a SharePoint library to help keep track of our users inventory. My question is can someone help me clean up this code before i get too far into it? I've been using the WMI Code Creator from Microsoft's Website to get the code samples and by brut force I've gotten them to start to pull the information i'm looking for, but the code seems a little ugly and messy for me. I'm sure there has to be a way to condense some of this code and make it easier to manage and i want to start to figure that out before i get too far, once I see how it's done I should be able to figure it out from there. My code sample just has the video card and the sound card query, but eventually i'll have RAM, Hard drive, CPU, etc. Code Sample:

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using System.Management;
    //using System.Windows.Forms;

    namespace Inventory_Rev1
    {
    public partial class FormCode
    {
    // Member variables are not supported in browser-enabled forms.
    // Instead, write and read these values from the FormState
    // dictionary using code such as the following:
    //
    // private object _memberVariable
    // {
    // get
    // {
    // return FormState["_memberVariable"];
    // }
    // set
    // {
    // FormState["_memberVariable"] = value;
    // }
    // }

        // NOTE: The following procedure is required by Microsoft Office InfoPath.
        // It can be modified using Microsoft Office InfoPath.
        public void InternalStartup()
        {
            EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents\_Loading);
        }
    
        public void FormEvents\_Loading(object sender, LoadingEventArgs e)
        {
            ManagementObjectSearcher searcherRAM =
                new ManagementObjectSearcher("root\\\\CIMV2",
                "SELECT \* FROM Win32\_PhysicalMemory");
            //ManagementObjectCollection oReturnCollection = searcher.Get();
    
            ManagementObjectSearcher searcherDisplay =
                    new ManagementObjectSearcher("root\\\\CIMV2",
                    "SELECT \* FROM Win32\_VideoController
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups