/// <summary> /// Gets the name of the application from. /// </summary> /// <param name="applicationName">Name of the application.</param> /// <param name="onlyLatest">if set to <c>true</c> [only latest].</param> /// <returns></returns> private sccm.Application GetApplicationFromName(string applicationName) { WqlResultObject appReference = GetApplicationWQLFromName(applicationName); if (appReference != null) { ////load all the properties for the application object so it can be loaded into an AppManWrapper to retrive application appReference.Get(); ApplicationFactory applicationFactory = new ApplicationFactory(); AppManWrapper applicationWrapper = AppManWrapper.WrapExisting(appReference, applicationFactory) as AppManWrapper; return(applicationWrapper.InnerAppManObject as sccm.Application); } return(null); }
/// <summary> /// Return a single Application object /// </summary> internal static Application GetApplicationByName(string name, string server) { NamedObject.DefaultScope = "xCM"; WqlConnectionManager connectionManager = CMConnection.Connect(server); IResultObject applications = connectionManager.QueryProcessor.ExecuteQuery("SELECT * FROM SMS_Application WHERE LocalizedDisplayName='" + name + "' AND IsLatest=1"); // this should only return one result, but we need to perform a Get() to retrieve the lazy properties IResultObject application = null; foreach (IResultObject result in applications) { result.Get(); // tip : make sure the CI_ID is not in single quotes, for example, SMS_Application.CI_ID='123456' application = connectionManager.GetInstance(@"SMS_Application.CI_ID=" + result["CI_ID"].IntegerValue); } ApplicationFactory applicationFactory = new ApplicationFactory(); AppManWrapper applicationWrapper = AppManWrapper.WrapExisting(application, applicationFactory) as AppManWrapper; return(applicationWrapper.InnerAppManObject as Application); }