My Laptop is running Vista RC1 and trying to use WMI to recycle an application pool on a remote Longhorn server. I am able to connect with the code listed below but it won't recycle the app pool. If I change the AuthenticationLevel property to anything else I get an Access Denied right away. If I have it on PacketPrivacy it connects however this message shows up in the event log? I also tried this from a straight console application using VB express vs. Visual Web Developer. same error showed up in the remote server. If I run this code from a console app locally on my Vista RC1 box, the app pools recycle. What obvious thing am I missing? :).
Access to the root\WebAdministration namespace was denied because the namespace is marked with RequiresEncryption but the script or application attempted to connect to this namespace with an authentication level below Pkt_Privacy. Change the authentication level to Pkt_Privacy and run the script or application again.
Here is the code
Sub Main() Whatever3("x.x.x.x", "lh5600\Administrator", "MyPassword") End Sub
Function Whatever3(ByVal ServerName As String, ByVal strUID As String, ByVal strPWD As String) As String
Dim options As New System.Management.ConnectionOptions options.Username = strUID
options.Password = strPWD
options.EnablePrivileges = True
options.Authentication = Management.AuthenticationLevel.PacketPrivacy
Dim path As New Management.ManagementPath("\\" & ServerName & "\root\WebAdministration:ApplicationPool.Name='DefaultAppPool'") Dim scope As New Management.ManagementScope(path, options) scope.Connect()
Dim opt As New Management.ObjectGetOptions Dim classInstance As New Management.ManagementObject(scope, path, opt) ' Execute the method and obtain the return values.
Dim outParams As Management.ManagementBaseObject = _ classInstance.InvokeMethod("Recycle", Nothing, Nothing) Return "done"
End Function
This works on a local Vista RC1 box.
Function Whatever3()
Dim path As New Management.ManagementPath("\\.\root\WebAdministration:ApplicationPool.Name='DefaultAppPool'")Dim scope As New Management.ManagementScope(path)scope.Connect()
Dim opt As New Management.ObjectGetOptionsDim classInstance As New Management.ManagementObject(scope, path, opt)' Execute the method and obtain the return values.
Dim outParams As Management.ManagementBaseObject = classInstance.InvokeMethod("Recycle", Nothing, Nothing)Return "done"
End Function