How to parameterize a hostname for ManagementScope?

rgouette

New member
Joined
Jun 28, 2023
Messages
4
Location
Maine, USA
Programming Experience
3-5
I'm trying to insert a parameter for hostname in the following code:

C#:
            ManagementScope scope =
                new ManagementScope(
                "\\\\{mySvrToCheck}\\root\\cimv2", options);

           scope.Options.Context.Add("mySvrToCheck", svrToCheck); //<----???

            scope.Options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
            scope.Connect();
When I insert this to debug: MessageBox.Show("Scope Path:" + "\r\n" + scope.Path);
The path simply contains :
1690911175800.png



Pretty new to C#, so I'm sure it's something easy...

Thanks much & Cheers,
Rich
 
Not easy to tell what you're asking but perhaps you meant to use an interpolated string:

C#:
  $"\\\\{svrToCheck}\\root\\cimv2", options);

Note the $ at the start and the use of the variable name inside the { }
 

Latest posts

Back
Top Bottom