need more help with hta/vbs

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

  1. red death68

    red death68 Command Sergeant Major

    ok so since my uninstallers down to just needing the batch files written i decided to start a new project today to make a hta that lets you change the picture that shows up behind the login screen(that normaly ugly plain blue one) i have the registry value and all but im having trouble. I have no idea how to make the input from my file selection box be used for the path of the picture. after i get that solved it should be quite easy heres what i have so far


    Code:
    <html>
      <head>
        <title>Login Background Modifier</title>
        <HTA:APPLICATION 
             ID="Login Modifier"
             APPLICATIONNAME="Login background Modifier"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
    
        Set objDialog = CreateObject("UserAccounts.CommonDialog")
    objDialog.Filter = "Image Files|*.bmp"
    objDialog.FilterIndex = 1
    objDialog.InitialDir = "C:\"
    intResult = objDialog.ShowOpen
    If intResult = 0 Then
    Exit Sub
    End If
    
        end sub
      </script>
      
      <body>
        
        </div>
          <input type="button" value="Choose Picture" name="run_button" onClick="test">    
        </div>
      </body>
    </html>
    basicly what i want it to do is take the path from the file selected and then save it so i can then later run a batch hidden
    that will copy the picture to a differnt directory so the user wont accidently delete the file and then take the new location and add it to the path of the registry key that controls this
     
  2. GermanOne

    GermanOne Guest

    Well, since I'm on Win7 the ActiveX components for the CommonDialog isn't available anymore. For that reason I have to work with the input type "file" which you normally would use to choose a file for uploads. It's hidden to make it look like your hta window, but the dialog box is completely different and less comfortable :(
    How ever, this should work:
    Code:
    <html>
      <head>
        <title>Login Background Modifier</title>
        <HTA:APPLICATION 
             ID="Login Modifier"
             APPLICATIONNAME="Login background Modifier"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          strOutFile = "test.txt"
    
          Set oFSO = CreateObject("Scripting.FileSystemObject")
          hiddenInput.click
          strChoosenFile = hiddenInput.value
          If oFSO.FileExists(strChoosenFile) Then
            If LCase(oFSO.GetExtensionName(strChoosenFile)) = "jpg" Then
              Set oOutFile = oFSO.OpenTextFile(strOutFile, 2, True)
              oOutFile.Write strChoosenFile
              oOutFile.Close
            End If
          End If
          Set oFSO = Nothing
        end sub
      </script>
    
      <body>
        <div style="position:absolute; visibility:'hidden';">
          <input type="file" ID="hiddenInput">
        </div>
        <div>
          <input type="button" value="Choose Picture" name="run_button" onClick="test">
        </div>
      </body>
    </html>
    
    Regards
    GermanOne
     
  3. PC-XT

    PC-XT Master Sergeant

    You should be able to use the code:
    chr(34)&objDialog.filename&chr(34)
    as the picture file name in your batch file, like:
    batchfile.writeLine "copy /Y "&chr(34)&objDialog.filename&chr(34)&" c:\bgpic\bg.bmp"
    Then, add c:\bgpic\bg.bmp or whatever filename you use to the registry.

    Haha... I missed GermanOne's post. Either should work. Use what you are most comfortable with. If you want it to work on win7, his is probably better. I didn't know they took out the control. :(
     
    Last edited: Apr 19, 2011
  4. GermanOne

    GermanOne Guest

    @PC-XT
    As far as I remember red death68 doesn't work on Win7, so I'm virtually certain he could act on your suggestion.
    BTW: I thought I could predefine the file type for my solution, because the "accept" attribute belongs to the HTML 4.01 standard. It's a weird glitch that none of the browsers support it as you can find here :confused

    Regards
    GermanOne
     
  5. red death68

    red death68 Command Sergeant Major

    yes i am working on xp and i don't know if the registry value is even the same for windows 7 but i do know that the login background is changable in windows 7 and the changer is built into the os last i heard

    one question german with you code how would i make it so only .bmp is available as file type since that the only file type that the background can be?
     
  6. GermanOne

    GermanOne Guest

    Well, that's what I wrote in my last post. There is a possibility but it's not supported by any of the browsers (basically mshta.exe works with the components of Internet Explorer).
    The only thing you could do is to check whether the file extension is "bmp" after you choose the file. I did it for extension "jpg" in my example.
    Sorry but I don't have a better solution and I'm not able to test PC-XT's suggestion.

    Regards
    GermanOne
     
  7. red death68

    red death68 Command Sergeant Major

    so if i switch the line "If LCase(oFSO.GetExtensionName(strChoosenFile)) = "jpg" Then"

    to say "If LCase(oFSO.GetExtensionName(strChoosenFile)) = "bmp" Then"

    instead then it should verify bitmap?
     
  8. GermanOne

    GermanOne Guest

    Exactly. And the path will only been written to the file if the extension is bmp.
    But you cannot avoid that the user selects another file type. That was what I tried to explain.

    Regards
    GermanOne
     
  9. red death68

    red death68 Command Sergeant Major

    i think to avoid miss select as well i could propably add a loop and a message box if bmp is not selected(lets hope i can do that much myself..... man i gotta learn vbs more lol)
     
  10. GermanOne

    GermanOne Guest

    Basically you could write an infinite loop with some interruption criterions. Have a look at this:
    Code:
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          strOutFile = "test.txt"
    
          Set oFSO = CreateObject("Scripting.FileSystemObject")
    
          Do
            hiddenInput.click
            strChoosenFile = hiddenInput.value
            If oFSO.FileExists(strChoosenFile) Then
              If LCase(oFSO.GetExtensionName(strChoosenFile)) = "bmp" Then
                Set oOutFile = oFSO.OpenTextFile(strOutFile, 2, True)
                oOutFile.Write strChoosenFile
                oOutFile.Close
                Exit Do
              Else
                MsgBox "Please select .bmp files only!", vbCritical, "Wrong File Type"
              End If
            Else
              Exit Do
            End If
          Loop
    
          Set oFSO = Nothing
        end sub
      </script>
    
    The Do is an infinite loop in this case.
    In the outer If I check whether the chosen file exists. Actually this seems senseless, but its a trick to find out whether the user clicked on the cancel button ;) That means here we need an Else statement to interrupt the loop.
    In the inner If I check whether the chosen file has extension .bmp. If so, do your stuff and interrupt the loop. Otherwise show the message box and loop again.

    Hope that helps
    GermanOne
     
  11. red death68

    red death68 Command Sergeant Major

    it keeps saying object required hiddenInput
     
  12. GermanOne

    GermanOne Guest

    It's only the script tag for my example before. The entire code would look like that:
    Code:
    <html>
      <head>
        <title>Login Background Modifier</title>
        <HTA:APPLICATION 
             ID="Login Modifier"
             APPLICATIONNAME="Login background Modifier"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          strOutFile = "test.txt"
    
          Set oFSO = CreateObject("Scripting.FileSystemObject")
    
          Do
            hiddenInput.click
            strChoosenFile = hiddenInput.value
            If oFSO.FileExists(strChoosenFile) Then
              If LCase(oFSO.GetExtensionName(strChoosenFile)) = "bmp" Then
                Set oOutFile = oFSO.OpenTextFile(strOutFile, 2, True)
                oOutFile.Write strChoosenFile
                oOutFile.Close
                Exit Do
              Else
                MsgBox "Please select .bmp files only!", vbCritical, "Wrong File Type"
              End If
            Else
              Exit Do
            End If
          Loop
    
          Set oFSO = Nothing
        end sub
      </script>
    
      <body>
        <div style="position:absolute; visibility:'hidden';">
          <input type="file" ID="hiddenInput">
        </div>
        <div>
          <input type="button" value="Choose Picture" name="run_button" onClick="test">
        </div>
      </body>
    </html>
    
    "hiddenInput" is the ID of the file input tag. In case you renamed it the script can't find it.

    Regards
    GermanOne
     
  13. red death68

    red death68 Command Sergeant Major

    o i c thanks man it works perfect i really need to learn more vbs lol
     
  14. GermanOne

    GermanOne Guest

    Not that perfect. I found a bug. If you choose a wrong file type and click on cancel next time then it will not exit the loop.
    How ever, I fixed it:
    Code:
    <html>
      <head>
        <title>Login Background Modifier</title>
        <HTA:APPLICATION 
             ID="Login Modifier"
             APPLICATIONNAME="Login background Modifier"
             SCROLL="no"
             SINGLEINSTANCE="yes"
             WINDOWSTATE="maximize"
             MaximizeButton="no"
             MinimizeButton="yes"
             Border="thin"
        >
      </head>
      
      <SCRIPT LANGUAGE="VBScript">
        window.resizeto 800, 620
        
        sub test
          strOutFile = "test.txt"
    
          Set oFSO = CreateObject("Scripting.FileSystemObject")
    
          Do
            hiddenForm.reset
            hiddenForm.hiddenInput.click
            strChoosenFile = hiddenForm.hiddenInput.value
            If oFSO.FileExists(strChoosenFile) Then
              If LCase(oFSO.GetExtensionName(strChoosenFile)) = "bmp" Then
                Set oOutFile = oFSO.OpenTextFile(strOutFile, 2, True)
                oOutFile.Write strChoosenFile
                oOutFile.Close
                Exit Do
              Else
                MsgBox "Please select .bmp files only!", vbCritical, "Wrong File Type"
              End If
            Else
              Exit Do
            End If
          Loop
    
          Set oFSO = Nothing
        end sub
      </script>
    
      <body>
        <form ID="hiddenForm" style="position:'absolute'; visibility:'hidden';">
          <input type="file" ID="hiddenInput">
        </form>
        <div>
          <input type="button" value="Choose Picture" name="run_button" onClick="test">
        </div>
      </body>
    </html>
    
    Regards
    GermanOne
     
  15. red death68

    red death68 Command Sergeant Major

    wow i completly missed that lol

    glad you double checked or i woulda been scratching my head in a week or so lol
     

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