How to have Userprofile variable in bks file or convert text file containing variables to bks using a batch script?

We  have created a batch script to run nt backup to backup our field computers. We had bks file with variable userprofile (%userprofile%) but nt backup would not recognize it. Is it possible to have any variables in bks file which is unicode format so that Nt backup recognizes it.Or I need to find a way to using a batch script to take a text file containing locations with variables to a local location and then convert convert the file to Unicode. The reason we want text file is the capability to add more location if needed.

thanks
Andy
dakoitAsked:
Who is Participating?
 
Bill PrewConnect With a Mentor Commented:
This seemed to work for me.  Save the attached BAT script as a file, let's say CHGBKS.BAT.  Then run as follows from a command line.

CMD /U /C CHGBKS.BAT inputfile.txt outputfile.bks

The idea here is that the CMD /U option forces unicode output from the BAT file executed.  In my batch file I just process the inputfile, replace the %USERPROFILE% string in the file with the current environment variable, and then write it out again to outputfile.

~bp
@echo off
setlocal EnableDelayedExpansion
setlocal EnableExtensions
if exist %2 del %2
for /f "tokens=*" %%A in ('type %1') do (
  set Temp=%%A
  set Temp=!Temp:%%USERPROFILE%%=%USERPROFILE%!
  echo !Temp!
)>>%2

Open in new window

0
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
That method is unsafe, as some chars might be  converted. I tested with
test
ÐAest
%UserProfile%\My Docs
Another one

and the second line was converted to
ÐLest
That might be not important, as long as noone is using Unicode folder names in the BKS file.
0
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.

All Courses

From novice to tech pro — start learning today.