473,725 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SecurityExcepti on with PerformanceCoun ter on remote server in .NET 2.0

I have been struggling with a security issue that occurs under .NET
2.0, but does not occur under .NET 1.1. Essentially I am trying to
open up a performance counter on a remote server and monitor its value.
In .NET 1.1 this worked fine, however under .NET 2.0 it fails when I
am not an administrator on the remote server.

To provide a lean demonstration of the issue, I created the following
class:

=============== =============

using System;
using System.Diagnost ics;
using System.Threadin g;

namespace ConsoleApplicat ion3
{
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
string machineName = null;

// Was exactly 1 argument was passed?
if (args.Length != 1)
{
// Prompt for machine name
Console.Write(" Please enter a machine name: ");
machineName = Console.ReadLin e();
}
else
{
// Use command line argument
machineName = args[0];
}

// Get the performance counter
PerformanceCoun ter c = new PerformanceCoun ter("Processor" , "%
Processor Time", "_Total", machineName);

// Display counter value once every second for 5 seconds
for (int i = 0; i < 5; i++)
{
Console.WriteLi ne(c.RawValue);
Thread.Sleep(10 00);
}
}
catch (Exception ex)
{
Console.WriteLi ne("=========== ===");
Console.WriteLi ne(ex);
Console.WriteLi ne("=========== ===");
}
finally
{
Console.WriteLi ne();
Console.WriteLi ne("Hit ENTER to quit application.");
Console.ReadLin e();
}
}
}
}

=============== =============

I then created a batch file that compiles this file under both .NET 1.1
and .NET 2.0:

c:\windows\Micr osoft.NET\Frame work\v1.1.4322\ csc.exe
/out:CounterTest 11.exe /t:exe Class1.cs
c:\windows\Micr osoft.NET\Frame work\v2.0.50727 \csc.exe
/out:CounterTest 20.exe /t:exe Class1.cs
Now, when I run either version against a server on which I am an
administrator, I get the following output:
--------
C:\Projects\Con soleApplication 3>CounterTest20 .exe
Please enter a machine name: speck
6708935078125
6708945000000
6708954921875
6708964609375
6708974687500

Hit ENTER to quit application.
--------

When I run the .NET 1.1 version against a server on which I am only a
member of the "Performanc e Monitoring" group, I get the following
results:
--------
C:\Projects\Con soleApplication 3>CounterTest11 .exe
Please enter a machine name: bonnie
114549931445312
114549938945312
114549946445312
114549954023437
114549961523437

Hit ENTER to quit application.
--------

But when I run the .NET 2.0 version against the same server, I get the
following:
--------
C:\Projects\Con soleApplication 3>CounterTest20 .exe
Please enter a machine name: bonnie
==============
System.Security .SecurityExcept ion: Requested registry access is not
allowed.
at System.ThrowHel per.ThrowSecuri tyException(Exc eptionResource
resource)
at Microsoft.Win32 .RegistryKey.Op enSubKey(String name, Boolean
writable)
at Microsoft.Win32 .RegistryKey.Op enSubKey(String name)
at
System.Diagnost ics.Performance CounterLib.Find CustomCategory( String
categor
y, PerformanceCoun terCategoryType & categoryType)
at System.Diagnost ics.Performance CounterLib.GetC ategoryType(Str ing
machine, S
tring category)
at System.Diagnost ics.Performance Counter.Initial ize()
at System.Diagnost ics.Performance Counter..ctor(S tring categoryName,
String co
unterName, String instanceName, String machineName)
at ConsoleApplicat ion3.Class1.Mai n(String[] args)
The Zone of the assembly that failed was:
MyComputer
==============

Hit ENTER to quit application.

Now, I posted this earlier to another forum but the only suggestion was
that I was not running with Full Trust. I am launching the application
locally, and so I don't understand how I could not be running under
Full Trust. I poked around in the .NET 2.0 configuration tool, but
could not come up with any ideas.

Any insight into this problem would be very much appreciated!
Geoff McElhanon

Aug 24 '06 #1
3 4593
V2 uses WMI to collect performance information from the remote perfmon
(through the remote registry), that means that the impersonated user
(remote) must be a member of the (remote)adminis trators alias, only
administrators are allowed to read perf data.

Willy.

