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 ...
Related
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!
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>
I have an HTA that I want to pop into focus every hour as a reminder in case it's minimised or has the focus taken away from it. The problem I'm having is there's a Sub that's not recognising variables. I'll post the code and then explain:
<HTML>
<HEAD>
<style type="text/css">
p {font-family: 'Segoe UI Light'; font-size: 12pt}
td {font-family: 'Segoe UI Light'; font-size: 12pt}
input {font-family: 'Segoe UI Light'; font-size: 12pt}
body {font-family: 'Segoe UI Light'; font-size: 12pt; color: #4D4C5C; background-color: white}
</style>
<TITLE>QT MOE Upgrade</TITLE>
<HTA:APPLICATION ID="MOEUpgrade"
APPLICATIONNAME="MOE Upgrade"
BORDER="dialog"
SCROLL="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="no">
</HEAD>
<SCRIPT LANGUAGE="VBScript">
Dim iTimerID, strProcName, strProcID
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE CommandLine LIKE '%MOEUpgrade.hta%'")
For Each objProcess in colProcesses
strProcName = objProcess.Name
strProcID = objProcess.ProcessID
Next
Sub Window_OnLoad
Set colItems = objWMIService.ExecQuery("Select * From Win32_VideoController WHERE AdapterDACType='Internal'")
For Each objItem in colItems
intHorizontal = objItem.CurrentHorizontalResolution
intVertical = objItem.CurrentVerticalResolution
Next
intLeft = (intHorizontal-1024)/2
intTop = (intVertical-600)/2
self.resizeto 1024,600
self.moveTo intLeft,intTop
self.focus()
iTimerID = window.setInterval("NagWindow",5000)
End Sub
Sub NagWindow
MsgBox strProcName & VBCRLF & strProcID
End Sub
Sub StartUpgradeNow
If MsgBox ("Are you sure you want to start the upgrade now?",vbYesNo+vbExclamation,"Confirm Upgrade") = vbYes Then
self.close()
End If
End Sub
</SCRIPT>
<BODY>
<div align="justify">
<p>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</p>
</div>
<div align="center">
<br>
<span class="tooltip" title="Click OK to start the upgrade now"><input type="button" name="OKButton" value=" OK " onClick="StartUpgradeNow" style="font-family: 'Segoe UI Light'"></span>
</div>
</BODY>
</HTML>
If you're so inclined, you can save this code as MOEUpgrade.hta and it should run for you without any issues. This code works and pops up a message box showing the strProcName and strProcID variables as expected, but when I change line 58 inside the NagWindow Sub to:
objShell.AppActivate strProcName.strProcID
It fails with an object required ('strProcName') error. Does anyone know why the variables are not being recognised when using the objShell function please but are when using MsgBox?
The reason for the error
Object required: 'strProcName'
is because you try to call strProcID as an object property of strProcName but it is clear from the code that both strProcName and strProcID are string variables.
If you are trying to use AppActivate with the Window Process Id you likely want to try;
Call objShell.AppActivate(strProcID)
Useful Links
WshShell.AppActivate doesn't seem to work in simple vbs script
Use AppActivate to change the active window
I have started to learn VBScript and I want to validate a HTML form / web page elements using VBScript .
Can anyone tell me if it is possible to refer an external HTML form/web page to the VBScript code and validate it's elements inside the script?
Like, I want to add a form reference or location (designed in HTML) in VBScript and validate its textbox, checkbox and submit it.
FYI, I can validate a HTML form simply by adding the VBScript part on the HTML code.
Example:
<html>
<head>
...
</head>
<body>
<script type="text/vbscript">
...
</SCRIPT>
<FORM NAME="Form1">
...
</FORM>
</body>
</html>
<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Submit_OnClick
Dim TheForm
Set TheForm = Document.ValidForm
If IsNumeric(TheForm.Text1.Value) Then
If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
MsgBox "Please enter a number between 1 and 10."
Else
MsgBox "Thank you."
End If
Else
MsgBox "Please enter a numeric value."
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>Simple Validation</H3><HR>
<FORM NAME="ValidForm">
Enter a value between 1 and 10:
<INPUT NAME="Text1" TYPE="TEXT" SIZE="2">
<INPUT NAME="Submit" TYPE="BUTTON" VALUE="Submit">
</FORM>
</BODY>
</HTML>
I want to validate a HTML form / web page elements using VBScript
This is very bad decision. Your solution will work only under Internet Explorer.
On client side strongly recomend to use JavaScript
On server sode of couse VBScript.
This worked in windows 2008 server R2, but not on windows 2012 server R2. What is the equivalent in 2012?
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AD Manager</title>
<script language="vbscript" type="text/vbscript">
<!--
Sub Validate
Dim objSysInfo, owsh
Set objSysInfo = CreateObject("ADSystemInfo")
Set owsh = CreateObject("WScript.Network")
username = owsh.username
domain2 = objSysInfo.DomainShortName <==== This is the line that fails
document.getElementById("UserName").value = domain2 & "\" & username
document.getElementById("Password").value = "1234"
document.getElementById("frmADManager").submit()
End Sub
//-->
</script>
</head>
<body onload="Validate()">
<form id="frmADManager" action="ProcessLogin.asp" method="post">
<input type="hidden" id="UserName" name="UserName" value="" />
<input type="hidden" id="Password" name="Password" value="" />
</form>
</body>
</html>
You appear to be mixing VBScript with JavaScript in a possibly awkward way.
Here is one method that should work with either OS. There are many ways you could achieve this in a single language. I am surprised that the code you were using actually works on Windows 2008 R2 (yes, I know it does - I just tested it).
Take a look at this article for more information on how you can mix client side JavaScript with VBScript on the same page: http://msdn.microsoft.com/en-us/library/aa260861(v=vs.60).aspx
In this example, we have split your VBScript and JavaScript into separate scripts, where one calls the other.
Tested to work on Windows 2008 R2 and Windows 2012 Server.
NOTE: I do not recommend storing passwords like this in a production environment. Anyone can intercept this password as it loading client side. Presumably you are also using HTTP - the password will be visible in clear text. Consider a more secure alternative - as I am not sure why you are doing this or where you are feeding these credentials, I can't offer you a suggestion as to how to change things.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>AD Manager</title>
<script language="vbscript">
function getDomainInfo()
Dim objSysInfo, owsh
Set objSysInfo = CreateObject("ADSystemInfo")
Set owsh = CreateObject("WScript.Network")
username = owsh.username
getDomainInfo = objSysInfo.DomainShortName & "\" & owsh.username
End function
</script>
<script language="javascript">
function validate()
{
document.getElementById("UserName").value = getDomainInfo();
document.getElementById("Password").value = "1234";
document.getElementById("frmADManager").submit();
}
</script>
</head>
<body onload="validate()">
<form id="frmADManager" action="ProcessLogin.asp" method="post">
<input type="hidden" id="UserName" name="UserName" value="" />
<input type="hidden" id="Password" name="Password" value="" />
</form>
</body>
</html>