Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Mon, 14 Apr 2008 03:27:39 -0700 (PDT),    group: microsoft.public.win32.programmer.wmi        back       


WMI Query against remote machine. Access issues   
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
date: Mon, 14 Apr 2008 03:27:39 -0700 (PDT)   author:   unknown

Re: WMI Query against remote machine. Access issues   
On Apr 14, 11:27 am, a...@c4ppy.net 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
date: Mon, 14 Apr 2008 05:29:52 -0700 (PDT)   author:   unknown

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us