Creating a registry ValueName with a backslash in VB6 / VBScript

I need to write a registry value name that has a '\' in it but this is interpreted as a key. How do I get around this?
EG.
ValueName ="CN=User\, Test1,OU=Users.,OU=Departments,DC=ni,DC=ad,DC=newsint"
oShell.RegWrite "HKCU\Software\App" & ValueName, vbNullString, "REG_SZ"
...creates a new key under "App" called "CN=User", with a value of ", Test1,OU=Users.,OU=Departments,DC=ni,DC=ad,DC=newsint".
There must be an easy way around this! All help appreciated, thanks
NewsInternationalLtdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

WesleySaysHiCommented:
You must "escape" the backslash.
The backslashes in the registry key are escaped by a backslash.
For example: instead of writing "User\" you will write "User\\", the first backslash being used to escape the backslash you are using and which is interpreted as a key.

Wesley
0
sirbountyCommented:
Is this what you're looking for?

oShell.RegWrite "HKCU\Software\App\", ValueName, "REG_SZ"
0
NewsInternationalLtdAuthor Commented:
Both the above solutions seem to have the same outcome, ie the ValueName is ends up as the datavalue. I need it to be the name.
I can understand the theory behind what Wesley is saying regarding the escape character as this is needed in some DS commands but if I change the string with a replace statement so it now reads:
CN=User\\, Test1,OU=Users.,OU=Departments,DC=ni,DC=ad,DC=newsint
...this still ends up as a data value. I I have also tried
HKCU\Software\App\\
which still doesn't work! What am I doing wrong?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

WesleySaysHiCommented:
RegWrite "HKCU\Software\App", "CN=User\\,Test1,OU=Users.,OU=Departments,DC=ni,DC=ad,DC=newsint", "REG_SZ" should work. It's a simple regwrite statement as at: http://psacake.com/web/func/
Check the syntax carefully.

Wesley
0
NewsInternationalLtdAuthor Commented:
This creates the dn as a DataValue under HKCU\Software\App\Default.
0
sirbountyCommented:
So, what is the value name you're trying to assign it to? CN?
0
NewsInternationalLtdAuthor Commented:
I simply want the dn (which obviously includes the backslash) to be the valuename, it doesn't really matter what the value is. As I'm sure you know this is usually accomplished by removing the trailing '\' but I'm really struggling to script this. Atypical value name is below.

"CN=User\, Test,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint", "test", "REG_SZ"
0
sirbountyCommented:
Then this should work...does for me...drop the value at the end - no need to escape the backslash...

oShell.RegWrite "HKCU\Software\App\Test", ValueName, "REG_SZ"
0
NewsInternationalLtdAuthor Commented:
Surely this creates a key called 'App' with a VALUENAME of 'Test' and VALUEDATA of the dn (disName)? This is what happens when I run it. I would like the VALUENAME to be the dn.
For maximum clarity, this is what I'm writing:

set oshell = createobject("Wscript.Shell")
disName = "CN=User\, Test1,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint"
oShell.RegWrite "HKCU\Software\App\Test", disName, "REG_SZ"

0
drbayerCommented:
I haven't tested it, but have you tried

set oshell = createobject("Wscript.Shell")
disName = "CN=User\\, Test1,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint"
oShell.RegWrite "HKCU\Software\App\" & disName, ValueData, "REG_SZ"

0
sirbountyCommented:
Can you show me the full path youre looking for...
This creates it under the Software key...

oshell.regwrite "HKCU\Software\App", disName, "REG_SZ"
0
NewsInternationalLtdAuthor Commented:
Yep, just creates a new key called "CN=User" with a value of " ,Test1,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint".
I know it's stupid and it can be done maually so I can only assume there is a way to do this programmatically. I have just logged a call with Microsoft PSS so I'll let you know how I get on.
0
sirbountyCommented:
Not 'exactly' a fix for the regwrite method, but replace this line...it will work (sets the valuedata to 0, since I'm not sure what you want that set to).

set oshell = createobject("Wscript.Shell")
disName = "CN=User\, Test1,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint"
oShell.Run "reg add HKCU\Software\App /v " & Chr(34) & disName & Chr(34) & " /d 0", 0


0
NewsInternationalLtdAuthor Commented:
Sirbounty:
What you have there actually creates a VALUENAME of App with VALUEDATA of the dn under the Software key. I need it to appear as below in the registry:

Name                                                                                    Type                                       Data
CN=User\, Test1,OU=Users,OU=I.T.,OU=Departments...   REG_SZ                                    Whatever
0
sirbountyCommented:
Alright, I was under the impression that App was already created...

Use this

set oshell = createobject("Wscript.Shell")
disName = "CN=User\, Test1,OU=Users,OU=I.T.,OU=Departments,DC=ni,DC=ad,DC=newsint"
oShell.Run "reg add HKCU\Software\App\ /v " & Chr(34) & disName & Chr(34) & " /d 0", 0
0
NewsInternationalLtdAuthor Commented:
Sorry, our replies are a little out of sync.
SirBounty, your last solution does work exactly as I would like although as you say not an exact fix as such. However it might be enough. I am certainly happy to award you points for this solution though. I shall do this when I find the official one from MS which I will post (if indeed there is one any better).

Thanks a lot for your efforts.
0
sirbountyCommented:
Cool.
What I meant was - it wasn't a 'fix' for the regwrite method.
It's actually using your shell reference to run the command-line reg.exe version (which is a bit more intuitive because you can explicitly decide what you want the value (/v) and data (/d) to be...)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyCommented:
I thought I put in a fair amount of work for you here...I'm a bit surprised by the "B" grade...
0
NewsInternationalLtdAuthor Commented:
I have accepted Sir Bounty's solution as it is simple and it does work. However having spoken to MS PSS about this they tell me it can't be done with the Regwrite method, hence the problems encountered. They did howver provide me with a 'purer' solution to this which I have included here. It's a WMI solution but at least it doesn't rely on a third party utility (of sorts):
Const HKEY_CURRENT_USER = &H80000001
Set objRegistry = GetObject("winmgmts://./root/default:StdRegProv")
sPath = "SOFTWARE\App"
lRC = objRegistry.SetStringValue(HKEY_CURRENT_USER, sPath, "CN=User\, Test3, OU=Users, OU=Departments, DC=ni,DC=ad,DC=newsint", "Test")
0
sirbountyCommented:
Fair enough...glad you got it working.
0
NewsInternationalLtdAuthor Commented:
Sorry, SirB, the only reason for the B was, as I said above, that I was looking for a purer solution. I VERY MUCH appreciate your efforts and you have been extremlely helpful on this, don't get me wrong! I just thought in the interests of what was originally required it wan't an exact solution for what I needed although the end result was the same.
0
sirbountyCommented:
"as I said above, that I was looking for a purer solution."
In truth, it's really 6 vs 1/2 dozen, but now I'm a bit embarrased I didn't suggest the wmi method.  I guess I couldn't see the forest for the trees...
0
NewsInternationalLtdAuthor Commented:
No worries thanks for you help anyway. You always manage to pull out a solution of sorts in the end!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.