Object Doesn't support this method - vbscript

I am getting a
Object doesn't support this method
when I click the start button. It says the line is;
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button">
I believe it actually may be somewhere in my vbscript. When I click on the start button it depending on whether the strPath is entered and the checkbox is checked it should run the program to install, or tell me that I need to enter the strPath or check a box.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tombstone USD #1 - Software Installer</title>
<HTA:APPLICATION
APPLICATIONNAME = "Software Installer"
ICON = "images\districtlogo.ico"
ID = "NAME"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE="normal"
SCROLL = "no"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "yes"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "no"
NAVIGABLE = "no"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
/>
<script type="text/javascript">
<!--Resolution//-->
window.resizeTo(600,750);
</script>
<script language="VBScript">
Sub Start_Button()
Dim strAnswer,strPath, objNetwork
Set objNetwork = CreateObject("WScript.Network")
strAnswer = ""
strPath=""
If chkEset.Checked Then strAnswer = "Eset"
'If strPath is empty then nothing was checked.
If strPath = "" Then
Window.Alert "Please input Path location!"
End If
'If strAnswer is empty then nothing was checked.
If strAnswer = "" Then
Window.Alert "Please Make an Selection!"
Exit Sub
End If
Window.Alert "Done!"
End Sub
</script>
</head>
<body style="background-color:#E6E6FA">
<center>
<img src="images\districtlogo.png" alt="Logo" height="100" width="100"/>
<h1>Software Installer</h1>
</center>
<form name="MainMenu" action="" method="">
<label for="sPath">Drive Letter or File Path:</label><input type="text" size="60" id="sPath" name="sPath"></td>
<br />
<label for="Eset">ESet AntiVirus</label></td><input type="checkbox" id="Eset" name="chkEset">
<br />
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button">
<br />
<input type="reset" value="Reset">
</form>
</body>
</html>
I'm currently just trying to get this run with the one program. This is a proof of concept test.

Ok, since I figured it out I thought I would add the completed script below. All this does is check to see if the strPath is filled in and if the checkbox is checked. Next step is to get it to run a program that corresponds to the checkbox.
The way I fixed it was by changing the <input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button"> to <input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button()">.
I also realized that the Form wasn't actually assigning the values to the script and created TheForm value and assigned it to the MainMenu form. I then had to add that value to all the existing values.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tombstone USD #1 - Software Installer</title>
<HTA:APPLICATION
APPLICATIONNAME = "Software Installer"
ICON = "images\districtlogo.ico"
ID = "NAME"
BORDER = "thick"
CAPTION = "yes"
SHOWINTASKBAR = "yes"
SINGLEINSTANCE = "yes"
SYSMENU = "yes"
WINDOWSTATE="normal"
SCROLL = "no"
VERSION = "1.0"
INNERBORDER = "yes"
SELECTION = "yes"
MAXIMIZEBUTTON = "no"
MINIMIZEBUTTON = "no"
NAVIGABLE = "no"
CONTEXTMENU = "yes"
BORDERSTYLE = "normal"
/>
<script type="text/javascript">
<!--Resolution//-->
window.resizeTo(600,750);
</script>
<script language="VBScript">
Sub Start_Button()
Dim strAnswer,strPath, objNetwork,TheForm
Set objNetwork = CreateObject("WScript.Network")
Set TheForm = Document.MainMenu
strAnswer = ""
strPath = ""
If TheForm.chkEset.Checked Then strAnswer = "Eset"
'If strPath is empty then nothing was checked.
If TheForm.strPath = "" Then
Window.Alert "Please input Path location!"
Exit Sub
End If
'If strAnswer is empty then nothing was checked.
If strAnswer = "" Then
Window.Alert "Please Make an Selection!"
Exit Sub
End If
Window.Alert "Done!"
End Sub
</script>
</head>
<body style="background-color:#E6E6FA">
<center>
<img src="images\districtlogo.png" alt="Logo" height="100" width="100"/>
<h1>Software Installer</h1>
</center>
<form name="MainMenu" action="" method="">
<label for="Path">Drive Letter or File Path:</label><input type="text" size="60" id="Path" name="strPath"></td>
<br />
<label for="Eset">ESet AntiVirus</label></td><input type="checkbox" id="Eset" name="chkEset">
<br />
<input type="button" name="btnStart" id="btnStart" value="Start" onclick="Start_Button()">
<br />
<input type="reset" value="Reset">
</form>
</body>
</html>

