473,569 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Read registry keys of type REG_MULTI_SZ into C# arrays

Bo
I am using RegistryKey.Get Value() method to retrieve values from
Windows Registry. I don't know how to read type REG_MULTI_SZ into a
string array. I have tried
string[] array = (string[]) RKey.GetValue(n ame);
But it gave me "Invalid Cast Exception".

Please provide C# sample code in your reply.

Thank you.
Nov 15 '05 #1
3 17720
Excerpt from MSDN:

Note When setting a value, the way in which the value being passed is
stored in the registry is interpreted. There is no way to control whether
the information being passed is stored as an sz, or an expanded_sz string,
and therefore, all string values are interpreted as standard sz values.
I guess if you extend this to read, you'll be able to read MULTI_SZ strings
as one string... although you should try a sample app to make sure.

-vJ
"Bo" <bo*****@yahoo. com> wrote in message
news:a7******** *************** ***@posting.goo gle.com...
I am using RegistryKey.Get Value() method to retrieve values from
Windows Registry. I don't know how to read type REG_MULTI_SZ into a
string array. I have tried
string[] array = (string[]) RKey.GetValue(n ame);
But it gave me "Invalid Cast Exception".

Please provide C# sample code in your reply.

Thank you.

Nov 15 '05 #2

Hi Bo,

It should work, I do like this:
private void button1_Click(o bject sender, System.EventArg s e)
{
string[] before = new string[] {"Hello", "World"};
string[] after;
RegistryKey key = Registry.Curren tUser.CreateSub Key(@"Software\ GetValue");
key.SetValue("T est", before);
after = (string[])key.GetValue(" Test");
foreach(string str in after)
{
MessageBox.Show (str);
}
key.Close();
}

And it works well.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
Bo wrote:
I am using RegistryKey.Get Value() method to retrieve values from
Windows Registry. I don't know how to read type REG_MULTI_SZ into a
string array. I have tried
string[] array = (string[]) RKey.GetValue(n ame);
But it gave me "Invalid Cast Exception".


Something else is wrong - it works fine for me. I suspect that the value
being read by RKey.GetValue(n ame) is not really REG_MULTI_SZ.

I'll even post a complete example:

using System;
using Microsoft.Win32 ;

namespace MultiSZTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string [] vals = (string [])
Registry.Curren tUser.GetValue( "test");
}
}
}

Note that I created a REG_MULTI_SZ registry value named "test" under
HKCU using RegEdit. Note that my test worked even if the value had no
data in it or just one string.

I also got no exception if the value "test" did not exist at all. In
that case, the vals array was null.

I did get the InvalidCastExce ption (as expected) if "test" had a type of
REG_SZ.

Now you get to post a complete example that fails.

--
mikeb
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1970
by: Pat Blair | last post by:
Sorry to anyone who read this post, but in case it's useful to anyone: Further experiments reveal that while a tuple comes back if you read a multi-line string, you set the value using a list (not a tuple). That's sensible and I don't know why this didn't occur to me before I posted. Thanks -----Original Message----- From: Pat Blair
1
1661
by: Jim Moon | last post by:
I'm setting up a Win Server 2003 for remote debugging. From this page, I see that I need to set two registry keys on the server: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vctskinstallingremotedebugmonitor.asp This key already exists: with: Name: (Default) Type: REG_SZ
1
3778
by: Borka | last post by:
Hi all! I have some questions. 1. I write script which controls registry settings, which must work on every computer. If I try JFSO = new ActiveXObject("Scripting.FileSystemObject"); JWS = new ActiveXObject("WScript.Shell"); key = JWS.RegRead("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\\").toL
0
7683
by: DJP | last post by:
Hi there I need to be able to programmatically set permissions on registry keys using VB / VBScript / VBA. So far I have had a look at doing this using the WScript.Shell object, API calls, and WMI but the only one of these that goes any where near registry permissions is WMI and that is only to get the permissions of a key (cannot set). I...
0
372
by: sdb1031 | last post by:
Hi, I am trying to learn how to write, change and delete registry keys and values of a remote computer via Python's _winreg module. So far, I've been able to programmatically create a value and read the value. However, I am unable to figure out how to delete the value. Using the following code, I get the following output: MyNewKey...
2
1704
by: jphelan | last post by:
I was testing the install and uninstall, on my WindowsXP Pro SP2 machine, of software that I created, called, "inbusiness". Because of the following error message that I received on attempting to uninstall the program through, "Add/Remove", I assume that I will have to find some other way to remove it. "An installation package for the...
5
6962
by: Sin Jeong-hun | last post by:
I need to read some registry keys of a remote computer. The key will be any key users provide. (For example : HKEY_CURRENT_USER\SOFTWARE \MyGame) I found that there was a handy method called RegistryKey.OpenRemoteBaseKey(); I tried But everytime I execute it, an UnauthorizedAccessException occurred at the OpenRemoteBaseKey method. Both...
0
4619
by: Gary | last post by:
I'm having trouble entering Additional Registry Keys into my Package Solution that will deploy the Access 2007 runtime. (Client machine is running XP with Office 2007 Standard.) The Package Solution Wizard, on about page 3, has a section for entering Additional Registry Keys. I want to include a locations key that will identify my install...
0
876
by: PRR | last post by:
i want to add/modify HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\SysmonLog\Log Queries i might warn u guys .. i practically ..dunno much abt registry .. I want to define my own performance ALERTS ... i m aware of Performance Counters.. class in .net.. also WMI...They dont help me here.. as i want to know when processor usage...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.