Ejemplo n.º 1
0
        internal static string GetResourceString(string Key)
        {
            if (WSManResourceLoader.ResourceValueCache.Count <= 0)
            {
                WSManResourceLoader.LoadResourceData();
            }
            string str = "";

            if (WSManResourceLoader.ResourceValueCache.ContainsKey(Key.Trim()))
            {
                WSManResourceLoader.ResourceValueCache.TryGetValue(Key.Trim(), out str);
            }
            return(str.Trim());
        }
Ejemplo n.º 2
0
        private void QuickConfigRemoting(bool serviceonly)
        {
            IWSManSession m_SessionObj = null;

            try
            {
                string   transport;
                IWSManEx wsmanObject = (IWSManEx) new WSManClass();
                m_SessionObj = (IWSManSession)wsmanObject.CreateSession(null, 0, null);
                string xpathEnabled     = string.Empty;
                string xpathText        = string.Empty;
                string xpathUpdate      = string.Empty;
                string analysisInputXml = string.Empty;
                string action           = string.Empty;
                string xpathStatus      = string.Empty;
                string xpathResult      = string.Empty;

                if (!usessl)
                {
                    transport = "http";
                }
                else
                {
                    transport = "https";
                }

                if (serviceonly)
                {
                    analysisInputXml = @"<AnalyzeService_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""></AnalyzeService_INPUT>";
                    action           = "AnalyzeService";
                }
                else
                {
                    string openAllProfiles = skipNetworkProfileCheck ? "<Force/>" : string.Empty;
                    analysisInputXml = @"<Analyze_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""><Transport>" + transport + "</Transport>" + openAllProfiles + "</Analyze_INPUT>";
                    action           = "Analyze";
                }

                string      analysisOutputXml = m_SessionObj.Invoke(action, "winrm/config/service", analysisInputXml, 0);
                XmlDocument resultopxml       = new XmlDocument();
                resultopxml.LoadXml(analysisOutputXml);

                if (serviceonly)
                {
                    xpathEnabled = "/cfg:AnalyzeService_OUTPUT/cfg:RemotingEnabled";
                    xpathText    = "/cfg:AnalyzeService_OUTPUT/cfg:Results";
                    xpathUpdate  = "/cfg:AnalyzeService_OUTPUT/cfg:EnableService_INPUT";
                }
                else
                {
                    xpathEnabled = "/cfg:Analyze_OUTPUT/cfg:RemotingEnabled";
                    xpathText    = "/cfg:Analyze_OUTPUT/cfg:Results";
                    xpathUpdate  = "/cfg:Analyze_OUTPUT/cfg:EnableRemoting_INPUT";
                }

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", "http://schemas.microsoft.com/wbem/wsman/1/config/service");
                string  enabled         = resultopxml.SelectSingleNode(xpathEnabled, nsmgr).InnerText;
                XmlNode sourceAttribute = resultopxml.SelectSingleNode(xpathEnabled, nsmgr).Attributes.GetNamedItem("Source");
                string  source          = null;
                if (sourceAttribute != null)
                {
                    source = sourceAttribute.Value;
                }

                string rxml = string.Empty;
                if (enabled.Equals("true"))
                {
                    string Err_Msg = string.Empty;
                    if (serviceonly)
                    {
                        Err_Msg = WSManResourceLoader.GetResourceString("L_QuickConfigNoServiceChangesNeeded_Message");
                    }
                    else
                    {
                        Err_Msg = WSManResourceLoader.GetResourceString("L_QuickConfigNoChangesNeeded_Message");
                    }
                    //  ArgumentException e = new ArgumentException(Err_Msg);
                    // ErrorRecord er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    //  WriteError(er);
                    WriteObject(Err_Msg);
                    return;
                }

                if (!enabled.Equals("false"))
                {
                    ArgumentException e  = new ArgumentException(WSManResourceLoader.GetResourceString("L_QuickConfig_InvalidBool_0_ErrorMessage"));
                    ErrorRecord       er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                string resultAction = resultopxml.SelectSingleNode(xpathText, nsmgr).InnerText;
                if (source != null && source.Equals("GPO"))
                {
                    string Info_Msg = WSManResourceLoader.GetResourceString("L_QuickConfig_RemotingDisabledbyGP_00_ErrorMessage");
                    Info_Msg += " " + resultAction;
                    ArgumentException e = new ArgumentException(Info_Msg);
                    WriteError(new ErrorRecord(e, "NotSpecified", ErrorCategory.NotSpecified, null));
                    return;
                }

                string inputXml = resultopxml.SelectSingleNode(xpathUpdate, nsmgr).OuterXml;
                if (resultAction.Equals(string.Empty) || inputXml.Equals(string.Empty))
                {
                    ArgumentException e  = new ArgumentException(WSManResourceLoader.GetResourceString("L_ERR_Message") + WSManResourceLoader.GetResourceString("L_QuickConfig_MissingUpdateXml_0_ErrorMessage"));
                    ErrorRecord       er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                if (serviceonly)
                {
                    action = "EnableService";
                }
                else
                {
                    action = "EnableRemoting";
                }

                rxml = m_SessionObj.Invoke(action, "winrm/config/service", inputXml, 0);
                XmlDocument finalxml = new XmlDocument();
                finalxml.LoadXml(rxml);

                if (serviceonly)
                {
                    xpathStatus = "/cfg:EnableService_OUTPUT/cfg:Status";
                    xpathResult = "/cfg:EnableService_OUTPUT/cfg:Results";
                }
                else
                {
                    xpathStatus = "/cfg:EnableRemoting_OUTPUT/cfg:Status";
                    xpathResult = "/cfg:EnableRemoting_OUTPUT/cfg:Results";
                }

                if (finalxml.SelectSingleNode(xpathStatus, nsmgr).InnerText.ToString().Equals("succeeded"))
                {
                    if (serviceonly)
                    {
                        WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdatedService_Message"));
                    }
                    else
                    {
                        WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdated_Message"));
                    }

                    WriteObject(finalxml.SelectSingleNode(xpathResult, nsmgr).InnerText);
                }
                else
                {
                    helper.AssertError(WSManResourceLoader.GetResourceString("L_ERR_Message") + WSManResourceLoader.GetResourceString("L_QuickConfigUpdateFailed_ErrorMessage"), false, null);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
        private void QuickConfigRemoting(bool serviceonly)
        {
            string        str;
            string        str1;
            string        str2;
            string        str3;
            string        str4;
            string        str5;
            string        str6;
            string        str7;
            string        resourceString;
            string        empty;
            IWSManSession wSManSession = null;

            try
            {
                IWSManEx wSManClass = (IWSManEx)(new WSManClass());
                wSManSession = (IWSManSession)wSManClass.CreateSession(null, 0, null);
                if (this.usessl)
                {
                    str = "https";
                }
                else
                {
                    str = "http";
                }
                if (!serviceonly)
                {
                    if (this.skipNetworkProfileCheck)
                    {
                        empty = "<Force/>";
                    }
                    else
                    {
                        empty = string.Empty;
                    }
                    string   str8      = empty;
                    string[] strArrays = new string[5];
                    strArrays[0] = "<Analyze_INPUT xmlns=\"http://schemas.microsoft.com/wbem/wsman/1/config/service\"><Transport>";
                    strArrays[1] = str;
                    strArrays[2] = "</Transport>";
                    strArrays[3] = str8;
                    strArrays[4] = "</Analyze_INPUT>";
                    str4         = string.Concat(strArrays);
                    str5         = "Analyze";
                }
                else
                {
                    str4 = "<AnalyzeService_INPUT xmlns=\"http://schemas.microsoft.com/wbem/wsman/1/config/service\"></AnalyzeService_INPUT>";
                    str5 = "AnalyzeService";
                }
                string      str9        = wSManSession.Invoke(str5, "winrm/config/service", str4, 0);
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(str9);
                if (!serviceonly)
                {
                    str1 = "/cfg:Analyze_OUTPUT/cfg:RemotingEnabled";
                    str2 = "/cfg:Analyze_OUTPUT/cfg:Results";
                    str3 = "/cfg:Analyze_OUTPUT/cfg:EnableRemoting_INPUT";
                }
                else
                {
                    str1 = "/cfg:AnalyzeService_OUTPUT/cfg:RemotingEnabled";
                    str2 = "/cfg:AnalyzeService_OUTPUT/cfg:Results";
                    str3 = "/cfg:AnalyzeService_OUTPUT/cfg:EnableService_INPUT";
                }
                XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
                xmlNamespaceManagers.AddNamespace("cfg", "http://schemas.microsoft.com/wbem/wsman/1/config/service");
                string  innerText = xmlDocument.SelectSingleNode(str1, xmlNamespaceManagers).InnerText;
                XmlNode namedItem = xmlDocument.SelectSingleNode(str1, xmlNamespaceManagers).Attributes.GetNamedItem("Source");
                string  value     = null;
                if (namedItem != null)
                {
                    value = namedItem.Value;
                }
                if (!innerText.Equals("true"))
                {
                    if (innerText.Equals("false"))
                    {
                        string innerText1 = xmlDocument.SelectSingleNode(str2, xmlNamespaceManagers).InnerText;
                        if (value == null || !value.Equals("GPO"))
                        {
                            string outerXml = xmlDocument.SelectSingleNode(str3, xmlNamespaceManagers).OuterXml;
                            if (innerText1.Equals("") || outerXml.Equals(""))
                            {
                                ArgumentException argumentException = new ArgumentException(string.Concat(WSManResourceLoader.GetResourceString("L_ERR_Message"), WSManResourceLoader.GetResourceString("L_QuickConfig_MissingUpdateXml_0_ErrorMessage")));
                                ErrorRecord       errorRecord       = new ErrorRecord(argumentException, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                                base.WriteError(errorRecord);
                            }
                            else
                            {
                                if (!serviceonly)
                                {
                                    str5 = "EnableRemoting";
                                }
                                else
                                {
                                    str5 = "EnableService";
                                }
                                string      str10        = wSManSession.Invoke(str5, "winrm/config/service", outerXml, 0);
                                XmlDocument xmlDocument1 = new XmlDocument();
                                xmlDocument1.LoadXml(str10);
                                if (!serviceonly)
                                {
                                    str6 = "/cfg:EnableRemoting_OUTPUT/cfg:Status";
                                    str7 = "/cfg:EnableRemoting_OUTPUT/cfg:Results";
                                }
                                else
                                {
                                    str6 = "/cfg:EnableService_OUTPUT/cfg:Status";
                                    str7 = "/cfg:EnableService_OUTPUT/cfg:Results";
                                }
                                if (!xmlDocument1.SelectSingleNode(str6, xmlNamespaceManagers).InnerText.ToString().Equals("succeeded"))
                                {
                                    this.helper.AssertError(string.Concat(WSManResourceLoader.GetResourceString("L_ERR_Message"), WSManResourceLoader.GetResourceString("L_QuickConfigUpdateFailed_ErrorMessage")), false, null);
                                }
                                else
                                {
                                    if (!serviceonly)
                                    {
                                        base.WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdated_Message"));
                                    }
                                    else
                                    {
                                        base.WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdatedService_Message"));
                                    }
                                    base.WriteObject(xmlDocument1.SelectSingleNode(str7, xmlNamespaceManagers).InnerText);
                                }
                            }
                        }
                        else
                        {
                            string resourceString1 = WSManResourceLoader.GetResourceString("L_QuickConfig_RemotingDisabledbyGP_00_ErrorMessage");
                            resourceString1 = string.Concat(resourceString1, " ", innerText1);
                            ArgumentException argumentException1 = new ArgumentException(resourceString1);
                            base.WriteError(new ErrorRecord(argumentException1, "NotSpecified", ErrorCategory.NotSpecified, null));
                        }
                    }
                    else
                    {
                        ArgumentException argumentException2 = new ArgumentException(WSManResourceLoader.GetResourceString("L_QuickConfig_InvalidBool_0_ErrorMessage"));
                        ErrorRecord       errorRecord1       = new ErrorRecord(argumentException2, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord1);
                    }
                }
                else
                {
                    if (!serviceonly)
                    {
                        resourceString = WSManResourceLoader.GetResourceString("L_QuickConfigNoChangesNeeded_Message");
                    }
                    else
                    {
                        resourceString = WSManResourceLoader.GetResourceString("L_QuickConfigNoServiceChangesNeeded_Message");
                    }
                    base.WriteObject(resourceString);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(wSManSession.Error))
                {
                    this.helper.AssertError(wSManSession.Error, true, null);
                }
                if (wSManSession != null)
                {
                    this.Dispose(wSManSession);
                }
            }
        }