Re: WMI Query against remote machine. Access issues
- From: amit@xxxxxxxxx
- Date: Mon, 14 Apr 2008 05:29:52 -0700 (PDT)
On Apr 14, 11:27 am, a...@xxxxxxxxx wrote:
I am trying to query a service and perf mon counters on a remote
machine.
My code is as below.
ConnectionOptions opt = new ConnectionOptions();
opt.Impersonation = ImpersonationLevel.Impersonate;
opt.Timeout = new TimeSpan(0, 0, 30);
ManagementScope scope = new
ManagementScope(String.Format(@"\\{0}\root\cimv2", "TRLW16628"), opt);
scope.Connect();
if (scope.IsConnected)
{
//Select the SMTP Service
ObjectQuery query = new ObjectQuery("SELECT * FROM
Win32_Service WHERE Name = 'SMTPSVC'");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(scope, query);
//Loop through the collection and if the service
is started, set result to true
foreach (ManagementObject service in
searcher.Get())
{
Console.WriteLine("Service started = " +
service.Properties["Started"].Value);
}
}
and the perfmon query is SELECT * FROM
Win32_PerfFormattedData_SMTPSVC_SMTPServer
When I add my username to the local admin group on the remote computer
(TRLW16628) everything works fine.
I dont want to give admin rights to the user so instead, I have given
full rights to my user to root, and I have also given my user DCOM
remote launch and activation permissions.. but still no joy.
Through wbemtest.exe I get 0x80041003 Access Denied,
and in my code i get
System.Management.ManagementException: Access denied
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStat
us errorCode)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementScope.Connect()
at WMITestConsole.Program.Main(String[] args) in C:\Documents and
Settings\de
saia1\My Documents\Visual Studio 2005\Projects\WMITestConsole
\WMITestConsole\Pro
gram.cs:line 22
Anyone have any ideas
Ok I have got a bit further with this one..
I add applied permissions to the root name space and not the root
\cimv2 having corrected that.. I can now connect to the remote
computer, but the actual query still fails with the following
exception
System.Management.ManagementException: Generic failure
at
System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStat
us errorCode)
at
System.Management.ManagementObjectCollection.ManagementObjectEnumerator.Mo
veNext()
at WMITestConsole.Program.Main(String[] args) in C:\Documents and
Settings\de
saia1\My Documents\Visual Studio 2005\Projects\WMITestConsole
\WMITestConsole\Pro
gram.cs:line 29
.
- References:
- Prev by Date: WMI Query against remote machine. Access issues
- Next by Date: RE: Questions about WMI MOF Schemas and versioning
- Previous by thread: WMI Query against remote machine. Access issues
- Index(es):
Relevant Pages
|