|
We use SSRS for our server based reporting, Telerik will only be used for reports embedded into the application, there is no integrated viewer for any other reporting system in SilverLight.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm looking for direction on how to do this. I've looked at RegistryMonitor, but I'm having a hard time following how the code works.
I was expecting it to be like a normal event where I could use e.cancel and stop it if needed, but it appears that .net doesn't have that for the registry.
This code example monitors changes on "SYSTEM\CurrentControlSet\Control\Test" in HKLM, but how can I catch it and stop the change from completing?
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
public class RegistryTester
{
const int INFINITE = -1;
const int WAIT_OBJECT_0 = 0;
const long HKEY_LOCAL_MACHINE = 0x80000002L;
const long REG_NOTIFY_CHANGE_LAST_SET = 0x00000004L;
[DllImport("advapi32.dll", EntryPoint = "RegNotifyChangeKeyValue")]
static extern long RegNotifyChangeKeyValue(IntPtr key,
bool watchSubTree, int notifyFilter, IntPtr regEvent, bool
async);
[DllImport("advapi32.dll", EntryPoint = "RegOpenKey")]
static extern IntPtr RegOpenKey(IntPtr key, String subKey,
out IntPtr resultSubKey);
[DllImport("kernel32.dll", EntryPoint = "CreateEvent")]
static extern IntPtr CreateEvent(IntPtr eventAttributes,
bool manualReset, bool initialState, String name);
[DllImport("kernel32.dll", EntryPoint = "WaitForMultipleObjects")]
static extern unsafe int WaitForMultipleObjects(int numHandles,
IntPtr* handleArrays, bool waitAll, int timeOut);
[DllImport("kernel32.dll", EntryPoint = "CloseHandle")]
static extern IntPtr CloseHandle(IntPtr handle);
public unsafe static void Main(String[] args)
{
args = new string[] { "1", @"SYSTEM\CurrentControlSet\Control\Test" };
int ret = 0;
if (args.Length < 2)
{
Console.WriteLine("Usage: RegistryTester NUMKEYS KEY1 KEY2...");
return;
}
int numKeys = 0;
try
{
numKeys = int.Parse(args[0]);
}
catch (Exception)
{
Console.WriteLine("Invalid argument for NUMKEYS");
return;
}
if (numKeys != args.Length - 1)
{
Console.WriteLine("Did not provide correct number of key arguments.");
return;
}
String[] keys = new String[numKeys];
for (int i = 0; i < numKeys; i++)
{
keys[i] = args[i + 1];
}
IntPtr[] eventHandles = new IntPtr[numKeys];
for (int i = 0; i < numKeys; i++)
{
eventHandles[i] = CreateEvent((IntPtr)null, false, false,
null);
IntPtr myKey;
unchecked
{
RegOpenKey(new IntPtr((int)HKEY_LOCAL_MACHINE),
keys[i], out myKey);
}
RegNotifyChangeKeyValue(myKey, true,
(int)REG_NOTIFY_CHANGE_LAST_SET, eventHandles[i],
true);
}
Console.WriteLine("Waiting on " + numKeys + " keys.");
fixed (IntPtr* handlePtr = eventHandles)
{
ret = WaitForMultipleObjects(numKeys, handlePtr, false,
INFINITE);
}
Console.WriteLine(keys[ret - WAIT_OBJECT_0] + " was changed.");
Console.ReadLine();
}
}
}
|
|
|
|
|
The short answer is you can't stop it from happening. If the user has the permissions to make the change, then the change will be made.
Having said that, the long answer is it's possible, depending on your requirements.
You could just change the permissions on the key for user in question. But, since it looks like you're trying to block something under KEY_LOCAL_MACHINE, the user will already have admin permissions and can just remove your permissions block and grant him/herself permissions to it again.
The other method is to intercept the API calls for registry access. You would need a library, called Detours, to do this. This library is not cheap if you want 64-bit support! This method is also NOT TRIVIAL! It's extremely complicated to do.
You would have to examine the caller to see what code is making the call to change the registry. You can't just stop all registry access because you'd be stopping the system from modifying critical values in the registry. You have to example not only where the call is being made from but who is running the code making the call! After all, what good is blocking the change from your app code if the user can just open RegEdit and make the change manually?!
|
|
|
|
|
Hi Dave, thanks for the reply.
I read an overview on Detours and an open source counterpart, Easy Hook. Do you have any experience with either? From your phraseology, this may be above my programming experience, but I like a challenge so I would like to give one a try.
|
|
|
|
|
Haven't used either. I've never had a reason to.
|
|
|
|
|
Hooking API's is not something trivial, and it is not meant as a generic extension point for plugin writers;
turbosupramk3 wrote: but I like a challenge so I would like to give one a try. It's something that probably requires multiple tries. Be sure to work from a VM, you don't want to kill your boot-environment.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
What about the approach to monitor the key and coerce your value if it gets changed by immediately resetting it?
modified 3-Aug-13 15:51pm.
|
|
|
|
|
Thanks for the reply, this is a good idea.
Although this would be easier in the short term, I would also like to do this with folder access and file access in the long term and a liaison application would be much better.
|
|
|
|
|
I have a table named login
I am binded login table with rdlc report in a table whose showing username and password from login table into report
but now m wanna tht in my rdlc report table show initially 10 rows thn as data comes from login table it just inerted automatically
but as the number of rows are more thn 10 thn the other rows will be displayed on the next page in the same manner.
can anyone help me with it???
|
|
|
|
|
Set the page height to only display 10 records.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ka ka ka ka ka
Yes.......
|
|
|
|
|
The System.Timers.Timer is too slow in my application. Can you guys please give me a hint?
I wrote this short Code to test the timer.
At first I create a timer:
private void button2_Click(object sender, EventArgs e)
{
System.Timers.Timer Timer;
Timer = new System.Timers.Timer();
Timer.Interval = 20;
Timer.Enabled = true;
Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
}
Afterwards I simple dispolay the elapsed time in a label, so that I can compare theese result with a stop watch:
private void OnTimedEvent(object source, ElapsedEventArgs e)
{
Invoke(new MethodInvoker(delegate
{
label1.Text = (Convert.ToInt32(label3.Text) + 20).ToString();
}));
}
|
|
|
|
|
Why not just use the Stopwatch class instead? As you currently have this implementation, you aren't actually displaying the elapsed time - you're just displaying an arbitrary value (oh, and if you use Debug.WriteLine in the OnTimedEvent, you can track the elapsed in the output window without having to marshall across to the UI thread.
|
|
|
|
|
Thanks for the tipp. I have a continuos signal and need to take measurements every 20ms. Can you give me a codeexample, how to use stopwatch in this case? Actually I think I need a thread that constantly tests if my stopwatch elapsed time is divisible by 20ms?
|
|
|
|
|
Hi,
Measure it manually and checking everytime for elapsed time never good option. timer is for that purpose. you are calling method every 20ms it means your code is executed 50 times per second. Please elaborate your actual problem. Why you need to execute function after 20ms ?
Thanks
-Amit Gajjar
|
|
|
|
|
Quote: Why you need to execute function after 20ms ?
As i said, I have contious time signal (by Leap Motion) and I want to sample it with 50 Hz, or at least 40 Hz.
|
|
|
|
|
|
Windows is not a real-time OS. 20 ms means that the event will be triggered "somewhere" after 20 ms passed, not "exactly" after 20 ms.
Don't, unless you're sure.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Member 9940073 wrote: The System.Timers.Timer is too slow in my application.
That's beautifully vague but I'll assume that you are wondering why the real timer interval is fairly consistent but is is not 20ms.
The timer does not have a millisecond resolution and although the programmer may set different values e.g. 17, 18, 19 or 20 ms the actual interval obtained may not vary. On most systems the resolution of the timer is 15.625 ms which means that the real timer intervals can only be multiples of 15.625ms, i.e. 15.625, 31.25, 46.875 etc. So when you set 20ms, what you actually get is rounded up to the next possible real interval, i.e. 31.25ms.
As Eddy said in his reply the operating system is not real time and the timer event may be delayed slightly beyond the rounded up interval.
Alan.
|
|
|
|
|
Precision - I like that! I knew that the resolution was around 16ms on most systems but now I know its 15.625ms.
Timers have been rubbish for ages, but I think I recall being surprised that the one on my PC is actually considerably more accurate than that. But, as you say when dealing in the ms range I'd have thought that waiting for a context switch could certainly bump things into the next ms or so.
Regards,
Rob Philpott.
|
|
|
|
|
For most purposes, the advice that (always reliable) Pete O'Hanlon gave you, to use an instance of System.Diagnostics.Stopwatch: is what you need.
But, given your requirements, you may also want to examine this April 13, CodeProject article: "Microsecond and Millisecond C# Timer," by Ken Loveday: [^].
And, possibly other resources on high-precision .NET timing at: [^].
However, I do not know if any of the techniques above can meet your requirements: I have never needed higher-precision timing than that provided by 'Stopwatch.
When you use the 'Stopwatch class, I hope you don't make the same stupid mistake I made recently [^], and use Stopwatch.Elapsed.Milliseconds, thinking that gets the total time, instead of Stopwatch.TotalElapsedMilliseconds, as was kindly pointed out to me by Alan N. here on this forum: [^].
good luck, Bill
~
“This isn't right; this isn't even wrong." Wolfgang Pauli, commenting on a physics paper submitted for a journal
modified 30-Jul-13 12:16pm.
|
|
|
|
|
I have successfully used (via P/Invoke wrappers I wrote) both the MultimediaTimer [now depreciated but has been available on every system I have ever tested] and TimerQueueTimer with greater precision than you are requiring.
I can dig the code out if you would like it, but it didn't take me too long to knock it up from scratch as I remember.
They are not recommended for general purpose timers however and it is very rare that level of precision is required!
|
|
|
|
|
If you 'need' to do this rather than 'want' to do it then I suspect you might be forced to write a OS driver. Doing that should give you complete control to collect the data at the interval you want.
The driver would do nothing but the following
- Collect the data at the required interval
- Put the data in a buffer
- Provide a method callable from an external app that returns the current buffer.
Then your application can ask the driver for the data and do whatever you want with it.
If you just 'want' to do it then some of the other suggestions will probably require sufficient functionality to get the data most of the time.
|
|
|
|
|
I am Making Dashbord in .net C#. I want to open some module whis is made in VB6. when i add module dll in Dashbord open form but grid not display
|
|
|
|
|
Please give some more detail. We cannot see your screen so it is impossible to guess what your problem may be.
Use the best guess
|
|
|
|