Community discussion forum

[5450] Using WMI From Managed Code

Tags:
  • 9 years ago

    This thread is for discussions of Using WMI From Managed Code.

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 2 years ago

    Using WMI is it possible to specify folder security rights for the user groups specified.

  • 1 year ago

    I am unable to detect my Network Printer's IP Address / Hostname. Is there something wrong in my code below?

     

    ConnectionOptions myConnectionOptions = new ConnectionOptions();

    myConnectionOptions.Impersonation = ImpersonationLevel.Impersonate;

    myConnectionOptions.Authentication = System.Management.AuthenticationLevel.Packet;

    string myServerName = ".";

    ManagementScope myManagementScope = new ManagementScope(@"\root\cimv2");

    myManagementScope.Connect();

    SelectQuery selectQuery = new SelectQuery();

    selectQuery.QueryString = String.Format("SELECT * FROM Win32_TCPIPPrinterPort WHERE Name = 'IP_10.25.1.221'");

    if (myManagementScope.IsConnected == false) Console.WriteLine("Could not connect to WMI namespace");

    ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(myManagementScope, selectQuery);

    foreach (ManagementObject objMgmt in managementObjectSearcher.Get())

    {

    if (objMgmt["Caption"].ToString()== "")

    {

    ...

    }

    }

    }

    catch (Exception err) { Console.WriteLine("Err:"+ err.Message); }

     

     

    Hope you can advise me..

     

     

Post a reply

Enter your message below

Sign in or Join us (it's free).