コード例 #1
0
ファイル: wmihelper.cs プロジェクト: oturan-boga/nt5src
        public static ISWbemObject GetClassObject(String server,
                                                  String ns,
                                                  String className)
        {
            if (ns == string.Empty || className == string.Empty)
            {
                throw new ArgumentException();
            }

            try
            {
                ISWbemLocator wbemLocator = WmiHelper.wbemLocator;                //(ISWbemLocator)(new SWbemLocator());

                ISWbemServices wbemServices = wbemLocator.ConnectServer(server,
                                                                        ns,
                                                                        "",                                                     //user: blank defaults to current logged-on user
                                                                        "",                                                     //password: blank defaults to current logged-on user
                                                                        "",                                                     //locale: blank for current locale
                                                                        "",                                                     //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                                        0,                                                      //flags: reserved
                                                                        null);                                                  //context info: not needed here

                ISWbemObject classObj = wbemServices.Get(className,
                                                         (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                                         null);
                return(classObj);
            }

            catch (Exception e)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace));
                return(null);
            }
        }
コード例 #2
0
ファイル: wmiclassnode.cs プロジェクト: wolewd/windows-XP-SP1
        //
        // CONSTRUCTORS
        //

        // <doc>
        // <desc>
        //     Main constructor.
        //     Parameters:
        //	string server (in, machine name)
        //	string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass")
        // </desc>
        // </doc>
        public WMIClassNode(string pathIn)
        {
            try
            {
                path = pathIn;

                //parse the path to get server, namespace and class name
                Int32 separ = path.IndexOf("\\", 2);
                if (separ == -1)
                {
                    //invalid path
                    throw (new Exception("Invalid argument"));
                }

                serverName   = path.Substring(2, separ - 2);
                pathNoServer = path.Substring(separ + 1, path.Length - separ - 1);


                //split pathNoServer into namespace and classname parts (':' is the separator)
                Int32 colon = pathNoServer.IndexOf(':', 0);
                if (colon == -1)
                {
                    //invalid path
                    throw (new Exception("Invalid argument"));
                }
                nsName    = pathNoServer.Substring(0, colon);
                className = pathNoServer.Substring(colon + 1, pathNoServer.Length - colon - 1);

                //Get and cache wmiObj
                ISWbemLocator wbemLocator = (ISWbemLocator)(new SWbemLocator());

                wbemServices = wbemLocator.ConnectServer(serverName,
                                                         nsName,
                                                         "",                    //user: blank defaults to current logged-on user
                                                         "",                    //password: blank defaults to current logged-on user
                                                         "",                    //locale: blank for current locale
                                                         "",                    //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                         0,                     //flags: reserved
                                                         null);                 //context info: not needed here
                if (wbemServices == null)
                {
                    throw new Exception("Could not connect to WMI");
                }

                wmiObj = wbemServices.Get(className,
                                          0,
                                          //(int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                          null);
                if (wmiObj == null)
                {
                    throw new Exception("Could not get WMI object" + path);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show("Exception: " + exc.Message + "\n\rTrace: " + exc.StackTrace);
                throw (exc);
            }
        }
コード例 #3
0
        /// <summary>
        ///     The object retrieves its serialization info.
        /// </summary>
        public WMIAssocGroupNode(SerializationInfo info, StreamingContext context)
        {
            try
            {
                try
                {
                    rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res",                          // Name of the resource.
                                             ".",                                                     // Use current directory.
                                             null);
                }
                catch (Exception)
                {
                    //do nothing, will use static RM
                }


                //De-serialize string data mambers
                String associationPath = info.GetString("associationPath");
                String targetClass     = info.GetString("targetClass");
                String targetRole      = info.GetString("targetRole");


                //De-serialize strings necessary to restore the source object
                String sourcePath   = info.GetString("sourcePath");
                String sourceNS     = info.GetString("sourceNS");
                String sourceServer = info.GetString("sourceServer");

                //Restore SWbemObject for "source"
                ISWbemLocator wbemLocator = WmiHelper.WbemLocator;                //(ISWbemLocator)(new SWbemLocator());

                ISWbemServices wbemServices = wbemLocator.ConnectServer(sourceServer,
                                                                        sourceNS,
                                                                        "",                                             //user: blank defaults to current logged-on user
                                                                        "",                                             //password: blank defaults to current logged-on user
                                                                        "",                                             //locale: blank for current locale
                                                                        "",                                             //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                                        0,                                              //flags: reserved
                                                                        null);                                          //context info: not needed here

                ISWbemObject sourceInst = wbemServices.Get(sourcePath,
                                                           (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                                           null);


                theComp = new AssocGroupComponent(sourceInst,
                                                  associationPath,
                                                  targetClass,
                                                  targetRole);
            }

            catch (Exception exc)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
                throw (exc);
            }
        }
コード例 #4
0
ファイル: wmihelper.cs プロジェクト: oturan-boga/nt5src
        /// <summary>
        /// This is the method to call in case you cannot QI for ISWbemObject
        /// on the cached SWbemObject (bug in interop? urt?)
        /// </summary>
        /// <param name="objPath"> </param>
        /// <param name="services">  propriately</param>
        /// <param name="serverName"> </param>
        /// <param name="nsName"> </param>
        static public ISWbemObject GetObject(string objPath,
                                             ISWbemServices services,                                                           //in - out
                                             string serverName,
                                             string nsName)
        {
            try
            {
                try
                {
                    ISWbemSecurity sec = services.Security_;
                }
                catch (Exception)
                {
                    //MessageBox.Show ("refreshing services in wmihelper");
                    services = null;
                    services = WbemLocator.ConnectServer(serverName,
                                                         nsName,
                                                         string.Empty,
                                                         string.Empty,
                                                         string.Empty,
                                                         string.Empty,
                                                         0,
                                                         null);
                }
                ISWbemObject obj = services.Get(objPath,
                                                (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                                null);
                //MessageBox.Show ("refreshing object in wmihelper");


                return(obj);
            }
            catch (Exception e)
            {
                MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace));

                return(null);
            }
        }
