vbs help needed

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

  1. red death68

    red death68 Command Sergeant Major

    ok im still working on my uninstaller it worked great untill i found it was missing files and didnt copy to right location(batch issue i fixed lol) but now iv decided to change alot and im having trouble i decided to add a msgbox to the start but i dont know how to make it read if the cancel button has been pressed and and if so cancel the script but leave the hta window its running from intact any idea's?
     
  2. GermanOne

    GermanOne Guest

    I'm sure you used the msdn language reference as I suggested last time :-D
    For that reason I'm also sure you figured out that MsgBox is a function that returns a numeric value depending on the button you've clicked.

    Okay okay, here's a small example that shows you 3 different possibilities how to handle it:
    Code:
    <html>
      <head>
        <title>Test</title>
        <HTA:APPLICATION>
      </head>
      
      <SCRIPT LANGUAGE="VBScript">   
        sub test1
          out.innerHTML = ""
          RetVal = MsgBox("Click any button", vbOkCancel + vbExclamation, "Test 1 using ""If""")
          If RetVal <> vbCancel Then
            out.innerHTML = "You did not click on ""cancel""."
          End If
        end sub
    
        sub test2
          out.innerHTML = ""
          RetVal = MsgBox("Click any button", vbOkCancel + vbExclamation, "Test 2 using ""Do""")
          Do While RetVal <> vbCancel
            out.innerHTML = "You did not click on ""cancel""."
            Exit Do
          Loop
        end sub
    
        sub test3
          out.innerHTML = ""
          Select Case MsgBox("Click any button", vbOkCancel + vbExclamation, "Test 3 using ""Select""")
            Case vbCancel
              'do nothing
            Case Else
              out.innerHTML = "You did not click on ""cancel""."
          End Select  
        end sub
      </script>
      
      <body>
        <div id="out" style="border:2px solid black; width:200px; hight:20px";></div>
        <br><br><br>
        <input id="button1" type="button" value="Test 1" onClick="test1">
        <input id="button2" type="button" value="Test 2" onClick="test2">
        <input id="button3" type="button" value="Test 3" onClick="test3">
      </body>
    </html>
    
    Regards
    GermanOne
     
  3. red death68

    red death68 Command Sergeant Major

    ok this is weird when i save the entire code as an hta it works but if i splice 1 example into my code it says object required out


    any idea's?
     
  4. GermanOne

    GermanOne Guest

    Well, the only object I reference in my code is the div with ID "out" where I write in.
    This is only an example how to process the return value of MsgBox, do what ever you want instead of writing an output into a div object.

    Regards
    GermanOne
     
    Last edited by a moderator: Apr 17, 2011
  5. red death68

    red death68 Command Sergeant Major

    well iv kind of got it working but no matter what i click it still calls the vbs at the end 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="Mod Remover.ico"
        >
      </head>
    
     <SCRIPT LANGUAGE="VBScript">   
        window.resizeto 800, 620 
        sub test
         Select Case MsgBox ("Click OK to countinue a message will appear upon completion.", _
    	 vbOKCancel+vbDefultButton1+vbSystemModal, "CF Mod Uninstaller")
            Case vbCancel
              'do nothing	
    		 case else
    		 End Select
    		 Set Objreg = Createobject("Wscript.shell")
          regvalue = objreg.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Cross Fire_is1\InstallLocation") 
          'Reading registry value
          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 regvalue
          objTextStream.Close
          Set objTextStream = Nothing
        
          If Sound.Checked then          
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option1.txt", fsoForWriting, True)
            objTextStream.WriteLine "sound"
            objTextStream.Close
            Set objTextStream = Nothing    
          End If
        
          If bg.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option2.txt", fsoForWriting, True)
            objTextStream.WriteLine "background"
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If bgm.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option3.txt", fsoForWriting, True)
            objTextStream.WriteLine "background music"
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If ui.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option4.txt", fsoForWriting, True)
            objTextStream.WriteLine "user interface"
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          If km.Checked Then
            Set objTextStream = objFSO.OpenTextFile("C:\temp\option5.txt", fsoForWriting, True)
            objTextStream.WriteLine "kill marks"
            objTextStream.Close
            Set objTextStream = Nothing
          End If
        
          Set objFSO = Nothing
          
          objShell.Run "unpack.vbs"
        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>Select the crossfire modifications you would 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>
     
  6. GermanOne

    GermanOne Guest

    Below of Case Else you have to place the code that should been processed if you didn't click the cancel button. End Select quits the select-mode and belongs to the end of the code.
    Try:
    Code:
     <SCRIPT LANGUAGE="VBScript">   
        window.resizeto 800, 620 
        sub test
         Select Case MsgBox ("Click OK to countinue a message will appear upon completion.", _
    	     vbOKCancel+vbDefultButton1+vbSystemModal, "CF Mod Uninstaller")
            Case vbCancel
              'do nothing	
    		    Case Else
        		 Set Objreg = Createobject("Wscript.shell")
              regvalue = objreg.regread("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Cross Fire_is1\InstallLocation") 
              'Reading registry value
              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 regvalue
              objTextStream.Close
              Set objTextStream = Nothing
            
              If Sound.Checked then          
                Set objTextStream = objFSO.OpenTextFile("C:\temp\option1.txt", fsoForWriting, True)
                objTextStream.WriteLine "sound"
                objTextStream.Close
                Set objTextStream = Nothing    
              End If
            
              If bg.Checked Then
                Set objTextStream = objFSO.OpenTextFile("C:\temp\option2.txt", fsoForWriting, True)
                objTextStream.WriteLine "background"
                objTextStream.Close
                Set objTextStream = Nothing
              End If
            
              If bgm.Checked Then
                Set objTextStream = objFSO.OpenTextFile("C:\temp\option3.txt", fsoForWriting, True)
                objTextStream.WriteLine "background music"
                objTextStream.Close
                Set objTextStream = Nothing
              End If
            
              If ui.Checked Then
                Set objTextStream = objFSO.OpenTextFile("C:\temp\option4.txt", fsoForWriting, True)
                objTextStream.WriteLine "user interface"
                objTextStream.Close
                Set objTextStream = Nothing
              End If
            
              If km.Checked Then
                Set objTextStream = objFSO.OpenTextFile("C:\temp\option5.txt", fsoForWriting, True)
                objTextStream.WriteLine "kill marks"
                objTextStream.Close
                Set objTextStream = Nothing
              End If
            
              Set objFSO = Nothing
              
              objShell.Run "unpack.vbs"
         End Select
        end sub
      </script>
    
    Regards
    GermanOne
     
  7. red death68

    red death68 Command Sergeant Major

    worked like a charm man your a life saver
     

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