Hi,
I have been coding HTA for about 2 weeks now and am trying to produce the same thing as the guy who started this thread.
I already have experience in PHP, but VBS is not my strong point.
I created a few Backup batch files with Robocopy and am trying to combine them.
This thread along with other threads on visualbasicscript.com have helped me get as far as i am now:
My Code:
<html>
<head>
<title id="title">Backup</title>
<HTA:APPLICATION
SCROLL="no"
MAXIMIZEBUTTON="no"/>
<LINK href=a.css rel=stylesheet type=text/css>
<SCRIPT Language="VBScript">
Public w,x,y
Const M=1048576
Set A=CreateObject("Scripting.FileSystemObject")
Set B=CreateObject("wscript.shell")
Set K=A.CreateTextFile(2, True)
K.Close
Set K=A.CreateTextFile(3, True)
K.Close
'-- w: bar width, x: done items, y: remaining items
Sub Window_Onload
window.resizeTo 800,600
w=50
Set C=A.OpenTextFile(1, 1)
y=C.ReadAll
C.Close
window.setInterval "Progress", 150
End Sub
Sub Progress
Set C=A.GetFolder("E:\Hello")
x=Int((C.Size))
Set F=window.document.getElementById("G")
Set L=window.document.getElementById("A")
Call G()
F.value=G
F.scrollTop=F.scrollTop+F.scrollHeight
Call I()
L.value=I
L.scrollTop=L.scrollTop+L.scrollHeight
d = Round( x / (y/w) +1 ,0)
document.Title="Running Backup " & FormatPercent(x/y, 0)
document.all.ProgBarText.innerText = FormatNumber(x/M,0) & " MB" & "/" & FormatNumber(y/M,0) & " MB"
document.all.ProgBarDone.innerText = String(d, "_")
If d<w Then
document.all.ProgBarToDo.innerText = String(w-d, "_") & "|"
Else
document.all.ProgBarToDo.innerText = "|"
End If
If x=y Then
document.all.ProgBarToDo.innerText = ""
MsgBox "ok"
window.close
End If
End Sub
Sub H_OnClick()
E=A.GetTempName
E=B.Environment("PROCESS")("TEMP") & "\" & E
D=B.Run("test2.bat >" & Chr(34) & E & Chr(34), 0, True)
End Sub
Function G()
With A.OpenTextFile(2)
If Not .AtEndOfStream Then
G=.ReadAll
End If
.Close
End With
End Function
Function I()
With A.OpenTextFile(3)
If Not .AtEndOfStream Then I=.ReadAll
.Close
End With
End Function
</SCRIPT>
</head>
<body bgcolor="#D7D7D7">
<input type=button id=H value=Test Me>
<span id="ProgBarText"></span><br />
<span id="ProgBarDone" style="background-color: #3399FF"></span>
<font color="#FFFFFF">
<span id="ProgBarToDo"style="background-color: #C0C0C0"></span>
</font><br />
<textarea id=G rows="30" cols="100" bgcolor="Green"></textarea><br />
<textarea style=overflow:hidden; id=A cols="4" bgcolor="Green">0</textarea>
</body>
</html> I like to make things compacted because this is going to be used on very slow computers in a business that uses thousands of computers.
That's why i have all my variables named A,B,C,D,E,F,G,H,I,J,K and output files 1,2,3 without .txt on the end.
This file will not copy the files from one area but a lot of different area's on the computer.
How it works:
Progress bar:
1. Before this code runs I have a batch file which counts the amount of memory the backup. (this file is invisible)
Batch file:
setlocal enabledelayedexpansion
Set A="%programfiles%\folder1"
Set B="%programfiles%\folder2"
Set C="%userprofile%\folder1"
Set D="%userprofile%\folder2"
Set M=0
for /R %A% %%N in (*) do (set /a M=!M!+%%~zN)
for /R %B% %%N in (*) do (set /a M=!M!+%%~zN)
for /R %C% %%N in (*) do (set /a M=!M!+%%~zN)
for /R %D% %%N in (*) do (set /a M=!M!+%%~zN)
for /R D: %%N in (*) do (set /a M=!M!+%%~zN)
echo %M% > 1
endlocal
2. This file then puts the total memory in bytes into file '1'.
3. Set C=A.OpenTextFile(1, 1), y=C.ReadAll, y then = the value in file '1'.
4. Set C=A.GetFolder("E:\Hello"), x=Int((C.Size)) x then = the total size of folder Hello. (The backup will make its own folder so it will be empty at the start of the backup)
That is the progress bar, it works through the total memory transferred from the copy location to the destination for a more accurate result.
When button (id=H) is pressed:
Sub H_OnClick()
E=A.GetTempName
E=B.Environment("PROCESS")("TEMP") & "\" & E
D=B.Run("test2.bat >" & Chr(34) & E & Chr(34), 0, True)
End Sub
Function G()
Test2.bat starts with robocopy built in, this code also allows it to run invisible
Robocopy code:
if exist "%programfiles%\folder1" robocopy "%programfiles%\folder1" "E:\Hello" /E /NC /NDL /NJH /NJS /LOG+:"2" /LOG:"3"
As you can see I am updating 2 different log files, file '2' and '3', this seems to work fine.
If you can follow me so far, what i want to do now is get one textarea to show the % progress and the other one to show the completed file through robocopy.
Set F=window.document.getElementById("G")
Set L=window.document.getElementById("A")
Sub Progress Call G()
F.value=G
F.scrollTop=F.scrollTop+F.scrollHeight
Call I()
L.value=I
L.scrollTop=L.scrollTop+L.scrollHeight
End Sub
Sub Function G()
With A.OpenTextFile(2)
If Not .AtEndOfStream Then
G=.ReadAll
End If
.Close
End With
End Function
Function I()
With A.OpenTextFile(3)
If Not .AtEndOfStream Then I=.ReadAll
.Close
End With
End Function
This is the code i have created to read files '2' and '3' and put them into textarea G and A.
I have tried all sorts of things, SkipLine, Skip(), ReadLine with a loop but i can't seem to edit out the % values of file '2' and only have the % values in file '3'.
Any idea?
If you manage to understand my code and can help me it would be greatly appreciated!
Kind regards,
Paul Hemmens
<message edited by Paulus88 on Wednesday, December 28, 2011 7:46 AM>