need help with hta's

Discussion in 'Software' started by red death68, Mar 26, 2011.

  1. red death68

    red death68 Command Sergeant Major

    ok so i recently found out about a thing called hta(html application) and im trying to use one to make a uninstaller for game mod's but im having trouble i need a way to write the options from the check box into a text doc so i can make a batch file read the options and respond accordingly by transfering files based on what they are but im having great trouble with this since many vbs commands dont work yet with hta's here what i have so far

    Code:
    <html>
    <head>
    <title>Mod Uninstaller</title>
    <HTA:APPLICATION 
         ID="Mod Uninstaller"
         APPLICATIONNAME="Mod Uninstaller"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
         MaximizeButton="no"
         MinimizeButton="yes"
         Border="thin"
         icon="skull.ico"
    </head>
    
    <SCRIPT LANGUAGE="VBScript">
    window.resizeto 800, 620
    Sub sounds
    Call ScriptStart(autoactpath & "test.VBS")
    End Sub
    </SCRIPT>
    
    <body background=cf.jpg BGPROPERTIES=FIXED>
    <input type="checkbox" name="sound"> sound
    <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="sounds">
    </body>
    
    </form> 
    </html>
    what i need to do is take the input from the check boxes add it to a text doc then i can make the batch file which will copy them accordingly to the corrasponding folders

    PS: im gonna run the batch file hidden if at all possible so i also need to call a vbs to run the cmd window hidden which i have the code for here

    Code:
    Set WshShell = WScript.CreateObject( "WScript.Shell" )
    WshShell.Run "test2.bat",0,True
     
  2. PC-XT

    PC-XT Master Sergeant

    I'm more familiar with WScript and regular HTML than hta, but here's some tips:

    For creating files, the following usually works fine for me, as in WScript:
    Code:
    Set fSys = CreateObject("Scripting.FileSystemObject")
    Set logf=fSys.createTextFile("hta.log")
    logf.writeLine "yo!"
    logf.close

    I also found that checkboxes can be tested using just the id. For a checkbox with html:
    Code:
    <input type="checkbox" id="chk1">
    you can use the following vbScript test:
    Code:
    if chk1.checked then ItsChecked else ItsNotChecked

    For using the shell.run function, using VBScript's CreateObject function doesn't work as well as WScript's or JScript's activeXobject. WScript isn't supported directly, so I use Jscript. Here's an example of calling "hello world.hta" from the same folder, both directly in an onclick and using a sub:
    Code:
    <html><head><HTA:APPLICATION ID="testWshShell" 
       BORDER="thick" 
       BORDERSTYLE="complex"/>
    <TITLE>HTA - Hello World Test</TITLE>
    <script language="VBScript">
    self.ResizeTo 300,360
    </script>
    <script language="JScript">
    WshShell=new ActiveXObject('WSCRIPT.Shell');
    function ShellRun(commandline,winmode,wait){return WshShell.run(commandline,winmode,wait);}
    </script>
    <script language="VBScript">
    sub testWshShell
     t=ShellRun(chr(34)+"hello world.hta"+chr(34),1,false)
    end sub
    </script>
    </head><body><input type="button" value="run (direct)" onclick="shellRun '&quot;hello world.hta&quot;',1,false"> <input type="button" value="run (from sub)" onclick="testWshShell"></body></html>
    I find it usually works best to precede the JScript section by a VBScript one if the majority of the code will be VBScript.

    If I try the same thing using VBScript, I get a file not found error when the file is there, even using an absolute path. :banghead I also have trouble accessing the WshShell object directly in VBScript, but calling the JScript ShellRun from vbScript works for me.
     
  3. PC-XT

    PC-XT Master Sergeant

    I forgot to mention I'm pretty sure ActiveXObject "WScript.shell" requires WScript to be installed on the machine running the script, in case you are planning to distribute your code.
     
  4. red death68

    red death68 Command Sergeant Major

    iv found that apperently you cannot use win.script with an hta for some strange reason

    so i need a way to run the window hidden if i can do that i can make it just run batch files hidden to create the output text and then read the output as variables in the final batch file which i will be creating

    ill probably start writting the batches for now until i have found a way to call them using vbs while avoiding the win.shell which isnt allowed in hta
     
  5. red death68

    red death68 Command Sergeant Major

    iv also found a useful part for the uninstaller its how to add a dialog box for file selection but what i need it it to select a folder any idea's

    heres the code

    Code:
    <html>
    <head>
    <title>Load Computers Sample</title>
    <HTA:APPLICATION 
         ID="objTestHTA"
         APPLICATIONNAME="Load Computers Sample"
         SCROLL="yes"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
    >
    </head>
    <SCRIPT Language="VBScript">
    Sub LoadComputers
        Set objDialog = CreateObject("UserAccounts.CommonDialog")
        objDialog.Filter = "Text Files|*.txt|All Files|*.*"
        objDialog.FilterIndex = 1
        objDialog.InitialDir = "C:\Scripts"
        intResult = objDialog.ShowOpen
        If intResult = 0 Then
            Exit Sub
        End If
        For Each objOption in AvailableComputers.Options
            objOption.RemoveNode
        Next
        
        ForReading = 1
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objFile = objFSO.OpenTextFile _
            (objDialog.FileName, ForReading)
        Do Until objFile.AtEndOfStream
            strLine = objFile.ReadLine
            Set objOption = Document.createElement("OPTION")
            objOption.Text = strLine
            objOption.Value = strLine
            AvailableComputers.Add(objOption)
        Loop
        objFile.Close
    End Sub
    </SCRIPT>
    <body bgcolor="buttonface">
    <input id=runbutton  class="button" type="button" value="Load Computers" 
    name="run_button"  onClick="LoadComputers"><p>
    <select size="10" name="AvailableComputers" style="width:300" >
    </select>
    </body>
    </html>
    id like to find a way to select just the folder not the file
     
  6. GermanOne

    GermanOne Guest

    Have a look at the BrowseForFolder method
    Code:
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Please select a folder.", 0, "C:\Scripts")
        If Not TypeName(oFolder) = "Nothing" Then
            MsgBox oFolder.Self.Path
        End If
        Set oFolder = Nothing
    
    Instead of MsgBox you can assign a string variable.

    Regards
    GermanOne
     
  7. red death68

    red death68 Command Sergeant Major

    thanks german buddy that will help quite a bit but i still have a few other problems with my hta (thats what i get for going complex on my first try)

    i need to make a batch run hidden as i stated earlier and im also having having some trouble the vbs

    i need to make it write contents of folder selection to a text doc along with writing a seprate text doc that could would hold the options for my uninstaller(specifics to uninstall in differnt area's of mods)

    so what i need is basicly a way to write the folder selection to a text doc and the options from check boxes (which i already have) to a seperate text doc

    also is it possible to cut off the folder selection at a certain folder? because the folder structure for the game the mods will be uninstalled from is quite complex it has multiple folders but i only want the user to select the root of the program directory not the specific folder for each mod

    good to know because i was planning on posting the final hta as a sfx archive on the forums for the game since the current uninstaller available is not all that great and the guy who made it didnt do something right so you cant delete the uninstaller itself without removing the files it replaced

    so mines going to be a much better solution if i ever finish it sadly im used to batch and now im trying to mix vbs,html,hta,and batch its quite complex an undertaking but i think i can handle it with a little help fromm the local community(majorgeeks) so ty to both you and german for your help so far
     
  8. GermanOne

    GermanOne Guest

    Thats all too complicated. There's nothing in Batch what you couldn't do in VBScript as well. Forget all this "write to file/read from file"-sh... and do it using VBScript.

    If all the folders are in the same root then loop over this root folder, write all found subfolders to a drop down list and let the user select one of them...

    Regards
    GermanOne
     
  9. GermanOne

    GermanOne Guest

    OK, just to show an example how my suggestion could work.
    Lets say the root folder is "C:\Scripts":
    Code:
    <html>
    <head>
    <title>Load Computers Sample</title>
    <HTA:APPLICATION 
         ID="objTestHTA"
         APPLICATIONNAME="Load Computers Sample"
         SCROLL="yes"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
    >
    </head>
    
    <SCRIPT Language="VBScript">
    
    Sub LoadSubfolders
      For Each oOption In AvailableSubfolders.Options
        oOption.RemoveNode
      Next 
      Set oFSO = CreateObject("Scripting.FileSystemObject")
      Set oRootFolder = oFSO.GetFolder("C:\Scripts")
      For Each oFolder In oRootFolder.SubFolders
        Set oOption = Document.createElement("OPTION")
        oOption.Text = oFolder.Name
        oOption.Value = oFolder.Name
        AvailableSubfolders.Add(oOption)
      Next
    End Sub
    
    Sub ShowSelection()
      x = AvailableSubfolders.selectedIndex
      MsgBox AvailableSubfolders.options(x).text
    End Sub
    
    </SCRIPT>
    
    <body bgcolor="buttonface">
    <input id=runbutton  class="button" type="button" value="Load Subfolders" 
    name="run_button"  onClick="LoadSubfolders"><p>
    <select size="1" name="AvailableSubfolders" style="width:300" onChange="ShowSelection">
    </select>
    </body>
    </html>
    
    Regards
    GermanOne
     
  10. red death68

    red death68 Command Sergeant Major

    ty german like i said im increadably new to vbs and hta can you explain some parts of this code?

    because at first it says folder doesnt exist then i got that fixed now it does nothing
     
  11. GermanOne

    GermanOne Guest

    Code:
      For Each oOption In AvailableSubfolders.Options
        oOption.RemoveNode
      Next 
    Remove each node in the drop down list (important if you run the code twice).

    Code:
      Set oFSO = CreateObject("Scripting.FileSystemObject")
    Reference the file system.

    Code:
      Set oRootFolder = oFSO.GetFolder("C:\Scripts")
    Reference the folder "C:\Scripts" as an object.

    Code:
      For Each oFolder In oRootFolder.SubFolders
    Assigns a reference for each subfolder found in "C:\Scripts".

    Code:
        Set oOption = Document.createElement("OPTION")
    Creates a new OPTION node.

    Code:
        oOption.Text = oFolder.Name
    Assigns the text property of the new node.

    Code:
        oOption.Value = oFolder.Name
    Assigns the value property of the new node.

    Code:
        AvailableSubfolders.Add(oOption)
    Add the node to the trop down list.

    Code:
      Next
    Return to the beginning of the loop to make the same things for the next found subfolder.
    _______________________________________________________________

    Code:
      x = AvailableSubfolders.selectedIndex
    Find the index of the selected node (the first node has index 0, the second has index 1 etc.).

    Code:
      MsgBox AvailableSubfolders.options(x).text
    Output the text property of the selected node.

    Regards
    GermanOne
     
  12. red death68

    red death68 Command Sergeant Major

    thanks man very informative ill see what i can do to implament it into my code
     
  13. red death68

    red death68 Command Sergeant Major

    ignore i figured it out ty bud
     
    Last edited: Mar 27, 2011
  14. red death68

    red death68 Command Sergeant Major

    well i found a code to do just what i want but im having trouble implamenting it into my hta it keeps saying it expected a statement here the code of the hta i have so far

    Code:
    <html>
    <head>
    <title>Mod Uninstaller</title>
    <HTA:APPLICATION 
         ID="Mod Uninstaller"
         APPLICATIONNAME="Mod Uninstaller"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
         MaximizeButton="no"
         MinimizeButton="yes"
         Border="thin"
         icon="skull.ico"
    </head>
    
    <SCRIPT LANGUAGE="VBScript">
    window.resizeto 800, 620
    sub test
            If sound.Checked Then
                Msgbox "You checked sound."
            End If
            If bg.Checked Then
                Msgbox "You checked background."
            End If
            If bgm.Checked Then
                Msgbox "You checked background music."
            End If
            If ui.Checked Then
                Msgbox "You checked User Interface."
            End If
            If km.Checked Then
                Msgbox "You checked kill marks."
            End If
    end sub
    </script>
    
    <body background=cf2.jpg BGPROPERTIES=FIXED>
    <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
    <h1>Which Modifications to CrossFire would you like to remove?</h1>
    </div>
    <div style="position:absolute;top:360px;left:320px">
    <input type="checkbox" name="sound"> Radio Sounds<br>
    <input type="checkbox" name="bg"> Login Background<br>
    <input type="checkbox" name="bgm"> Background Music<br>
    <input type="checkbox" name="ui"> User Interface<br>
    <input type="checkbox" name="km"> Kill Marks<p>
    <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="test">
    </div>
    
    </body>
    </div>
    </form> 
    </html>
    and heres the vbs code i found

    Code:
    '************************************************
    ' File:    Dialog.vbs (WSH sample in VBScript) 
    ' Author:  (c) G. Born
    '
    ' Using the shell dialog box to select a folder
    '************************************************
    Option Explicit
    
    ' Flags for the options parameter
    Const BIF_returnonlyfsdirs   = &H0001
    Const BIF_dontgobelowdomain  = &H0002
    Const BIF_statustext         = &H0004
    Const BIF_returnfsancestors  = &H0008
    Const BIF_editbox            = &H0010
    Const BIF_validate           = &H0020
    Const BIF_browseforcomputer  = &H1000
    Const BIF_browseforprinter   = &H2000
    Const BIF_browseincludefiles = &H4000
    
    Dim wsh, objDlg, objF
    
    ' Get Application object of the Windows shell.
    Set objDlg = WScript.CreateObject("Shell.Application")
    
    ' Use the BrowseForFolder method.
    ' For instance: Set objF = objDlg.BrowseForFolder _
    '     (&H0, "Select the folder to copy", &H10, "C:\Born")
    
    Set objF = objDlg.BrowseForFolder (&H0, _
        "Select the folder to copy", _
        BIF_editbox + BIF_returnonlyfsdirs)
    
    ' Here we use the first method to detect the result.
    If IsValue(objF) Then 
        MsgBox "Selected folder: " & objF.Title
    Else
        MsgBox "Canceled"
    End If
    
    ' Here we use TypeName to detect the result.
    If InStr(1, TypeName(objF), "Folder") > 0 Then
        MsgBox "Selected folder: " & objF.Title
    Else
        MsgBox "Canceled"
    End If
    
    Function IsValue(obj)
        ' Check whether the value has been returned.
        Dim tmp
        On Error Resume Next
        tmp = " " & obj
        If Err <> 0 Then
            IsValue = False
        Else
            IsValue = True
        End If
        On Error GoTo 0
    End Function
    
    '*** End
    i need to find a way to implament this code into the hta when someone clicks a button to select the path
     
  15. GermanOne

    GermanOne Guest

    LOL It's the BrowseForFolder like I suggested before.

    I guess it's not what you need. You have to find a way automatically figuring out whether and where CrossFire is installed.

    I don't play any computer games. For that reason I need your help to script this. Make the following manually:
    Run the rigistry editor (regedit.exe). Follow this path:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    If you found a key for CrossFire then right click it and generate an export file.
    C/P the content here.

    Regards
    GermanOne
     
  16. red death68

    red death68 Command Sergeant Major

    wow i guess i over looked your folder suggestion my bad iv been sick as a dog and figured id do some scripting in my free time

    iv implamented your earlier suggestion and it works like a charm again im sorry i over looked it i guess reading code while im sick isnt such a good idea
     
  17. red death68

    red death68 Command Sergeant Major

    ok need a little more help iv expanded the code quite a bit but im at a cross roads iv peieced in some code found for writting a variable to a text doc but its giving me an error saying object required server and ideas heres the code

    Code:
    <html>
    <head>
    <title>Mod Uninstaller</title>
    <HTA:APPLICATION 
         ID="Mod Uninstaller"
         APPLICATIONNAME="Mod Uninstaller"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
         MaximizeButton="no"
         MinimizeButton="yes"
         Border="thin"
         icon="skull.ico"
    </head>
    
    <SCRIPT LANGUAGE="VBScript">
    window.resizeto 800, 620
    sub test
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Please select a folder.", 0, "C:\Scripts")
        If Not TypeName(oFolder) = "Nothing" Then
        End If
        Set oFolder = Nothing
        Set objShell = CreateObject("Wscript.Shell")
    Const fsoForWriting = 2
    
    Dim objFSO
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\SomeFile.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    objTextStream.WriteLine "oFolder.Self.Path"
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
        objShell.Run "test.bat"
    end sub
    </script>
    
    <body background=cf2.jpg BGPROPERTIES=FIXED>
    <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
    <h1>Which Modifications to CrossFire would you like to remove?</h1>
    </div>
    <div style="position:absolute;top:360px;left:320px">
    <input type="checkbox" name="sound"> Radio Sounds<br>
    <input type="checkbox" name="bg"> Login Background<br>
    <input type="checkbox" name="bgm"> Background Music<br>
    <input type="checkbox" name="ui"> User Interface<br>
    <input type="checkbox" name="km"> Kill Marks<p>
    <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="test">
    </div>
    
    </body>
    </div>
    </form> 
    </html>
    i still have to add the if perematers for the check boxes but ill do those soome right now i need to get the writting to text doc part fixed then ill add the perematers because their using the same method to write the results to a text doc
     
  18. GermanOne

    GermanOne Guest

    Have a look at the changings (marked by asterisks).
    Code:
    <html>
    <head>
    <title>Mod Uninstaller</title>
    <HTA:APPLICATION 
         ID="Mod Uninstaller"
         APPLICATIONNAME="Mod Uninstaller"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
         MaximizeButton="no"
         MinimizeButton="yes"
         Border="thin"
         icon="skull.ico"
    </head>
    
    <SCRIPT LANGUAGE="VBScript">
    window.resizeto 800, 620
    sub test
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(&H0, "Please select a folder.", &H0010 + &H0001) '********** CHANGED
        If Not TypeName(oFolder) = "Nothing" Then
          selctedFolderName = oFolder.Self.Path '********** INSERTED
        End If
        Set oFolder = Nothing
        Set objShell = CreateObject("Wscript.Shell")
    Const fsoForWriting = 2
    
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject") '********** That caused your error. There is no server object.
    Set objFSO = CreateObject("Scripting.FileSystemObject") '********** CHANGED
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("d:\SomeFile.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "oFolder.Self.Path" '********** things in double quotes are interpreted as strings AND oFolder isn't valid anymore
    objTextStream.WriteLine selctedFolderName '********** CHANGED
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
        'objShell.Run "test.bat"
    end sub
    </script>
    
    <body background=cf2.jpg BGPROPERTIES=FIXED>
    <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
    <h1>Which Modifications to CrossFire would you like to remove?</h1>
    </div>
    <div style="position:absolute;top:360px;left:320px">
    <input type="checkbox" name="sound"> Radio Sounds<br>
    <input type="checkbox" name="bg"> Login Background<br>
    <input type="checkbox" name="bgm"> Background Music<br>
    <input type="checkbox" name="ui"> User Interface<br>
    <input type="checkbox" name="km"> Kill Marks<p>
    <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="test">
    </div>
    
    </body>
    </div>
    </form> 
    </html>
    
    Basically you had the If statements in your previous code. Where's the problem?

    Regards
    GermanOne
     
    Last edited by a moderator: Mar 28, 2011
  19. GermanOne

    GermanOne Guest

    Um, sorry I forgot to undo some changes:
    Set objTextStream = objFSO.OpenTextFile("d:\SomeFile.txt", fsoForWriting, True)
    Changed the drive letter.

    'objShell.Run "test.bat"
    You have to uncomment the line (remove the single quote).

    Sorry again!
     
  20. red death68

    red death68 Command Sergeant Major

    the only problem was the error about service not existing as for the if statements i was just remarking that i have them saved to add soon i just havnt added them yet until i fix the other errores of the code lol


    and once again man thanks your a life saver its works like a charm now i can finish the code your a real life saver again man i wish i could press the thanks button a million times lol

    btw where did you learn all this kind of coding stuff?
     
  21. GermanOne

    GermanOne Guest

    Nah, don't thank me so many times. Otherwise I become too bigheaded. ;)

    I work for a big multinational company where it is strictly forbidden to setup some additional software. So - necessity is the mother of invention - I had to learn the basics in VBA, Batch, WSH and HTA to get my own tools for handling e.g. export files of databases and similar things. I'm an autodidact, means it's all learning by doing. :)

    Regards
    GermanOne
     
  22. red death68

    red death68 Command Sergeant Major

    nice im just learninf at my own pace because thats all i can do my school sucks for computers (thats hs for you) theyve canceled my computer classes every year because of lack of intrest but there kids with classes that have 4 kids in them go figure

    so i missed my a+ class and c++ class
     
  23. red death68

    red death68 Command Sergeant Major

    figures i thought i was done but theres an error in my code and i cant find the fix its a name redifined error heres the code please help

    Code:
    <html>
    <head>
    <title>Mod Uninstaller</title>
    <HTA:APPLICATION 
         ID="Mod Uninstaller"
         APPLICATIONNAME="Mod Uninstaller"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="maximize"
         MaximizeButton="no"
         MinimizeButton="yes"
         Border="thin"
         icon="skull.ico"
    </head>
    
    <SCRIPT LANGUAGE="VBScript">
    window.resizeto 800, 620
    sub test
        Set oFolder = CreateObject("Shell.Application").BrowseForFolder(&H0, "Please select a folder.", &H0010 + &H0001)
        If Not TypeName(oFolder) = "Nothing" Then
          selctedFolderName = oFolder.Self.Path
        End if
        Set oFolder = Nothing
        Set objShell = CreateObject("Wscript.Shell")
    
    Const fsoForWriting = 2
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\path.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "oFolder.Self.Path"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
    
            If Sound.Checked then          
    Const fsoForWriting = 2
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\option1.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "sound"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing    
            End If
            If bg.Checked Then
                Const fsoForWriting = 2
    
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\option2.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "background"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
            End If
            If bgm.Checked Then
                
    Const fsoForWriting = 2
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\option3.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "backgroundmusic"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
            End If
            If ui.Checked Then
                
    Const fsoForWriting = 2
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\option4.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "userinterface"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
            End If
            If km.Checked Then
                
    Const fsoForWriting = 2
    Dim objFSO
    'Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("C:\temp\option5.txt", fsoForWriting, True)
    
    'Display the contents of the text file
    'objTextStream.WriteLine "killmarks"
    objTextStream.WriteLine selctedFolderName
    
    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing
    
    objShell.Run "test.bat"
    end sub
    </script>
    
    <body background=cf2.jpg BGPROPERTIES=FIXED>
    <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
    <h1>Which Modifications to CrossFire would you like to remove?</h1>
    </div>
    <div style="position:absolute;top:360px;left:320px">
    <input type="checkbox" name="sound"> Radio Sounds<br>
    <input type="checkbox" name="bg"> Login Background<br>
    <input type="checkbox" name="bgm"> Background Music<br>
    <input type="checkbox" name="ui"> User Interface<br>
    <input type="checkbox" name="km"> Kill Marks<p>
    <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="test">
    </div>
    
    </body>
    </div>
    </form> 
    </html>
    error appears to be at line 43 where it says "If Sound.checked then"

    (without the qoutes)
     
  24. GermanOne

    GermanOne Guest

    -You declared constants and variables again and again like "Const fsoForWriting = 2", "Dim objFSO", "Dim objTextStream". That's forbidden.
    -You forgot an "End If"
    -objFSO could be valid for the entire code if you dont destroy it.

    BTW Strange kind of inverted code indention. I had some problems to read it in the beginning. For that reason I tried to make it better ;) I also removed some unnecessary commented lines.
    Code:
    <html>
      <head>
        <title>Mod Uninstaller</title>
        <HTA:APPLICATION 
             ID="Mod Uninstaller"
             APPLICATIONNAME="Mod Uninstaller"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
             icon="skull.ico"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          Set oFolder = CreateObject("Shell.Application").BrowseForFolder(&H0, "Please select a folder.", &H0010 + &H0001)
          If Not TypeName(oFolder) = "Nothing" Then
            selctedFolderName = oFolder.Self.Path
          End if
          Set oFolder = Nothing
          Set objShell = CreateObject("Wscript.Shell")
        
          Const fsoForWriting = 2
          Dim objFSO
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          
          Dim objTextStream
          Set objTextStream = objFSO.OpenTextFile("C:\temp\path.txt", fsoForWriting, True)
          objTextStream.WriteLine selctedFolderName
          objTextStream.Close
          Set objTextStream = Nothing
        
          If Sound.Checked then          
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option1.txt", fsoForWriting, True)
            objTextStream.WriteLine selctedFolderName
            objTextStream.Close
            Set objTextStream = Nothing    
          End If
        
          If bg.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option2.txt", fsoForWriting, True)
            objTextStream.WriteLine selctedFolderName
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If bgm.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option3.txt", fsoForWriting, True)
            objTextStream.WriteLine selctedFolderName
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If ui.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option4.txt", fsoForWriting, True)
            objTextStream.WriteLine selctedFolderName
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If km.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option5.txt", fsoForWriting, True)
            objTextStream.WriteLine selctedFolderName
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          Set objFSO = Nothing
          
          objShell.Run "test.bat"
        end sub
      </script>
      
      <body background=cf2.jpg BGPROPERTIES=FIXED>
        <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
          <h1>Which Modifications to CrossFire would you like to remove?</h1>
        </div>
        <div style="position:absolute;top:360px;left:320px">
          <input type="checkbox" name="sound"> Radio Sounds<br>
          <input type="checkbox" name="bg"> Login Background<br>
          <input type="checkbox" name="bgm"> Background Music<br>
          <input type="checkbox" name="ui"> User Interface<br>
          <input type="checkbox" name="km"> Kill Marks<p>
          <input id=runbutton  class="button" type="button" value="Run" name="run_button" onClick="test">
        </div>
      </body>
    </html>
    
    Regards
    GermanOne
     
  25. red death68

    red death68 Command Sergeant Major

    once again man your a life saver and the weird inversions is prob because i used regular notepd for most of it then later switched to notepad++ for trying to find the errors in it

    also i wasnt sure what was variables lol im so new to vbs its not even funny im alot better with batch after so much practice with it

    had to fix the right line they all were writing the selected folder path lol but other then that its perfect thanks again man
     
    Last edited: Mar 31, 2011
  26. GermanOne

    GermanOne Guest

    I guess you really want to learn some more in coding. Well, then it's time for some suggestions and optimizations.

    1st
    You're using "C:\temp" for saving your files. When I used your code it came up with the error message that this folder didn't exist.
    You should always make sure the folder where you're writing to does already exist.
    But what happen if someone has no permission to create this folder? ...
    Because you create only temporary files you could use the %temp% folder. In the code below I create the folder "%temp%\HTA" in which the files will be saved.

    2nd
    A programmer would never copy/paste the same piece of code to process the same things again. The result is a long unreadable and difficult to maintain "spaghetti-code".
    I used a loop to iterate over all check boxes. For that pupose I assigned the same ID ("check") to each check box. If you reference "check" in the code you will not get a single check box but something like an array of check boxes with an element for each check box.
    The advantages:
    - The code is shorter with a better readability.
    - If you have to change something in the code you have to change only one single line instead of 5 lines for 5 check boxes.
    - You could insert some more check boxes whithout changing the code.

    Code:
    <html>
      <head>
        <title>Mod Uninstaller</title>
        <HTA:APPLICATION 
             ID="Mod Uninstaller"
             APPLICATIONNAME="Mod Uninstaller"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
             icon="skull.ico"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          ' *** Declare the constant
          Const fsoForWriting = 2
          
          ' *** Reference objects which are used in the code
          Set objWshShell = CreateObject("WScript.Shell")
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          Set objShellApp = CreateObject("Shell.Application")
    
          ' *** Check whether folder "%temp%\HTA" exists
          strHTA_Temp = objWshShell.ExpandEnvironmentStrings("%temp%\HTA")
          If Not objFSO.FolderExists(strHTA_Temp) Then objFSO.CreateFolder(strHTA_Temp)
          
          ' *** Delete each file in "%temp%\HTA"
          Set oHTA_Temp = objFSO.GetFolder(strHTA_Temp)
          For Each oFile In oHTA_Temp.Files
            oFile.Delete
          Next
          Set oHTA_Temp = Nothing
          
          ' *** BrowseForFolder dialog
          Set oFolder = objShellApp.BrowseForFolder(&H0, "Please select a folder.", &H0010 + &H0001)
          If Not TypeName(oFolder) = "Nothing" Then
            selctedFolderName = oFolder.Self.Path
          End if
          Set oFolder = Nothing
    
          ' *** Write the chosen folder name to "%temp%\HTA\path.txt"
          Set objTextStream = objFSO.OpenTextFile(strHTA_Temp & "\path.txt", fsoForWriting, True)
          objTextStream.WriteLine selctedFolderName
          objTextStream.Close
          Set objTextStream = Nothing
    
          ' *** Iterate over all check boxes and write in "%temp%\HTA\option*.txt" if checked
          ' (You could change the name properties of the check boxes if you would like to have another text in the files.)
          num = 0
          For Each objCBox In check
            num = num + 1
            If objCBox.Checked Then
              Set objTextStream = objFSO.OpenTextFile(strHTA_Temp & "\option" & num & ".txt", fsoForWriting, True)
              objTextStream.WriteLine objCBox.name
              objTextStream.Close
              Set objTextStream = Nothing
            End If
          Next
          
          ' *** Run the batch file
          objWshShell.Run "test.bat"
    
          ' *** Destroy the used objects
          Set objWshShell = Nothing
          Set objFSO = Nothing
          Set objShellApp = Nothing
    
        end sub
      </script>
      
      <body background=cf2.jpg BGPROPERTIES=FIXED>
        <div style="border:2px solid black;background:transperent;width:350px;hight:100px;padding:5px;position:absolute;top:175px;left:250px">
          <h1>Which Modifications to CrossFire would you like to remove?</h1>
        </div>
        <div style="position:absolute;top:360px;left:320px">
          <input id="check" type="checkbox" name="sound"> Radio Sounds<br>
          <input id="check" type="checkbox" name="bg"> Login Background<br>
          <input id="check" type="checkbox" name="bgm"> Background Music<br>
          <input id="check" type="checkbox" name="ui"> User Interface<br>
          <input id="check" type="checkbox" name="km"> Kill Marks<p>
          <input id="runbutton" class="button" type="button" value="Run" name="run_button" onClick="test">
        </div>
      </body>
    </html>
    
    Regards
    GermanOne
     
  27. red death68

    red death68 Command Sergeant Major

    very useful tips since i dont know much about vbs or hta i used what bit of coding i found worked over and over again which like you said is a mess

    can you maybe provide some links to some good begginers guides or something to that effect video,text, i reallydont care what i just wanna learn this stuff
     
  28. GermanOne

    GermanOne Guest

    Basically HTA is the same as HTML. If you found a good HTML tutorial, you could use it for HTA as well.
    For all M$ related things I propose to use the MSDN (Microsoft Developer Network).
    HTA
    VBScript

    And for good examples how to use VBScript in HTA you should download HAT Helpomatic.

    Hope that helps
    GermanOne
     
  29. red death68

    red death68 Command Sergeant Major

    anything would help lol thanks again german ill save those and start reading soon
     

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