@@ -15,6 +15,15 @@ public CCMApplicationService(string computerName = ".")
1515 _computerName = computerName ;
1616 }
1717
18+ /// <summary>
19+ /// Helper method to get the correct namespace path for local or remote operations
20+ /// </summary>
21+ private string GetNamespacePath ( string baseNamespace )
22+ {
23+ bool isLocal = _computerName == "." || _computerName . Equals ( Environment . MachineName , StringComparison . OrdinalIgnoreCase ) ;
24+ return isLocal ? baseNamespace : $@ "\\{ _computerName } \{ baseNamespace } ";
25+ }
26+
1827 /// <summary>
1928 /// Gets all applications from the Configuration Manager client
2029 /// </summary>
@@ -44,7 +53,7 @@ public IEnumerable<CCMApplication> GetApplications()
4453
4554 try
4655 {
47- var scope = new ManagementScope ( $@ "\\ { _computerName } \ root\CCM\ClientSDK") ;
56+ var scope = new ManagementScope ( GetNamespacePath ( " root\\ CCM\\ ClientSDK") ) ;
4857 scope . Connect ( ) ;
4958
5059 using var searcher = new ManagementObjectSearcher ( scope , new ObjectQuery ( "SELECT * FROM CCM_Application" ) ) ;
@@ -79,7 +88,7 @@ public IEnumerable<CCMApplication> GetApplicationsByName(string applicationName)
7988
8089 try
8190 {
82- var scope = new ManagementScope ( $@ "\\ { _computerName } \ root\CCM\ClientSDK") ;
91+ var scope = new ManagementScope ( GetNamespacePath ( " root\\ CCM\\ ClientSDK") ) ;
8392 scope . Connect ( ) ;
8493
8594 var query = $ "SELECT * FROM CCM_Application WHERE Name LIKE '%{ applicationName } %'";
@@ -123,7 +132,7 @@ public bool InstallApplication(string applicationId)
123132 {
124133 try
125134 {
126- var scope = new ManagementScope ( $@ "\\ { _computerName } \ root\CCM\ClientSDK") ;
135+ var scope = new ManagementScope ( GetNamespacePath ( " root\\ CCM\\ ClientSDK") ) ;
127136 scope . Connect ( ) ;
128137
129138 using var appClass = new ManagementClass ( scope , new ManagementPath ( "CCM_Application" ) , null ) ;
0 commit comments