コード例 #5
0
ファイル: wmihelper.cs プロジェクト: oturan-boga/nt5src
        public static ISWbemObject GetClassObject(ISWbemObject objIn)
        {
            if (objIn == null)
            {
                throw new ArgumentException();
            }

            try
            {
                ISWbemObjectPath path = objIn.Path_;

                if (path.IsClass)
                {
                    return(objIn);
                }

                ISWbemLocator wbemLocator = WmiHelper.wbemLocator;                //(ISWbemLocator)(new SWbemLocator());

                ISWbemServices wbemServices = wbemLocator.ConnectServer(path.Server,
                                                                        path.Namespace,
                                                                        "",                                                     //user: blank defaults to current logged-on user
                                                                        "",                                                     //password: blank defaults to current logged-on user
                                                                        "",                                                     //locale: blank for current locale
                                                                        "",                                                     //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                                        0,                                                      //flags: reserved
                                                                        null);                                                  //context info: not needed here

                ISWbemObject classObj = wbemServices.Get(path.Class,
                                                         (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                                         null);
                return(classObj);
            }

            catch (Exception e)
            {
                //MessageBox.Show(WMISys.GetString("WMISE_Exception", e.Message, e.StackTrace));
                return(null);
            }
        }
コード例 #6
0
ファイル: wmiclassnode.cs プロジェクト: oturan-boga/nt5src
        // private NewChildNode newChildNode = null;


        //
        // CONSTRUCTORS
        //

        // <doc>
        // <desc>
        //     Main constructor.
        //     Parameters:
        //	string server (in, machine name)
        //	string pathIn (in, WMI path without the server name , e.g. "root\default:MyClass")
        // </desc>
        // </doc>
        public WMIClassNode(string pathIn)
        {
            try
            {
                try
                {
                    rm = new ResourceManager("Microsoft.VSDesigner.WMI.Res", // Name of the resource.
                                             ".",                            // Use current directory.
                                             null);
                }
                catch (Exception)
                {
                    //do nothing, will use static RM
                }


                path = pathIn;

                //parse the path to get server, namespace and class name
                Int32 separ = path.IndexOf("\\", 2);
                if (separ == -1)
                {
                    //invalid path
                    throw (new ArgumentException(WMISys.GetString("WMISE_InvalidPath", pathIn), "pathIn"));
                }

                serverName   = path.Substring(2, separ - 2);
                pathNoServer = path.Substring(separ + 1, path.Length - separ - 1);


                //split pathNoServer into namespace and classname parts (':' is the separator)
                Int32 colon = pathNoServer.IndexOf(':', 0);
                if (colon == -1)
                {
                    //invalid path
                    throw (new ArgumentException(WMISys.GetString("WMISE_InvalidPath, pathIn"), "pathIn"));
                }
                nsName    = pathNoServer.Substring(0, colon);
                className = pathNoServer.Substring(colon + 1, pathNoServer.Length - colon - 1);

                //Get and cache wmiObj
                ISWbemLocator wbemLocator = WmiHelper.WbemLocator;                //(ISWbemLocator)(new SWbemLocator());

                wbemServices = wbemLocator.ConnectServer(serverName,
                                                         nsName,
                                                         "",                    //user: blank defaults to current logged-on user
                                                         "",                    //password: blank defaults to current logged-on user
                                                         "",                    //locale: blank for current locale
                                                         "",                    //authority: NTLM or Kerberos. Blank lets DCOM negotiate.
                                                         0,                     //flags: reserved
                                                         null);                 //context info: not needed here


                wmiObj = wbemServices.Get(className,
                                          (int)WbemFlagEnum.wbemFlagUseAmendedQualifiers,
                                          null);
            }
            catch (Exception exc)
            {
                //MessageBox.Show(WMISys.GetString("WMISE_Exception", exc.Message, exc.StackTrace));
                throw (exc);
            }
        }