Solved Help with special characters in batch

Various / CUSTOM BUILT
September 29, 2015 at 07:33:34
Specs: Windows 10, Intel i7 4770k, 16GB 1600MHz RAM
I have a batch file I'm working on, it queries the registry for a value, which contains the path to a file on the computer, then puts iti n a variable.

However my username contains a "Trademark" sign, so I cannot use the path in any further logic in the batch file, as the command prompt translates the sign into some other sign.

I compare the path with "%homedrive%\%homepath%", which contains the trademark sign and displays it correctly, so when I do

if %filePath%==%homedrive%\%homepath%
it will always be false as the trademark sign is not correct.

Is there a way around this?

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


See More: Help with special characters in batch

Report •


✔ Best Answer
October 2, 2015 at 18:35:18
I don't think so (pls pardon my ignorance). That was indeed my first thought, but then (lightbulb) "it's bound to be already in there!" I found relevant content in my registry at:
HKCU\VolatileEnvironment
under "username" and "userprofile" keys.. (Userprofile most closely corresponding to your target path.)
So,
reg compare registry-path-to-file HKCU\VolatileEnvironment\userprofile &&goto :OK||goto :FAIL

Something like that...



#1
September 29, 2015 at 09:21:53
Without knowing how you're getting this value, I'll say what you're attempting would be easier inVBScript or PowerShell if that Win10 spec is accurate.

How To Ask Questions The Smart Way


Report •

#2
September 29, 2015 at 10:28:42
for /f "skip=2 tokens=3,*" %%B in ('reg query "HKCU\Software\App\Data" /ve') do set filePath=%%B

That's how I'm getting the value, and yes the Win10 spec is accurate, however I'd like to stay with batch if possible.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

#3
September 30, 2015 at 10:07:12
Well, you have a problem with your code pages, and a language like Batch probably isn't suited to your problem.

You could try a different app, like WMIC, to see if its return value is any better.

WMIC /NameSpace:\\root\default Class StdRegProv Call GetStringValue hDefKey="&H80000001" sSubKeyName="Software\App\Data" sValueName="" | findstr "sValue"

Note: Untested. I haven't bothered to see if the WMI provider fixes Unicode -> ASCII issues.

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

Related Solutions

#4
September 30, 2015 at 14:29:39
Idunno what to make of this output

Executing (StdRegProv)->GetStringValue()

Method execution successful.

Out Parameters:
instance of __PARAMETERS
{
	ReturnValue = 6;
};

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

#5
September 30, 2015 at 15:41:26
ERROR_INVALID_HANDLE. I'd have to see the line you're using

How To Ask Questions The Smart Way


Report •

#6
September 30, 2015 at 16:42:55
wmic /namespace:\\root\default Class StdRegProv Call GetStringValue hDefKey="&H8000000" sSubKeyName="VLC.mp3\shell\Add\command" sValueName=""

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.


Report •

#7
September 30, 2015 at 17:14:52
Your "hDefKey" is missing a '0'. You should have eight hex digits after the "&H"
hDefKey="&H80000000"

How To Ask Questions The Smart Way


Report •

#8
September 30, 2015 at 18:19:37
Fixed that, doesn't appear to work yet though

Executing (StdRegProv)->GetStringValue()

Method execution successful.

Out Parameters:
instance of __PARAMETERS
{
	ReturnValue = 2;
};

Isn't code 2 "Access Denied"?
Still getting the same error when running as administrator

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

#9
September 30, 2015 at 19:44:58
ERROR_FILE_NOT_FOUND. WMI runs as SYSTEM, so HKCU keys aren't available. Since HKCR is a combination of HKCU\Software\Classes and HKLM\Software\Classes, the key will not be available if it's per-user, which looks to be the case.

How To Ask Questions The Smart Way


Report •

#10
September 30, 2015 at 20:04:18
The value is in a key residing in HKCR, the script will be used by many separate users so I'd have to make it work "per-user", is there still a way to get the value with the WMI or can I use PS like
powershell -command {'stuff'}

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

message edited by RainBawZ


Report •

#11
October 1, 2015 at 08:30:00
You can, but in general I dislike mixing scripting languages like that. You need to remember the limitations of both languages, and how they interact, but yes you could go see if that works. You could also dump the output of REG to a temp file, and try reading that. PowerShell'd look something like this:
powershell "(gp 'Registry::HKCR\VLC.mp3\shell\Add\command').'(default)'"

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#12
October 1, 2015 at 21:47:52
Have you experimented with "REG COMPARE"? maybe potential there...

Report •

#13
October 2, 2015 at 08:32:10
So to use REG COMPARE I'd have to create a new registry key to compare the two values?

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.


Report •

#14
October 2, 2015 at 18:35:18
✔ Best Answer
I don't think so (pls pardon my ignorance). That was indeed my first thought, but then (lightbulb) "it's bound to be already in there!" I found relevant content in my registry at:
HKCU\VolatileEnvironment
under "username" and "userprofile" keys.. (Userprofile most closely corresponding to your target path.)
So,
reg compare registry-path-to-file HKCU\VolatileEnvironment\userprofile &&goto :OK||goto :FAIL

Something like that...


Report •

#15
October 2, 2015 at 20:06:31
If the userprofile value is the same as the one in %USERPROFILE% there might be trouble, because if the user has a custom "My documents" path, I think %HOMEDRIVE%\%HOMEPATH% would be correct, and not the userprofile one.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.


Report •


Ask Question