progress bar in vbs

Discussion in 'Software' started by red death68, May 18, 2011.

  1. red death68

    red death68 Command Sergeant Major

    as iv stated in other threads i am making a mod uninstaller for my one game but i need to add progress bars so it shows that its working i need to extract a 7z archive with a progress bar in vbs or alternantly create a sfx archive that auto extracts but i am having trouble with either. i can't manage to make the sfx automaticly extract without confirmation(im more used to winrar but its doesnt have as high of compression as 7z)

    i was thinking of somehow piping the results from a batch to a vbs such as the progress shown here in this code i found online

    Code:
    @ECHO OFF
    set "max=11"
    call :initProgress %max% "Window Title: [PPP]"
    for /l %%N in (1,1,%max%) do (
        ping -n 2 -w 1 127.0.0.1>NUL
        call:doProgress
    )
    GOTO:EOF
    
    :initProgress max format -- initialize an internal progress counter and display the progress in percent
    ::                       -- max    [in]     - progress counter maximum, equal to 100 percent
    ::                       -- format [in,opt] - title string formatter, default is '[P] completed.'
    :$created 20060101 :$changed 20080327
    :$source http://www.dostips.com
    set /a "ProgressCnt=-1"
    set /a "ProgressMax=%~1"
    set "ProgressFormat=%~2"
    if not defined ProgressFormat set "ProgressFormat=[PPPP]"
    set "ProgressFormat=%ProgressFormat:[PPPP]=[P] completed.%"
    call:doProgress
    EXIT /b
    
    
    :doProgress -- display the next progress tick
    :$created 20060101 :$changed 20080327
    :$source http://www.dostips.com
    set /a "ProgressCnt+=1"
    SETLOCAL ENABLEDELAYEDEXPANSION
    set /a "per100=100*ProgressCnt/ProgressMax"
    set /a "per10=per100/10"
    set /a "per10m=10-per100/10-1"
    set "P=%per100%%%"
    set "PP="
    for /l %%N in (0,1,%per10%) do call set "PP=%%PP%%*"
    for /l %%N in (%per10%,1,9) do call set "PP=%%PP%% "
    set "PPP="
    for /l %%N in (0,1,%per10m%) do call set "PPP=%%PPP%%*"
    set "ProgressFormat=%ProgressFormat:[P]=!P!%"
    set "ProgressFormat=%ProgressFormat:[PP]=!PP!%"
    set "ProgressFormat=%ProgressFormat:[PPP]=!PPP!%"
    title %ProgressFormat%
    EXIT /b
    
    does anyone have any idea how on earth i can make this work(it doesnt even matter what scripting language is used personally)
     
  2. GermanOne

    GermanOne Guest

    Haha, I know these batch functions. I'm one of the moderators of the web site where you found them ...

    There is no way to "pipe" the output of a batch file to the VBS code inside of an HTA file. The only possibility could be something like "write file -- read file" (but you should avoid it).

    A progress bar for HTA is very simple. Basically you need 3 nested DIVs -- one for the background, the second for the progress bar itself and the third for displaying the percentage. Of course you can change the length of the 2nd DIV and the text in the 3rd DIV by VBS.
    *.hta
    Code:
    <html>
      <head>
        <title>Progress Bar</title>
        <HTA:APPLICATION>
      </head>
    
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        Dim vTimer, iCurr, iMax
        iMax = 123
      
        sub start
          If vTimer <> "" Then Exit Sub
          iCurr = 0
          vTimer = window.setInterval("ticker", 20)
          x = x + 1
        end sub
    
        sub ticker
          write_progress iCurr, iMax
          If iCurr = iMax Then
            window.clearInterval vTimer
            vTimer = ""
          End If
          iCurr = iCurr + 1
        end sub
    
        sub write_progress(iCurrent, iTotal)
          pb_bar.style.width = Round(iCurrent * 300 / iTotal, 0) & "px"
          pb_text.innerHTML = Round(iCurrent * 100 / iTotal, 0) & "%" 
        end sub
      </script>
    
      <body>
        Test:<br><br>
        <div id="pb_background" style="position:relative; width:300px; height:30px; background:#AAAAAA;">
          <div id="pb_bar" style="position:absolute; width:0px; height:30px; background:#3333DD;">
            <div
             id="pb_text"
             onclick="start"
             style="position:absolute; top:0; left:0; padding-top:5px; width:300px; font:12pt arial; font-weight:bold; text-align:center; color:#FFFFFF; cursor:hand;"
            >
              click me
            </div>
          </div>
        </div>
      </body>
    </html>
    
    But (as I told you in your former thread) you need to know how many items comprises your archive in total and how many items are currently extracted. Where do these numbers come from???

    Regards
    GermanOne
     
  3. red death68

    red death68 Command Sergeant Major

    i dont know im trying to figure out how extraction programs find the values themselves

    as for total number of files i can do that part myself


    and kind of ironic your a mod there i got a good laugh outa the coincidence in that one lol
     
  4. PC-XT

    PC-XT Master Sergeant

    Extraction programs keep track of how much they have written and show it on a bar that represents the total size of all files, (or the size of each file.) You may be able to make a hack from a list of files in order of when they are copied, but it would be a little slow... The hack would be a separate process. Here's pseudocode:
    Code:
    const allfilesize=[size of all files]
    total=0
    for each file in filelist {
       do{
          size=file's size
          display progressbar for total+size out of allfilesize
       }loop until next file exists
       total=total+size
    }
    However, this may not work as expected, since some file extractors/movers/copiers make a new file of the final size, then fill it in, so the size will not change, and you might as well just check for files that exist and forget the size part:
    Code:
    numfiles=...
    total=0
    for each file in filelist {
        if file exists, increment total and show progressbar as total out of numfiles, next file
        wait some amount of time like a second
    }
    This will be less accurate, especially with a few large files, but is more efficient.
     
  5. GermanOne

    GermanOne Guest

    Well, you don't need a file list if the number of files is defined.

    Counting of the files in a folder (and its sub folders) is simple.
    *.vbs
    Code:
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    n = CountFiles("C:\somewhere")
    MsgBox n
    
    Function CountFiles(strFolderName)
      If objFSO.FolderExists(strFolderName) Then
        Set objParentFolder = objFSO.GetFolder(strFolderName)
        On Error Resume Next
        iFileCount = objParentFolder.Files.Count
        For Each objSubFolder In objParentFolder.SubFolders
          iFileCount = iFileCount + CountFiles(objSubFolder.Path)
        Next
        On Error Goto 0
      Else
        iFileCount = 0
      End If
      CountFiles = iFileCount
    End Function
    
    
    Regards
    GermanOne
     
  6. PC-XT

    PC-XT Master Sergeant

    Yes, if it's a new, empty, folder, or you count the number of files already in the folder to be used as an offset, then you don't need the file list unless other processes are modifying the folder's contents. For an installer, it should really be in a separate, new, empty, folder, anyway, making new empty subfolders, which would work.

    If it is a modification of an existing installation, you would need to remember the starting number of files, and subtract it from the count before displaying the progress bar. The installation should not be in use during the modification, of course, so the count should be accurate without a file list (as long as other programs don't mess with that part of the filesystem.)

    It would be trickier if there were file deletions, too... You would then need to check that some files don't exist... Then there are registry entries... but I think you are just extracting, so you don't need to worry about these.
     
  7. red death68

    red death68 Command Sergeant Major

    well iv found out how to make it automaticly extract itself but theres a slight error and to fix it i need to alter a file called 7zsd_All.sfx does anyone have any idea what program can alter this (preferably a free one)
     
  8. GermanOne

    GermanOne Guest

    I thought 7z.exe could do that (option u) :confused
    To be honest I never used it and I'm not familiar with this stuff.

    Regards
    GermanOne
     
  9. red death68

    red death68 Command Sergeant Major

    im not talking the option u im talking to make it automaticly extract when double clicked. iv got it to show the extraction like i want but theres a slight problem either the extraction finishes but then says it cant find setup.exe which is because of the sfx file or it finishes but wont get rid of the 100% complete window which I need to alter the sfx file to fix as well problem is i don't have a program that opens it properly it opens it in alot of gyperish

    and yes these are 2 differnt sfx files iv tried
     
  10. red death68

    red death68 Command Sergeant Major

    finaly got the sfx working it was a modual problem along with the fact that i made the nub mistake of running a large extraction on removable media which made it freeze
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds