kdunnett
asked on
Console app and microsoft.win32
All,
I have a simple console application done in c#, built in vs.net 2003. I have included microsoft.win32 as i'm hitting the registry. I can run the app locally, but when I run it on a basic pc, it wont' work. If I comment out the Microsoft.win32 and the reg calls, it works fine.
Any ideas how to solve.
Thanks in advance,
Kris
I have a simple console application done in c#, built in vs.net 2003. I have included microsoft.win32 as i'm hitting the registry. I can run the app locally, but when I run it on a basic pc, it wont' work. If I comment out the Microsoft.win32 and the reg calls, it works fine.
Any ideas how to solve.
Thanks in advance,
Kris
What happens when you try to run it ? Does it throw any exceptions ?
> I can run the app locally, but when I run it on a basic pc...
Is the "basic pc" accessing the application from the network? If so, can you try copying the application to the (C:) drive of the basic pc, and try again?
Is the "basic pc" accessing the application from the network? If so, can you try copying the application to the (C:) drive of the basic pc, and try again?
ASKER
Window pops up:
common language runtime debugging services
application has generated an exception that could not be handled.
process id = 0x6f4(1780), thread id=0x400(1024)
On the command line:
Unhandled Exception: System.NullReferenceExcept ion: Object reference not set to
an instance of an object.
at Application.class1.Main(St ring[] args)
common language runtime debugging services
application has generated an exception that could not be handled.
process id = 0x6f4(1780), thread id=0x400(1024)
On the command line:
Unhandled Exception: System.NullReferenceExcept
an instance of an object.
at Application.class1.Main(St
ASKER
The app is running locally on the test pc.
What operating systems are the two PCs running?
ASKER
win 2000 on the test pc. win xp on the development machine (the that works).
But I just tried the exe on another test pc with win xp, and that didn't work.
But I just tried the exe on another test pc with win xp, and that didn't work.
Can you verify that your Registry calls would actually successful on another machine (i.e. check the registry on the test machine to make sure the keys you are looking up actually exist, or if you are making modifications then make sure you have the appropriate permissions)?
If you are still stuck, a post with some more code from your Main method would be helpful.
If you are still stuck, a post with some more code from your Main method would be helpful.
ASKER
I'm thinking that it has something to do with .net framework and how on the test pc's its quite limited.
Is there a dll out there that contains the same methods and such thats in the microsoft.win32 namespace?
Is there a dll out there that contains the same methods and such thats in the microsoft.win32 namespace?
It may be a permissions issue that your code doesn't currently handle rather than there being something missing. Are you running the app under an Administrator account on all the machines ?
ASKER
I"m logging in as the admin on the test pc's... so permissions are valid.
yes, registry folder exists.
Here's the whole section that doesn't work... you should be able to compile with no issues. Just confirm you have the path first. and just does a read, no modification at all.
__________________________ ______
using System;
using Microsoft.Win32;
namespace LDAPEditRegistry
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
RegistryKey CurrentUser = Registry.CurrentUser;
CurrentUser = CurrentUser.OpenSubKey("So ftware\\Mi crosoft\\W indows Nt\\CurrentVersion\\Window s Messaging Subsystem\\Profiles\\Outlo ok",false) ;
foreach(string KeyName in CurrentUser.GetSubKeyNames ())
{
Console.WriteLine(KeyName) ;
RegistryKey OurKey = Registry.CurrentUser;
OurKey = OurKey.OpenSubKey("Softwar e\\Microso ft\\Window s Nt\\CurrentVersion\\Window s Messaging Subsystem\\Profiles\\Outlo ok\\"+ KeyName,false);
foreach(string valuename in OurKey.GetValueNames())
{
if(valuename == "001e6608")
{
Console.WriteLine("\t\tVal ueName: "+ OurKey.GetValue(valuename) .ToString( ));
if(OurKey.GetValue(valuena me).ToStri ng() == "100")
{
Console.WriteLine("\t\tFOU ND THE '100' VALUE");
}
}
}
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
}
}
}
}
yes, registry folder exists.
Here's the whole section that doesn't work... you should be able to compile with no issues. Just confirm you have the path first. and just does a read, no modification at all.
__________________________
using System;
using Microsoft.Win32;
namespace LDAPEditRegistry
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
RegistryKey CurrentUser = Registry.CurrentUser;
CurrentUser = CurrentUser.OpenSubKey("So
foreach(string KeyName in CurrentUser.GetSubKeyNames
{
Console.WriteLine(KeyName)
RegistryKey OurKey = Registry.CurrentUser;
OurKey = OurKey.OpenSubKey("Softwar
foreach(string valuename in OurKey.GetValueNames())
{
if(valuename == "001e6608")
{
Console.WriteLine("\t\tVal
if(OurKey.GetValue(valuena
{
Console.WriteLine("\t\tFOU
}
}
}
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note that, you will also need to check that OurKey is not null before proceeding to call OurKey.GetValueNames.
ASKER
Expert1701,
Thanks. I found out that the path in the registry (depending on computer) changes for the last entry in the path.
I just wasn't looking far enough down in the tree.
Thanks for your help!
Kris
Thanks. I found out that the path in the registry (depending on computer) changes for the last entry in the path.
I just wasn't looking far enough down in the tree.
Thanks for your help!
Kris