|
-
August 9th, 2008, 11:15 PM
#1
Registry Keys
Well I'm trying to create a registry reader and this is what I have so far:
Code:
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Nod\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907");
if (regkey.GetValue("CompanyName") != null)
{
string showIt = regkey.GetValue("CompanyName").ToString();
MessageBox.Show(showIt);
}
that however doesn't do anything, I'm just trying to read the company name form VMware Workstation, can anyone explain to me why my code doesn't work and how can I fix it? Thanks
-
August 10th, 2008, 04:46 AM
#2
Re: Registry Keys
I think it should be
Code:
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907");
Node the 'Wow6432Nod' becomes 'Wow6432Node'.
Check the path of the registry string : if it doesn't exist you won't get any results !
Also you should be doing this to ensure the key is closed when you've finished with it :
Code:
using (RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907"))
{
if (regkey.GetValue("CompanyName") != null)
{
string showIt = regkey.GetValue("CompanyName").ToString();
MessageBox.Show(showIt);
}
}
Darwen.
Last edited by darwen; August 10th, 2008 at 04:51 AM.
-
August 10th, 2008, 12:13 PM
#3
Re: Registry Keys
 Originally Posted by darwen
I think it should be
Code:
RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907");
Node the 'Wow6432Nod' becomes 'Wow6432Node'.
Check the path of the registry string : if it doesn't exist you won't get any results !
Also you should be doing this to ensure the key is closed when you've finished with it :
Code:
using (RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907"))
{
if (regkey.GetValue("CompanyName") != null)
{
string showIt = regkey.GetValue("CompanyName").ToString();
MessageBox.Show(showIt);
}
}
Darwen.
Still doesn't work, the message box never shows
EDIT: ohh one more thing how would I read the defult value in the folder cause on this one im trying to read the "CompanyName" value
Last edited by Korupt; August 10th, 2008 at 12:17 PM.
-
August 10th, 2008, 11:08 PM
#4
-
August 10th, 2008, 11:50 PM
#5
Re: Registry Keys
 Originally Posted by Korupt
Still doesn't work, the message box never shows
EDIT: ohh one more thing how would I read the defult value in the folder cause on this one im trying to read the "CompanyName" value
Are yo stepping into the code in a debugger? If you don't know how to do this, please say so so we can explain how.
In answer to how to get the default value... Just pass in a "" to the GetValue() method.
-
August 11th, 2008, 04:02 PM
#6
Re: Registry Keys
it's cool i figured it out and thanks for the input
-
October 12th, 2010, 05:38 AM
#7
Re: Registry Keys
Also you should be doing this to ensure the key is closed when you've finished with it :
Code:
using (RegistryKey regkey = Registry.CurrentUser.OpenSubKey("Software\\Wow6432Node\\VMware, Inc.\\VMware Workstation\\License.ws.6.0.200907"))
{
if (regkey.GetValue("CompanyName") != null)
{
string showIt = regkey.GetValue("CompanyName").ToString();
MessageBox.Show(showIt);
}
}
Darwen, I developed a class to easily access the Registry, so I store the RegistryKey regkey as a member variable.
I am wondering:
How can I ensure the key is closed when I've finished with it, since I OpenSubKey in my constructor, then I GetValue in other functions (I cannot enclose it in a using case)?
Last edited by MontgomeryBurns; October 12th, 2010 at 05:40 AM.
Mr. Burns
-
October 12th, 2010, 10:05 AM
#8
Re: Registry Keys
 Originally Posted by MontgomeryBurns
Darwen, I developed a class to easily access the Registry, so I store the RegistryKey regkey as a member variable.
I am wondering:
How can I ensure the key is closed when I've finished with it, since I OpenSubKey in my constructor, then I GetValue in other functions (I cannot enclose it in a using case)?
Are you aware that ATL already has a registry class? It's called CRegKey. Just include <atlbase.h> to use it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|