Related

How to maintain scroll position when submitting on toggle buttons - one form per toggle button

`I've been searching a lot, and I think the answer to my task is a call to an AJAX function. I'm using classic ASP. Please have in mind that I'm a total newbie. I really need someone to take my hand and tell me what to do. The examples I've found so far doesn't keep the same position on the website on submit. The idea is to press the toggle button (on/off) and save immidiately. That part is working perfectly. But when you have a lot of toggle buttons, and the submit gets you to the top of the page, you have a lot of scrolling down to do after every submit
The folowing is working just fine; either it's on or off. No need to do anything, but to press the toggle button. But if you are way down the webpage, you go way up to the top of the page, and you need to scroll way down to continue where you left off. This is where I want the page to be steady as a rock: Don't do anything on submit. Don't move up, don't move down. Stay put. I hope someone can help.
<%
If Request("mode") = "msgfromadmin" Then
Dim dato10, vUser10
dato10 = Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Time()
vUser10 = SQLEncode(Session("username"))
If Request.Form("msgfromadmin") = Lcase("on") Then
msgfromadmin = 1
Else
msgfromadmin = 0
End If
SQL = Conn.Execute("UPDATE usersettings SET msgfromadmin = " & msgfromadmin & " WHERE username = '" & SQLEncode(Session("username")) & "'")
Response.Redirect("/profile/mysettings/")
End If
%>
<head>
<style>
.switch{position:relative;display:inline-block;width:3.43em;height:1.75em;}
.switch input{opacity:0;width:0;height:0;}
.slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background-color:#ccc;-webkit-transition:.4s;transition:.4s;}
.slider:before{position:absolute;content:"";height:1.26em;width:1.26em;left:0.25em;bottom:0.25em;background-color:white;-webkit-transition: .4s;transition:.4s;}
input:checked + .slider{background-color:#4d72ff;}input:focus + .slider{box-shadow: 0 0 0.063em #c4cbe7;}
input:checked + .slider:before{-webkit-transform:translateX(1.625em);-ms-transform:translateX(1.625em);transform:translateX(1.625em);}
.slider.round{border-radius:2.125em;}.slider
.round:before{border-radius:50%;}
</style>
</head>
<html>
<body>
<form name="msgfromadmin" action="/profile/mysettings/" method="post">
<input type="hidden" name="mode" value="msgfromadmin">
<div class="col-12 form-group row mt-4">
<div class="col-1 form-group text-center">
<label class="switch">
<input type="checkbox" name="msgfromadmin" onChange="this.form.submit();"<% If RSchosenSetting("msgfromadmin") = 1 Then %> checked<% End If %>>
<span class="slider"></span>
</label>
</div>
<div class="col-11 form-group">
Send a mail when there's a message from admin
</div>
</div>
</form>
</body>
</html>
Is it something like this you want??
You will have to obviously do the database connections etc on the submitpage.asp
I added the loop to the text and slider to generate a page that is longer.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>msgfromadmin</title>
</head>
<style>
.switch{position:relative;display:inline-block;width:3.43em;height:1.75em;}
.switch input{opacity:0;width:0;height:0;}
.slider{position:absolute;cursor:pointer;top:0;left:0;right:0;bottom:0;background-color:#ccc;-webkit-transition:.4s;transition:.4s;}
.slider:before{position:absolute;content:"";height:1.26em;width:1.26em;left:0.25em;bottom:0.25em;background-color:white;-webkit-transition: .4s;transition:.4s;}
input:checked + .slider{background-color:#4d72ff;}input:focus + .slider{box-shadow: 0 0 0.063em #c4cbe7;}
input:checked + .slider:before{-webkit-transform:translateX(1.625em);-ms-transform:translateX(1.625em);transform:translateX(1.625em);}
.slider.round{border-radius:2.125em;}.slider
.round:before{border-radius:50%;}
</style>
</head>
<html>
<body>
<form name="msgfromadmin" action="msgfromadmin.asp" method="post">
<input type="hidden" name="mode" value="msgfromadmin">
<div class="col-12 form-group row mt-4">
<%for i = 1 to 100 %>
<div class="col-1 form-group text-center">
<label class="switch">
<input type="checkbox" name="msgfromadmin<%= i %>" id="msgfromadmin<%= i %>" onChange="loadXMLDoc('<%= i%>','message <%= i%> from admin')" <% If request("msgfromadmin" & i) = "on" Then %> checked<% End If %>>
<span class="slider"></span>
</label>
</div>
<div class="col-11 form-group" id=adminmessage<%=i%>>
Send a mail when there's a message from admin
</div>
<% next %>
</div>
</form>
<script>
function loadXMLDoc(incoming, incoming2) {
var demoChecked = document.getElementById("msgfromadmin"+ incoming).checked;
if (demoChecked == true) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("adminmessage"+incoming).innerHTML = this.responseText;
}
};
xhttp.open("post", "SubmitPage.asp?msgfromadmin="+ incoming +"&message="+incoming2, true);
xhttp.send();
document.getElementById("adminmessage"+incoming).innerHTML = "Mail sent to admin";
} else {
document.getElementById("adminmessage"+incoming).innerHTML = "Send a mail when there's a message from admin";
}
}
</script>
</body>
</html>
and the SubmitPage.asp
<%
If Request("msgfromadmin") <> "" then
Dim dato10, vUser10
dato10 = Day(Date) & "/" & Month(Date) & "/" & Year(Date) & " " & Time()
response.write "Mail sent to admin at " & dato10
' vUser10 = SQLEncode(Session("username"))
' SQL = Conn.Execute("UPDATE usersettings SET msgfromadmin = " & msgfromadmin & " WHERE username = '" & SQLEncode(Session("username")) & "'")
End If
%>

Passing Command Line Arguments To HTA Application

I have an HTA application I would like to run from a Command Prompt.
I've tried everything I could possibly think of and it's just not working!
It just launches the application and that's it.
From Command Prompt I run it with the full path as such:
C:\users\xxx\script.hta "arg1" "arg2"
which is essentially what I'm trying to accomplish here?
I've gone through numerous pages on here with similar issues but I guess I'm just not putting it together properly!
Here is the code:
<html>
<head>
<HTA:Application
ID="oHTA"
APPLICATIONNAME="MSI-BUILD"
Border = "NO"
Singleinstance ="YES"
BorderStyle = "Complex"
ShowInTaskBar = "YES"
MaximizeButton = "No"
MinimizeButton = "No"
scroll="NO"
VERSION="2"
/>
<script language = "VBScript">
Sub RunProgram
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strCurDir= WshShell.CurrentDirectory
StrARG = MSINAME.value
StrARG3 = FPath.value
strFolder = "D:\SMPSS\PROJECTS\"&MSINAME.value
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strFolder) Then
oFSO.CreateFolder strFolder
End If
objShell.Run "D:\SMPSS\MSI-2\1-newproject.vbs " & StrARG , 0, True
window.close()
End Sub
Sub Window_onLoad
Self.Resizeto 890, 300
document.title = oHTA.applicationName & " v" & oHTA.version
arrCommands = Split(oHTA.commandLine, chr(34))
For i = 3 to (Ubound(arrCommands) - 1) Step 2
Select Case arrCommands(i)
Case "arg1"
myarg1 = "This is argument 1."
Case "arg2"
myarg2 = "This is argument 2."
End Select
Next
MsgBox myarg1
MsgBox myarg2
End Sub
</script>
</head>
<body style="background-color: #b2b2f4">
<td>MSI-NAME:</td>
<td> </td>
<td style="overflow:hidden">
<td style="resize:none">
<td style="text-align:right">
<td style="width: 325px"><input type = "text" name = "MSINAME" id = "MSINAME" size="50" /></td>
<p>
<td>PATH:</td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="overflow:hidden"></td>
<td style="resize:none"></td>
<td style="text-align:right"></td>
<td style="width: 325px"><input type = "text" name = "FPath" id = "FPath" value ="" size="50" /></td>
<td> </td>
</p>
<p>
<input id='submit' type="button" value="Submit" onClick="RunProgram"></td>
</p>
</body>
</html>
I figured it out the issue was having <meta http-equiv="x-ua-compatible" content="ie=9"> in my code once removed everything started working as it should thanks! Also the file wasn't saved as ANSI so it was having invalid character errors. Everything is working great now!

Uploading a text file via POST method

I've been working on this problem for about a month now. I've seen dozens of web pages on the POST method and I just can't figure out how to use it.
I have this HTML form that posts data and a file up to a web site. this HTML form works great:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample Post Request</title>
</head>
<body>
<form action="https://xxx.xxx.com//trackit/file/upload"
method="post" enctype="multipart/form-data">
<div>
<p>
File Name<select name="name">
<option value="" disabled="disabled" selected="selected">Select file name</option>
<option value="Customer">Customer</option>
<option value="Shipment">Shipment</option>
</select>
</p>
<p>
File Date:<input type="text" name="date"> format : YYYYMMDD
</p>
<p>
Upload File: <input type="file" name="file" />
</p>
</div>
<input type="submit" value="Upload It" />
</form>
</body>
</html>
However, I'm trying to automate this so I don't have to use the form. Here is what I have so far:
OPTION EXPLICIT
DIM sFile, sURL, sDate, sName, objStream
'File Type
sName = "Shipment"
'File Date YYYYMMDD
sDate = "20150717"
' File we are uploading
sFile = "C:\shipment.txt"
sBoundary = "|-O-|"
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeText
objStream.Mode = adModeReadWrite
objStream.Open
objStream.LoadFromFile sFile
'Sending the data over HTTP Post
Set objHttp = CreateObject("MSXML2.XMLHTTP")
objHttp.Open "POST", "https://xxx.xxx.com//trackit/file/upload", False
objHttp.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" + sBoundary
objHttp.Send "name=" + sName
objHttp.Send "date=" + sDate
Any help will be appreciated.

Code Error 800A01A8 - Object Required

I have a HTA file that open a text box alows user to enter path to a folder then save it to a text file.
But when I trying to use second button to run a batch, it gives me an error code
Code Error 800A01A8 - Object Required : Wscript
<html>
<head>
<title>Files Sync </title>
<HTA:APPLICATION
APPLICATIONNAME="Files Sync"
ID="RY"
VERSION="1.0"/>
</head>
<script language="vbscript">
Sub WriteTxt_OnClick()
Dim fso, txt
Set fso = CreateObject("Scripting.FileSystemObject")
Set txt = fso.CreateTextFile("\\fs-02\C$\ntfs3\scripts\MexSync\000.txt")
txt.WriteLine document.Submitted_Link_To_Mex.body.value
MsgBox "File Submitted",64,"Selection"
End Sub
Sub SYNC_onClick()
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe /c C:\work\RLTP_SYNC_MEX\RunChangePS1.bat", 0
' 0 => hide
MsgBox("Success")
End Sub
</script>
<H2>Copy And Paste The Folder Path To Here </H2>
<body>
<form name="Submitted_Link_To_Mex">
<textarea name="body" cols="150" rows="20">
</textarea>
</form>
<br>
<input type="button" value="1. SUBMIT" name="WriteTxt">
<input type="Button" value="2. SYNC" name="SYNC">
<input type="Button" value="3. CLOSE" name="button2" onClick="close" class="button">
</div>
</body>
</html>
I can't find out why....did some research but no luck at all
Any suggestion?
The WScript object your line
Set WshShell = WScript.CreateObject("WScript.Shell")
tries to use does not exist in a HTA (it is provided by the w|cscript.exe hosts). As VBScript (the language itself) provides its own CreateObject function, just use
Set WshShell = CreateObject("WScript.Shell")
You need a trailing \ on your replacement text else you have DataAppData
Replace(txt, "K:\", "D:\Data\")
Also response.write is for ASP ...

Form validation in an HTA file

How can I perform a simple validation on this HTA form to make sure that data is inputted and an option is selected? This should be simple, I'm not sure what I'm missing.
Any answers or suggestions would be appreciated.
Thanks.
<html><head><title>Write data to text file</title>
<HTA:APPLICATION
border="thin"
borderStyle="normal"
caption="yes"
maximizeButton="no"
minimizeButton="yes"
showInTaskbar="yes"
innerBorder="yes"
navigable="yes"
scroll="auto"
scrollFlat="yes" />
<script language="javascript">
window.resizeTo(480,150)
function Writedata()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var write_id;
write_id = document.getElementById('write_id').value ;
alert('The data has been written to \n' + write_id);
var s = fso.OpenTextFile(write_id, 8, true);
s.WriteLine(document.getElementById('name_id').value);
s.Close();
}
</script>
</head>
<body>
<table>
<tr>
<h3>Input some information</h3>
<form>
<td>Input: </td><td><input type="text" name="name" value="" id="name_id"></td>
<td><select id="write_id">
<option name="write" value="">Select an Option</option>
<option name="write" value="C:\temp\option1.txt">Option1</option>
<option name="write" value="C:\temp\option2.txt">Option2</option>
</select></td>
<td><input type="button" onclick="Writedata()" value="submit"></td>
</form>
</tr>
</table>
</body>
</html>
I was stumped, so I rewrote this in vbscript.
I have included bits of what I did to give you an idea of how to write to a text file, and validate your form with an HTA.
The vbscript:
Set wshShell = CreateObject( "WScript.Shell" )
strSender = wshShell.ExpandEnvironmentStrings( "%USERNAME%" ) ' Get the current Username
Dim Checkmark
Sub Validate
If form.Flag.checked = True Then ' Find out if your Checkbox is checked
Checkmark = "*"
Else
Checkmark = ""
End IF
If form.field1.value = "" Then ' Validate the form
alert "Please enter an number!", "0", "Title"
ElseIf IsNumeric(form.field1.value) = False Then
alert "Please enter a valid number!", "0", "Title"
ElseIf form.drop_down1.Value = "" Then
alert "Please select a save location!", "0", "Title"
ElseIf form.field1.value < 100000 Then
alert "Please enter a six digit number!", "0", "Title"
ElseIf form.field1.value > 999999 Then
alert "Please enter a six digit number!", "0", "Title"
Else
SaveData
End If
End Sub
Sub SaveData ' Write data to a text file
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(form.drop_down1.Value) Then
Set objFile = objFSO.OpenTextFile(form.drop_down1.Value, 8)
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now ' fields that will be written
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
Else
Set objFile = objFSO.CreateTextFile(form.drop_down1.Value) ' If file does not exist, create file
strLine = form.field1.value & vbtab & Checkmark & vbtab & strSender & vbtab & Now
objFile.WriteLine strLine
MsgBox "The Information was successfully written to the file.", "0", "Title"
objFile.Close
End If
End Sub
The HTML:
<form name="form">
<h2>Imput</h2>
<tr><td><lable>Data: </lable></td><td><input type="text" name="field1" size="25"></td> </tr>
<tr><td><lable>Save Location: </lable></td><td><select name="drop_down1">
<option type="text" name="select" value="">Select an option</option>
<option type="text" value="SavePath1...">SavePath1</option>
<option type="text" value="SavePath2...">SavePath2</option>
<option type="text" value="SavePath3...">SavePath3</option>
</select></td><td><input type="checkbox" name="Flag" value="">Flag *</td></tr>
</table>
<input type="button" value="Submit" onClick="Validate">
<input type='reset' id='ResetFields' value='Clear Fields' />
</form>

Resources