"Geoff McElhanon" <gm********@yah oo.comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
|I have been struggling with a security issue that occurs under .NET
| 2.0, but does not occur under .NET 1.1. Essentially I am trying to
| open up a performance counter on a remote server and monitor its value.
| In .NET 1.1 this worked fine, however under .NET 2.0 it fails when I
| am not an administrator on the remote server.
|
| To provide a lean demonstration of the issue, I created the following
| class:
|
| =============== =============
|
| using System;
| using System.Diagnost ics;
| using System.Threadin g;
|
| namespace ConsoleApplicat ion3
| {
| class Class1
| {
| /// <summary>
| /// The main entry point for the application.
| /// </summary>
| [STAThread]
| static void Main(string[] args)
| {
| try
| {
| string machineName = null;
|
| // Was exactly 1 argument was passed?
| if (args.Length != 1)
| {
| // Prompt for machine name
| Console.Write(" Please enter a machine name: ");
| machineName = Console.ReadLin e();
| }
| else
| {
| // Use command line argument
| machineName = args[0];
| }
|
| // Get the performance counter
| PerformanceCoun ter c = new PerformanceCoun ter("Processor" , "%
| Processor Time", "_Total", machineName);
|
| // Display counter value once every second for 5 seconds
| for (int i = 0; i < 5; i++)
| {
| Console.WriteLi ne(c.RawValue);
| Thread.Sleep(10 00);
| }
| }
| catch (Exception ex)
| {
| Console.WriteLi ne("=========== ===");
| Console.WriteLi ne(ex);
| Console.WriteLi ne("=========== ===");
| }
| finally
| {
| Console.WriteLi ne();
| Console.WriteLi ne("Hit ENTER to quit application.");
| Console.ReadLin e();
| }
| }
| }
| }
|
| =============== =============
|
| I then created a batch file that compiles this file under both .NET 1.1
| and .NET 2.0:
|
| c:\windows\Micr osoft.NET\Frame work\v1.1.4322\ csc.exe
| /out:CounterTest 11.exe /t:exe Class1.cs
| c:\windows\Micr osoft.NET\Frame work\v2.0.50727 \csc.exe
| /out:CounterTest 20.exe /t:exe Class1.cs
|
|
| Now, when I run either version against a server on which I am an
| administrator, I get the following output:
| --------
| C:\Projects\Con soleApplication 3>CounterTest20 .exe
| Please enter a machine name: speck
| 6708935078125
| 6708945000000
| 6708954921875
| 6708964609375
| 6708974687500
|
| Hit ENTER to quit application.
| --------
|
| When I run the .NET 1.1 version against a server on which I am only a
| member of the "Performanc e Monitoring" group, I get the following
| results:
| --------
| C:\Projects\Con soleApplication 3>CounterTest11 .exe
| Please enter a machine name: bonnie
| 114549931445312
| 114549938945312
| 114549946445312
| 114549954023437
| 114549961523437
|
| Hit ENTER to quit application.
| --------
|
| But when I run the .NET 2.0 version against the same server, I get the
| following:
| --------
| C:\Projects\Con soleApplication 3>CounterTest20 .exe
| Please enter a machine name: bonnie
| ==============
| System.Security .SecurityExcept ion: Requested registry access is not
| allowed.
| at System.ThrowHel per.ThrowSecuri tyException(Exc eptionResource
| resource)
| at Microsoft.Win32 .RegistryKey.Op enSubKey(String name, Boolean
| writable)
| at Microsoft.Win32 .RegistryKey.Op enSubKey(String name)
| at
| System.Diagnost ics.Performance CounterLib.Find CustomCategory( String
| categor
| y, PerformanceCoun terCategoryType & categoryType)
| at System.Diagnost ics.Performance CounterLib.GetC ategoryType(Str ing
| machine, S
| tring category)
| at System.Diagnost ics.Performance Counter.Initial ize()
| at System.Diagnost ics.Performance Counter..ctor(S tring categoryName,
| String co
| unterName, String instanceName, String machineName)
| at ConsoleApplicat ion3.Class1.Mai n(String[] args)
| The Zone of the assembly that failed was:
| MyComputer
| ==============
|
| Hit ENTER to quit application.
|
| Now, I posted this earlier to another forum but the only suggestion was
| that I was not running with Full Trust. I am launching the application
| locally, and so I don't understand how I could not be running under
| Full Trust. I poked around in the .NET 2.0 configuration tool, but
| could not come up with any ideas.
|
| Any insight into this problem would be very much appreciated!
|
|
| Geoff McElhanon
|
Aug 24 '06 #2
Thank you, oh bearer of bad news. :-(

But seriously... thank you.

Willy Denoyette [MVP] wrote:
V2 uses WMI to collect performance information from the remote perfmon
(through the remote registry), that means that the impersonated user
(remote) must be a member of the (remote)adminis trators alias, only
administrators are allowed to read perf data.

Willy.
Aug 24 '06 #3
I would never use the PerformanceCoun ter class to access remote systems when
not running in a domain realm, much better is to use System.Manageme nt
clases (WMI wrappers) to access management objects like performance
counters. Note that even in this case you need to enable remote access to
the WMI service namespace.
Willy.
"Geoff McElhanon" <gm********@yah oo.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
| Thank you, oh bearer of bad news. :-(
|
| But seriously... thank you.
|
| Willy Denoyette [MVP] wrote:
| V2 uses WMI to collect performance information from the remote perfmon
| (through the remote registry), that means that the impersonated user
| (remote) must be a member of the (remote)adminis trators alias, only
| administrators are allowed to read perf data.
| >
| Willy.
| >
|
Aug 25 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6831
by: Sam | last post by:
I have a desktop VB.Net application I developed locally. I uploaded it to a file server we have and the .Net Framework is installed on the file server. When I try to run the executable from the network drive, I get, "System.Security.SecurityException." When I Open the solution from the network drive, I get, "The project location is not fully trusted by the .Net runtime. And then when I click ok and try to run in debug mode I get...
1
3303
by: W1ld0ne74 | last post by:
I am implimenting Performance counters into a web application. I use the following code to create the counters during setup: private void SetupPerfCntrs() { System.Diagnostics.CounterCreationDataCollection CounterDatas = null; System.Diagnostics.CounterCreationData cdCounter4 = null; try { if(System.Diagnostics.PerformanceCounterCategory.Exists("LogisOnline"))
1
4227
by: jimbo | last post by:
Here is my problem. I'm creating an Instrumentation class that will use previously created Performance Categories and Counters in order to time various processes (ie. query duration etc.). This Instrumentation class will be used by a variety of "services", so the Categories and Counters to be used within the object must be set during object construction. So I created a class variable array of: private static PerformanceCounter...
2
4226
by: jwgoerlich | last post by:
I wrote a simple VB.Net console application. It accepts command line parameters and creates a folder structure. It works on the local file system without a problem If I run the console app from a UNC or network share, I get a SecurityException on the following line: Dim args() As String = Environment.GetCommandLineArgs() Has anyone seen this before? Is there something special I need to do
3
2883
by: Rob Meade | last post by:
Hi all, I'm having a bit of trouble with the following function.... Private Function GetSystemUpTime() As TimeSpan ' declare variables Dim Result As TimeSpan Dim PerformanceCounter As PerformanceCounter
0
1153
by: gmcelhanon | last post by:
I have some code that attempts to read a performance counter on a remote machine. Under .NET 1.1 the code works just fine, but under ..NET 2.0 I get a SecurityException with a description of "Requested registry access is not allowed". Everything about the code and target machines is the same, with the only difference being that I'm running the code under a brand new installation of VS.NET 2005. As for security, I am a member of an AD...
4
2034
by: =?Utf-8?B?c2FtMDFt?= | last post by:
Not that I've ever gotten any reponse to questions in the past, but I don't know where else to turn. I have a remoting application (.NET 2.0, VS 2005, C#) with a custom ChannelSinkProvider as described in this article http://msdn2.microsoft.com/en-us/library/ms973909.aspx This example uses role-based security by way of decorating each method with or some other programmer defined role.
11
5432
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Has anybody worked with performancecounter object to access counters on remote machine? I managed to write code that retrieves counters categories froma remote machine, when I try another remote machine I get "System.ComponentModel.Win32Exception" error. Error message is "The network path was not found." I have checked running services (RPC, Remote registery.....) on both machines and they are exactly the same. I am wondering if there is...
5
8329
by: Henry Stock | last post by:
I am trying to understand the following error: Any thing you can tell me about this is appreciated. Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. Exception Details: for the permission of type
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9116
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.