|
I am trying to create a program that reads the registry key for disabled start up programs and the issue i am having is that while i can read it in regedit, my program says that it is a null object.
string Path = @"SOFTWARE\Microsoft\Shared Tools\MSConfig\startupreg";
RegistryKey Run = Registry.LocalMachine;
Run = Run.OpenSubKey(Path, true);
string[] SubKeys = Run.GetSubKeyNames();
Can someone please point me in the right direction for the right permissions cuz I am getting confused with all the different ways to do the permissions. I have followed the microsoft site for it, but it still doesnt seem to help.
Thanks
|
|
|
|
|
How do you know it's a permission issue? I don't see a try/catch block around your code. Are you running this under the debugger to see what the exception is that's being thrown? My guess is that you're not.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
There is a try catch, i didnt post the whole code cuz i didnt think it was important. the exception is null object reference. But i dont get why i could see it in the registry and copy the reg key, but not be able to access it in my program.
Here is the part of code:
try
{
string Path = @"SOFTWARE\Microsoft\Shared Tools\MSConfig\startupreg";
RegistryKey Run = Registry.LocalMachine;
Run = Run.OpenSubKey(Path, true);
string[] SubKeys = Run.GetSubKeyNames();
foreach (string SubKeys1 in SubKeys)
{
richTextBox1.Text += SubKeys1 + "/n";
}
}
catch (Exception ex)
{
richTextBox1.Text = ex.ToString();
}
Here is the exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at RegTest.MainForm.RegTest() in f:\Programming\SharpDevelop\SharpDevelop Projects\RegTest\RegTest\MainForm.cs:line 41
modified on Monday, August 29, 2011 12:35 PM
|
|
|
|
|
If you had a problem with insufficient permissions then OpenSubKey should throw an exception saying so, I'm not even sure if you need write permission from the code you've posted but it doesn't matter.
So far as I can tell, the key your trying to open doesn't exist. When OpenSubKey can't find what you're looking for it returns null so it's something you should check for.
After a little digging, is seems that the key your after may not actually exist. If your running Vista/Win7 64-bit then I'm going to assume you can see the key you want to open. But if your building a 32-bit application the key your actually trying to open is HKLM\SOFTWARE\Wow6432Node\Microsoft\Shared Tools\MSConfig\startupreg , which if you go and look you'll find doesn't exist.
|
|
|
|
|
Make sure have sufficient privileges to read the registry,
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Here is my new code:
try
{
string Path;
RegistryKey Run;
try
{
Path = @"SOFTWARE\Wow6432Node\Microsoft\Shared Tools\MSConfig";
Run = Registry.LocalMachine;
Run = Run.OpenSubKey(Path, true);
}
catch (Exception ex)
{
richTextBox1.Text = "Coulndt not find either Wow6432Node: \n" + ex.ToString();
}
Path = @"SOFTWARE\Microsoft\Shared Tools\MSConfig";
Run = Registry.LocalMachine;
Run = Run.OpenSubKey(Path, true);
string[] SubKeys = Run.GetSubKeyNames();
foreach (string SubKeys1 in SubKeys)
{
richTextBox1.Text += SubKeys1 + "\n";
}
}
catch (Exception ex)
{
richTextBox1.Text = "Coulndt not find either MSConfig: \n" + ex.ToString();
}
I am working on a 64bit system, and I do have the registry open to
SOFTWARE\Microsoft\Shared Tools\MSConfig\startupreg and I see keys in there.
I had to create a key for "SOFTWARE\Wow6432Node\Microsoft\Shared Tools\MSConfig\startupreg" and the program does work when i did that, but it doesnt store the keys i want in there. So i am having a heck of a time getting it to read the keys in the 32bit system
|
|
|
|
|
What information are you actually trying to get? Are you sure there's isn't an alternate way to get it?
|
|
|
|
|
I am trying to get the disabled startup programs. And if need be, write to it.
|
|
|
|
|
Well, I've come up with two solutions. The aim is to get access to the 64bit registry from a 32bit application (you'll have to check to make sure your running on x64 before trying to open the 64 bit version of the registry).
This Webpage[^] gives a few examples on how to do that. If you are already using (or are able to switch to) .Net 4 then its as simple as calling RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); otherwise your going to have to use the standard windows API because earlier versions of the framework don't support this functionality.
Once you make sure your working in the actual registry (rather than the 32bit mirror if your running on x64) you should be able to carry on as normal. Also I was checking this in a Virtual Machine and the MSConfig wasn't initially there because it had never been run, and I'd never disabled any startup applications so don't assume it will always be there.
|
|
|
|
|
Thanks you! it works like a dream now. I didnt think about accessing the registry as a 32 bit or 64 bit.
|
|
|
|
|
Hi,
I need to do a button which has same functionality as PTT (Press to Talk).
So, you press and keep the button pressed - it does some function.
On release of the button, do something else.
while (button.pressed)
do something
on release
do something
ps. I found this code in a Forum, but it is not working. Nothing happens on pressing the button.
///////////////////////////////////
isLooping = false;
//on mouse down
private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
isLooping = true;
runLoop();
}
//on mouse up event
private void myControl_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) {
isLooping = false;
}
//This is the main loop you care about. Put this in your application
//This should go in its own thread
void runLoop() {
while (isLooping) {
//do stuff
}
}
|
|
|
|
|
asterix5 wrote: Nothing happens on pressing the button.
Because there is no code inside runLoop() method. Put your code inside the while loop.
|
|
|
|
|
Inside the loop, of course is something that I run. I use it to send Skype commands to turn off/on the microphone.
As I was looking, I tried to simplify it, so just dealing simply with the MouseDown and MouseUp events turning OFF/ON the mic.
Here below is the code, but still is not working - what should I execute on the Button Click itself?
_____________________________________________________________
private void button2_Click_1(object sender, EventArgs e)
{
}
public void OnMouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
Skype.Attach(6, true);
SKYPE4COMLib.Command command1 = new SKYPE4COMLib.Command();
command1.Command = "SET MUTE OFF";
command1.Blocking = false;
command1.Id = 1000;
Skype.SendCommand(command1);
}
//on mouse up event
private void OnMouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Skype.Attach(6, true);
SKYPE4COMLib.Command command1 = new SKYPE4COMLib.Command();
command1.Command = "SET MUTE ON";
command1.Blocking = false;
command1.Id = 1000;
Skype.SendCommand(command1);
}
|
|
|
|
|
If I were you, I would log the events and actually see if they're executed or not.
Alternatively, the solution proposed by Wayne Gaylard is excellent. You may want to try that.
|
|
|
|
|
I would use a BackGroundWorker to handle the work while the button is pressed. I created a test app that adds the letter a to a textbox every second while the button is pressed, and stops when button is lifted. Here is the code for the form (assumes the form contains a button(button1) and a textbox(textBox1, with multiline set to true)). I am sure you can convert this to do what you require:
bool isPressed = false;
BackgroundWorker bgw = new BackgroundWorker();
public Form1()
{
InitializeComponent();
button1.MouseDown += new MouseEventHandler(button1_MouseDown);
button1.MouseUp += new MouseEventHandler(button1_MouseUp);
bgw.DoWork+=new DoWorkEventHandler(bgw_DoWork);
bgw.WorkerSupportsCancellation = true;
}
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
while (isPressed)
{
DoWork();
Thread.Sleep(1000);
}
}
void button1_MouseUp(object sender, MouseEventArgs e)
{
bgw.CancelAsync();
isPressed = false;
}
void button1_MouseDown(object sender, MouseEventArgs e)
{
isPressed = true;
bgw.RunWorkerAsync();
}
delegate void doWork();
void DoWork()
{
if (this.InvokeRequired)
{
doWork d = new doWork(DoWork);
this.Invoke(d);
}
else
{
this.textBox1.Text += "a";
}
}
Hope this helps
Live for today. Plan for tomorrow. Party tonight!
|
|
|
|
|
EDIT: I have it solved, have found a similar library as that mine and there it is implemented in Java, so I just looked for a way to do it. It is needed to use tile-overlapping, so I modified my code and now it's working...
This is that page: http://www.jhlabs.com/[^]
Original message:
Hi all, does anybody know some good source to learn apply a fast convolution filter to image? I am looking for kernels with 20x20 an bigger and need to process image fast, so I need to learn how to do that using FFT or DFT.
I like to use GDI+ in C#.
Any suggestion?
Thanks in idvance...
modified on Tuesday, August 30, 2011 4:23 AM
|
|
|
|
|
Have you seen how does Matlab Function fft work?
Source Code available and may be useful...
Regards,
D
|
|
|
|
|
I have not so far, but I'll give it a try... But still, I would prefer any working example programmed in some .Net language or in native C / C++.
Thanks...
|
|
|
|
|
I'm not sure here, but isn't it more typical to either convolve with a kernel in 'normal' (image) space?
A convolution is rather easy to program, so I'm guessing you could readily program a fast implementation yourself.
Just know that C# (and any .NET language for that matter) isn't known for its speed. If you really want the most out of your program, you could try at C++ or another machine-compiled language.
|
|
|
|
|
I am using native C++ to rewrite working stuff, but for testing I use C#. With GDI+ it is nice that BitmapData is same structure in .Net and native GDI+, so it is easy to migrate working code from C# to native C++.
Simple convolution is what I have done already, but it is too slow (even wrote in C++) compared to PhotoShop plugins, so I am searching for FFT transform of tiles...
Thanks...
|
|
|
|
|
|
Well, Andrew Kirillov has in his library FFT filter, but in convolution filters he does not use them and I need exactly that. Also Christion has made good stuff for beginners, but my question is little more about advanced image processing than about beginner tutorial.
|
|
|
|
|
|
Yes, for most part are, but exactly that part, where they are not is in my interest. What I need is to understand how to forward transform image and mask, multiply them together and transform result back to 'normal' image. I have made some algorithms, but on borders of tiles I have some errors, so I am interested in any code to look for inspiration...
modified on Monday, August 29, 2011 3:29 PM
|
|
|
|
|
if your kernels are separable, you can do the operation as a pair of 1-D convolutions (once in X, once in Y). that will change your complexity from N^2 to N.
|
|
|
|