Hi, I would like to create a website that can stop or start an apppool on the local machine. The local machine is a Windows 2012 server and websites are hosted in IIS 8.0.
My code currently always ends with "System.Management.ManagementException: Invalid namespace"
Can someone tell me how to get the correct namespace and my code working?
The code is:
Private Shared Sub SendAppPoolCommand(appPoolName As String, command As String)
Dim co As System.Management.ConnectionOptions
co = New System.Management.ConnectionOptions()
'Dim objPath As String = "IISApplicationPool.Name='W3SVC/AppPools/" + appPoolName + "'"
Dim objPath As String = "IISApplicationPool.Name='" + appPoolName + "'"
Dim scope As System.Management.ManagementScope = New System.Management.ManagementScope("\\localhost\root\MicrosoftIISV2", co)
Using mc As System.Management.ManagementObject = New System.Management.ManagementObject(objPath)
mc.Scope = scope
mc.InvokeMethod(command, Nothing, Nothing)
End Using
End SubThank you.