Oğuzhan Sari

Oğuzhan Sari

  • NA
  • 7
  • 829

Error CreateServer Binding for WMI Create website (C#)

Jan 21 2017 1:05 PM

Please help me!

I have reviewed about 100 source pages.

I just could not do it.

I work 2 days.

My last point is creating a Binding.

I'm getting an "Access Denied" error.

[TR] Yaklasik 100 kaynak sayfa inceledim.

Bir türlü yapamadim.

2 gündür ugrasiyorum.

Son geldigim nokta Binding olusturma.

"Access Denied" hatasi aliyorum.

  1. public void Creator()  
  2.   {  
  3.   
  4.       string hostName = "BuBirSitedir";  
  5.       string domainName = "www.bubirsitedir.com";  
  6.   
  7.       ConnectionOptions options = new ConnectionOptions();  
  8.       options.Impersonation = System.Management.ImpersonationLevel.Impersonate;  
  9.       options.Authentication = AuthenticationLevel.Connect;  
  10.       options.EnablePrivileges = true;  
  11.       options.Impersonation = ImpersonationLevel.Default;  
  12.   
  13.       ManagementClass classInstance = new ManagementClass("root\\WebAdministration""Site"null);  
  14.   
  15.       ManagementScope scope = new ManagementScope(string.Format(@"\\{0}\root\MicrosoftIISV2""DESKTOP-MGA1F3C"), options);  
  16.       scope.Connect();  
  17.   
  18.       ManagementBaseObject[] serverBindings = new ManagementBaseObject[3];  
  19.       serverBindings[0] = CreateServerBinding(scope, string.Format("{0}", hostName, domainName), "127.0.0.1", 40804);  
  20.       serverBindings[1] = CreateServerBinding(scope, string.Format("30603", hostName, domainName), "127.0.0.1", 30603);  
  21.       serverBindings[2] = CreateServerBinding(scope, string.Format("127.0.0.1", hostName, domainName), "127.0.0.1", 20402);  
  22.   }  
  23.   
  24.   
  25.   private static ManagementObject CreateServerBinding(ManagementScope scope, string hostName, string ip, int port)  
  26.   {  
  27.       ManagementClass mc = new ManagementClass(scope, new ManagementPath("ServerBinding"), null);  
  28.       ManagementObject mco = mc.CreateInstance();  
  29.       mco.Properties["Hostname"].Value = hostName;  
  30.       mco.Properties["IP"].Value = ip;  
  31.       mco.Properties["Port"].Value = port;  
  32.       mco.Put();  
  33.       return mco;  
  34.   }  
 

Answers (1)