Reputation: 45
I am developing a WMI query windows service to query network servers. If I run the application in console, it works as expected but the service fails to complete the WMI query. Is there any way I can setup the service so the RPC doesn't fail due to insufficient privileges? I am using credentials in the WMI query to connect to the remote PC so that should not be a problem.
Thanks
Upvotes: 3
Views: 740
Reputation: 1476
Probable reason:
Firewall configuration (RPC connections blockage)
You don't have enough permission to run WMI queries.
Second point is valid if you are trying to run queries on remote machines. You can use wbemtest
to verify.
Windows+R (run command)
Type wbemtest
You have to connect ManagementScope
and check for it's validity scope.IsConnected
. It is just a snippet of code, you might have to provide a structure to it.
ConnectionOptions cOption = new ConnectionOptions();
ManagementScope scope = new ManagementScope("\\\\" + machine + "\\" + nameSpaceRoot + "\\" + managementScope, cOption);
scope.Options.Username = UserName;
scope.Options.Password = passWord;
scope.Options.EnablePrivileges = true;
scope.Options.Authentication = AuthenticationLevel.PacketPrivacy;
//scope.Options.Timeout = TimeSpan.FromSeconds(180);
//cOption.Timeout = TimeSpan.FromSeconds(180);
scope.Options.Impersonation = ImpersonationLevel.Impersonate;
scope.Connect();
return scope;
if (scope.IsConnected && scope != null)
{
query = new ObjectQuery(@"Select * from Win32_SCSIController");
searcher = new ManagementObjectSearcher(scope, query); searcher.Options.Timeout = new TimeSpan(0, 0, wbemConnectFlagUseMaxWait);
ManagementObjectCollection qWin32_SCSIController = searcher.Get();
foreach (ManagementObject item in qWin32_SCSIController)
{
<Some code here>
}
Upvotes: 1