Computing.Net > Forums > Programming > Change reg query output

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Change reg query output

Reply to Message Icon

Name: toast (by NoIdea)
Date: October 11, 2008 at 05:19:28 Pacific
OS: XP Pro
CPU/Ram: 2.3Ghtz / 1gig
Product: EMachines 580
Comment:

Hi
What I want to do is change AltDefaultUserName to DefaultUserName in the output going to the DefaultUserName.reg

@echo off
cls
for /f "tokens=* delims= " %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Winlogon"\ ^|find "AltDefaultUserName"') do (
echo %%a >>"C:\Documents and Settings\???????\My Documents\DefaultUserName.reg"
)

exit



Sponsored Link
Ads by Google

Response Number 1
Name: Judago
Date: October 11, 2008 at 16:27:44 Pacific
Reply:

If you don't want to use delayed expansion this one should work after <tab>'s have been change to tabs and <space>'s have been changed to spaces. That is for default formatting, I don't know if you need it all.


@echo off
for /f "tokens=2,3" %%a in ('^(reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"\ ^|find "AltDefaultUserName"^) 2^>nul') do (
echo:<space><space><space><space>DefaultUserName<tab>%%a<tab>%%b>>"C:\Documents and Settings\???????\My Documents\DefaultUserName.reg"
)

Using delayed expansion:

SETLOCAL ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('^(reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"\ ^|find "AltDefaultUserName"^) 2^>nul') do (
set adrq=%%a
echo !adrq:AltDefaultUserName=DefaultUserName!>>"C:\Documents and Settings\???????\My Documents\DefaultUserName.reg"
)


It's a good idea to be careful with redirection >>. If your not specifying a handle and you put a space before it eg echo text >> file you will end up with the line "text " in file. echo text>>file won't give this space. That space can sometimes be a cause of alot of trouble.

I'm not using pre tags because of long lines, copy the script into a text editor with wrapping disabled to see where the line breaks are.


0

Response Number 2
Name: toast (by NoIdea)
Date: October 12, 2008 at 01:13:31 Pacific
Reply:

Thanks Judago,
I am not able to test the information just now. I will post back.
Thank you for your help


0

Response Number 3
Name: toast (by NoIdea)
Date: October 13, 2008 at 14:11:13 Pacific
Reply:

Hi Judago
I have now tested the information and with a little tweak, added 4th token
@echo off
for /f "tokens=2,3,4" %%a in ('^(reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"\ ^|find "AltDefaultUserName"^) 2^>nul') do (
echo:<space><space><space><space>DefaultUserName<tab>%%a<tab>%%b<space>%%c>>"C:\Documents and Settings\???????\My Documents\DefaultUserName.reg"
)
This works brilliantly. It was just missing off the last word of the name.
The second batch was brillo from the start.
Thanks for the explanations and the help really appreciated.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Printing RTF in Batch use... Advance Batch file help n...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Change reg query output

completely disable output of reg query www.computing.net/answers/programming/completely-disable-output-of-reg-query/19201.html

Reg query www.computing.net/answers/programming/reg-query/19792.html

Batch file. Extract single phrase f www.computing.net/answers/programming/batch-file-extract-single-phrase-f/16419.html