WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Registry
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Retain Percent Signs in SystemRoot Variable

Keywords: 	  Percent Signs  %%

Question:

This has got to be something simple, but it's eluding me. How do I get the value pulled out of the registry to expand/substitute so the last command doesn't fail?

Thanks

ProfilesDir1="%SystemRoot%\Profiles"
ProfilesDir2=RegQueryExpSz(@RegMachine,"Software\Microsoft\Windows
NT\CurrentVersion\ProfileList[ProfilesDirectory]")
If DirExist(ProfilesDir1) Then Message("Status","Dir1 exists")
If DirExist(ProfilesDir2) Then Message("Status","Dir2 exists")
and here's the debug info:
ProfilesDir1="C:\WINNT\Profiles"
(0) VALUE=> "C:\WINNT\Profiles"
ProfilesDir2=RegQueryExpSz(@RegMachine,"Software\Microsoft\Windows
NT\CurrentVersion\ProfileList[ProfilesDirectory]")
(0) VALUE=> "%SystemRoot%\Profiles"
If DirExist(ProfilesDir1) Then Message("Status","Dir1 exists")
(640) ==>TRUE=> 1
If DirExist(ProfilesDir2) Then Message("Status","Dir2 exists")
(640) ==>FALSE=> (skipped) 
The problem is the fact that when I pull data OUT of an ExpSz registry key into a WB variable, that variable then contains a literal string with %SystemRoot% (in this example) in it. When I then try to use that variable, I need it to be resolved to the value of %SystemRoot%.

Answer:

You need to use two percent signs if you want to retain the existing ones in the registry:
value=RegQueryExpSZ(.....
systemroot=Environment("systemroot")
value=StrReplace(value,"%%systemroot%%",systemroot)

Article ID:   W14708
Filename:   Retain Percent Signs in SystemRoot.txt
File Created: 2000:07:20:13:22:56
Last Updated: 2000:07:20:13:22:56