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

Posted on 2009-12-27
Last Modified: 2012-05-08
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.

Question by:dakoit
    LVL 51

    Accepted Solution

    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.

    @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!

    Open in new window

    LVL 68

    Assisted Solution

    That method is unsafe, as some chars might be  converted. I tested with
    %UserProfile%\My Docs
    Another one

    and the second line was converted to
    That might be not important, as long as noone is using Unicode folder names in the BKS file.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
    Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
    The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now