Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

altering Win2K Backup BKS file

Status
Not open for further replies.

darkman0101

Technical User
Oct 10, 2000
51
NZ
Right here we go...
basically I am Writing an application that shells a batch file that runs Win2k Backup. Backup has a .bks file that specifies directories etc to backup. This file need to be Unicode.

The problem is this... The directory to backup depends on what user is logged on. No probs call GetUserName to obtain the logged on user.

The bks file is initially something like:
C:\Documents and Settings\%username%\My Documents
now Backup will not parse %username% so I open the file backup.bks and create a string that replaces %username% with the logged on user's name.

If I write this string to a new file eg. backup1.bks the resulting text looks like this:
ÿþC:\Documents and Settings\jasonm\My Documents
The prob is the string for the line I get back when I read from the original backup.bks file. It has the these characters ÿþ at the beginning.

Also the original backup.bks file is 106 bytes and the backup1.bks file is 54 bytes. If I try to open them both in wordpad it complains that they are both Unicode txt files.
Backup will not run with this bks file.


Editing the path manually in notepad works fine.

Doesn't VB work in Unicode anyway?
How can I keep the integrity of the file?
BTW it doesn't matter if I open the original backup.bks file for output, the results are the same.
It probably doesn't help that I am using NT4 SP6 (VB6 SP3) and trying to create something for Win2k.(Makes testing hard as I need to email compiled code to brother).

Sorry it's a bit long winded.. here is some code.

Private Function UpdateBKSFile()
Dim filenum As Integer
Dim entirefile As String
Dim fileline As String
Dim beginvar As Long
Dim endvar As Long
Dim leftstr As String
Dim rightstr As String
entirefile = ""
fileline = ""
filenum = FreeFile

Open BKSPath For Input As filenum
Do Until EOF(filenum)
Line Input #filenum, fileline
beginvar = InStr(1, fileline, "%")
endvar = InStr(beginvar + 1, fileline, "%")
leftstr = Left(fileline, beginvar - 1)
rightstr = Mid(fileline, endvar + 1)
entirefile = entirefile & leftstr & UserName & rightstr & vbCrLf
Loop
Close filenum
'Debug.Print entirefile
WriteFile entirefile
End Function
******************************************
Private Sub WriteFile(filestring As String)
Dim filenum As Integer
filenum = FreeFile

Open "c:\backup1.bks" For Output As filenum
Print #filenum, filestring
Print #filenum, ""
Close filenum
End Sub
**********************************************
Public Function UserName() As String

Dim sBuffer As String
Dim lSize As Long
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)

If lSize > 0 Then _
UserName = LCase$(Left$(sBuffer, lSize - 1))
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top