Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Console app and microsoft.win32

Posted on 2006-11-09
13
Medium Priority
?
288 Views
Last Modified: 2010-04-16
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



0
Comment
Question by:kdunnett
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17908935
What happens when you try to run it ? Does it throw any exceptions ?
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17908976
> 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?
0
 

Author Comment

by:kdunnett
ID: 17909013
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.NullReferenceException: Object reference not set to
an instance of an object.
   at Application.class1.Main(String[] args)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:kdunnett
ID: 17909021
The app is running locally on the test pc.  
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17909031
What operating systems are the two PCs running?
0
 

Author Comment

by:kdunnett
ID: 17909050
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.

0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17909073
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.
0
 

Author Comment

by:kdunnett
ID: 17909082
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?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17909093
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 ?
0
 

Author Comment

by:kdunnett
ID: 17909111
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("Software\\Microsoft\\Windows Nt\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook",false);
            
                        foreach(string KeyName in CurrentUser.GetSubKeyNames())
                        {
                              Console.WriteLine(KeyName);
                  
                              RegistryKey OurKey = Registry.CurrentUser;
                              OurKey = OurKey.OpenSubKey("Software\\Microsoft\\Windows Nt\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook\\"+ KeyName,false);

                              foreach(string valuename in OurKey.GetValueNames())
                              {
                                    if(valuename == "001e6608")
                                    {
                                          Console.WriteLine("\t\tValueName: "+ OurKey.GetValue(valuename).ToString());

                                          if(OurKey.GetValue(valuename).ToString() == "100")
                                          {
                                                Console.WriteLine("\t\tFOUND THE '100' VALUE");
                                          }
                                    }            
                              }
                        }
                  }
                  catch(Exception ex)
                  {
                        throw ex;
                  }
                  finally
                  {
                  }
            }
      }
}
0
 
LVL 11

Accepted Solution

by:
Expert1701 earned 2000 total points
ID: 17909185
Excellent example, kdunnett; it failed on my system (Windows XP Professional, Office 2003 Professional).

Please try the following adjustment:

  CurrentUser = CurrentUser.OpenSubKey("Software\\Microsoft\\Windows Nt\\CurrentVersion\\Windows Messaging Subsystem\\Profiles\\Outlook", false);

  if (CurrentUser == null)
  {
    Console.WriteLine("Key does not exist!");
  }
  else
    foreach (string KeyName in CurrentUser.GetSubKeyNames())
    ...

Note that if you remove your try...catch block while testing, the exception message should provide more detail.
0
 
LVL 11

Expert Comment

by:Expert1701
ID: 17909404
Note that, you will also need to check that OurKey is not null before proceeding to call OurKey.GetValueNames.
0
 

Author Comment

by:kdunnett
ID: 17909411
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
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question