Would anyone be willing to review my script and give me pointers on my screw ups?
The entire script seems to be working as desired except for any of my:
Wscript.echo lines none of them work, I have them all commented out atm.
I get the error object required Wscript.
I was reading another post on here and it mentioned that Wscript.echo only works for vbs and not hta, what would I use in hta to display messages, just a plain ole msgbox? Anyway I am very new to scripting and this is my first go at it.
I've attached my script if anyone has a minute to give it a once over.
Thank You
LB
<html>
<head>
<title>Tenant Tracker File Utilities</title>
<HTA:APPLICATION
APPLICATIONNAME="Tenant Tracker Application"
ID="TenantTrackerApplication"
VERSION="1.0"/>
</head> <script language="VBScript"> Sub Window_OnLoad
'This method will be called when the application loads
ResetOk = window.MoveTo(500, 200)
ResetOk = window.resizeTo(500, 400)
End Sub Sub btnFullDL()
'This method will be called when button "btnFullDL" is clicked
GetFile "TenantTracker2011Full.msi"
End Sub Sub btnFullInstall()
'This method will be called when button "btnFullInstall" is clicked
Install "TenantTracker2011Full.msi",1
End Sub Sub btnGetUpdate()
Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("Menu.hta")
strThumbDrive = objFSO.GetParentFolderName(objFile)
'This method will be called when button "btnFullUpdate" is clicked
GetFile "TenantTracker2011Update.zip"
End Sub Sub btnRuntime()
'This method will be called when button "btnRuntime" is clicked
installRuntime
End Sub Sub btnInstallUpdate()
'This method will be called when button "btnInstallUpdate" is clicked
BackupFiles strThumbDrive,"C:\Rent Roll\","backup"
Unzip "TenantTracker2011Update.zip", "C:\Rent Roll\"
End Sub Sub btnDemoDL()
'This method will be called when button "btnFullDL" is clicked
GetFile "TenantTracker2011Demo.msi"
End Sub Sub btnDemoInstall()
'This method will be called when button "btnFullInstall" is clicked
Install "TenantTracker2011Demo.msi",2
End Sub Sub btnSendBE()
'This method will be called when button "btnSendBE" is clicked
PutFile "Tenant Tracker 2011_be.accdb"
End Sub Sub btnCancel()
'This method will be called when button "btnFullUpdate" is clicked
Set objFSO = Nothing
Set objShell = Nothing
Set objFile = Nothing
Self.close
End Sub Function GetFile(FileName)
' VBScript Client - FTP File to Thumb Drive
Dim objShell, objFSO
Dim strFTPScriptFileName, strFTPServerFolder
Dim strFTPServerName, strLoginID, strPassword
Dim strThumbDrive, strLocalFile Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("Menu.hta") strThumbDrive = objFSO.GetParentFolderName(objFile)
strLocalFile = objFSO.GetParentFolderName(objFile) & FileName 'Set FTP options
strFTPServerName = "00.00.00.00"
strLoginID = inputbox("UserName")
strPassword = inputbox("password")
strFTPServerFolder = "/" 'Generate FTP command
strFTPScriptFileName = strThumbDrive & "Get_File.txt" Set objFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objFile.WriteLine ("open " & strFTPServerName)
objFile.WriteLine (strLoginID)
objFile.WriteLine (strPassword)
objFile.WriteLine ("bin")
objFile.WriteLine ("prompt off")
objFile.WriteLine ("get " & FileName)
objFile.WriteLine ("bye")
'Execute the FTP script.
Set objShell = CreateObject( "WScript.Shell" )
'Wscript.Echo "Downloading File..." objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True objFile.Close
objFSO.DeleteFile strFTPScriptFileName,True 'Wscript.Echo "Deleting download script..." Set objFSO = Nothing
Set objShell = Nothing Self.close End Function Function PutFile(FileName)
' VBScript Client - FTP File to ftp server
Dim objShell, objFSO
Dim strFTPScriptFileName, strFTPServerFolder
Dim strFTPServerName, strLoginID, strPassword
Dim strThumbDrive, strLocalFile, strLocalFolderName Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("C:\Rent Roll\Tenant Tracker 2011_be.accdb")
strBE = "C:\Rent Roll\Tenant Tracker 2011_be.accdb" If objFSO.FileExists(strBE) Then strLocalFolderName = "C:\Rent Roll\"
FileName = Chr(34) & strLocalFolderName & FileName & Chr(34)
'Set FTP options
strFTPServerName = "00.00.00.00"
strLoginID = inputbox("UserName")
strPassword = inputbox("password")
'Generate FTP command
strFTPScriptFileName = strThumbDrive & "Send_File.txt"
Set objFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objFile.WriteLine ("open " & strFTPServerName)
objFile.WriteLine (strLoginID)
objFile.WriteLine (strPassword)
objFile.WriteLine ("bin")
objFile.WriteLine ("lcd " & strLocalFolderName)
objFile.WriteLine ("prompt off")
objFile.WriteLine ("put " & FileName)
objFile.WriteLine ("bye")
'Execute the FTP script.
Set objShell = CreateObject( "WScript.Shell" ) ' Wscript.Echo "Sending File..." objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True
objFile.Close
objFSO.DeleteFile strFTPScriptFileName,True 'Wscript.Echo "Deleting upload script..." Set objFSO = Nothing
Set objShell = Nothing
End If
Self.close End Function
Function Install(FileName,FileType)
Dim objShell, objFSO
Dim strFTPScriptFileName, strFTPServerFolder
Dim strFTPServerName, strLoginID, strPassword
Dim strThumbDrive, strLocalFile, strLocalFolderName Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("Menu.hta") strThumbDrive = objFSO.GetParentFolderName(objFile)
strLocalFile = objFSO.GetParentFolderName(objFile) & FileName
strLocalFolderName = "C:\Rent Roll\" If FileType = 1 Then
strToDir = objFSO.GetParentFolderName(objFile) & "backup\"
Else
strToDir = objFSO.GetParentFolderName(objFile) & "demo_backup\"
End If If objFSO.FolderExists(strLocalDir) Then
BackupFiles strThumbDrive, strLocalDir, strToDir, FileType
'Wscript.Echo "Need to uninstall current database..."
MsgBox ("Please use Add Remove Programs and uninstall" & Chr(13) & "Tenant Tracker then DOUBLE CLICK THIS file again...")
Else
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install(objFSO.GetParentFolderName(objFile) & FileName, , ALL_USERS)
End If Set objFSO = Nothing
Set objShell = Nothing Self.close
End Function Function BackupFiles(ThumbDrive, FromDir, ToDir)
Dim objShell, objFSO Const OverwriteExisting = TRUE Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") ' Create folder to receive files if it doesn' t already exist
ThumbDrive = ThumbDrive & ToDir
ToDir = ThumbDrive & "\"
FromDirFE = FromDir & "Tenant Tracker 2011.accdb"
FromDirBE = FromDir & "Tenant Tracker 2011_be.accdb"
If objFSO.FolderExists(ThumbDrive) Then
'Wscript.Echo "Backing up current database..."
objFSO.CopyFile FromDirFE, ToDir, OverwriteExisting
objFSO.CopyFile FromDirBE, ToDir, OverwriteExisting
'Wscript.Echo "Backed up current files to: " & ToDir
Else
'Wscript.Echo "Folder does not exist..."
Set objFolder = objFSO.CreateFolder(ToDir)
' Wscript.Echo "Backing up current database..."
objFSO.CopyFile FromDirFE, ToDir, OverwriteExisting
objFSO.CopyFile FromDirBE, ToDir, OverwriteExisting
' Wscript.Echo "Backed up current files to: " & ToDir
End If
Set objFSO = Nothing
Set objShell = Nothing Self.close End Function Function Unzip(strFrom,strTo)
Dim ParentFolder
Dim objFolder
Dim strThumbDrive, strLocalFile, strLocalFolderName Dim objShell:Set objShell = CreateObject("Shell.Application")
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("Menu.hta") strThumbDrive = objFSO.GetParentFolderName(objFile)
strLocalFolderName = "C:\Rent Roll\" ' For some reason overwrite does not work, since we backed it up above we can just delete it.
If objFSO.FileExists("C:\Rent Roll\Tenant Tracker 2011.accdb") Then
'Wscript.Echo "Deleting current front-end..."
objFSO.DeleteFile "C:\Rent Roll\Tenant Tracker 2011.accdb"
End If strZipFile = objFSO.GetParentFolderName(objFile) & strFrom
'Create the target folder if it isn't already there
If not objFSO.FolderExists(strLocalFolderName) Then
objFSO.CreateFolder strLocalFolderName
' wscript.echo strLocalFolderName & " Folder Has Been Created..."
end if
'Extract the files from the zip into the folder
objShell.NameSpace(strLocalFolderName).CopyHere objShell.NameSpace(strZipFile).Items
'wscript.echo strZipFile & " Has been unzipped to " & strLocalFolderName & " Successfully..."
Set objFSO = Nothing
Set objFolder = Nothing
Set objShell = Nothing
Self.close
End Function Function installRuntime
Dim objShell, objFSO
Dim strThumbDrive, strRunTime, strAccessLocation Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject") ' We need to get the path of the thumb drive we are using
Set objFile = objFSO.GetFile("Menu.hta") 'C:\Program Files (x86)\Microsoft Office\Office12
strThumbDrive = objFSO.GetParentFolderName(objFile)
strRunTime = "Access2007Runtime.exe"
strAccessLocation = "C:\Program Files (x86)\Microsoft Office\Office12\msaccess.exe" If objFSO.FileExists(strAccessLocation) Then
MsgBox ("The FULL version of Access 2007 or the Runtime version is already installed...")
Else
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install(objFSO.GetParentFolderName(objFile) & strRunTime, , ALL_USERS)
End If Set objFSO = Nothing
Set objShell = Nothing Self.close
End Function </script>
<body bgcolor="SteelBlue">
<center>
<!--Add your controls here-->
<input type="button" style="width:200;height:25" name="btnFullDL" id="btnFullDL" value="Full Install Download" onclick="btnFullDL">
<BR><input type="button" style="width:200;height:25" name="btnFullInstall" id="btnFullInstall" value="Full Install" onclick="btnFullInstall">
<BR><BR><input type="button" style="width:200;height:25" name="btnGetUpdate" id="btnGetUpdate" value="Download Update" onclick="btnGetUpdate">
<BR><input type="button" style="width:200;height:25" name="btnInstallUpdate" id="btnInstallUpdate" value="Install Update" onclick="btnInstallUpdate">
<BR><BR><input type="button" style="width:200;height:25" name="btnRuntime" id="btnRuntime" value="Install Access Runtime" onclick="btnRuntime">
<BR><BR><input type="button" style="width:200;height:25" name="btnDemoDL" id="btnDemoDL" value="Demo Install Download" onclick="btnDemoDL">
<BR><input type="button" style="width:200;height:25" name="btnDemoInstall" id="btnDemoInstall" value="Demo Install" onclick="btnDemoInstall">
<BR><BR><input type="button" style="width:200;height:25" name="btnSendBE" id="btnSendBE" value="Send Backend Database" onclick="btnSendBE">
<BR><BR><BR><input type="button" style="width:200;height:25" name="btnCancel" id="btnCancel" value="Cancel" onclick="btnCancel">
</center>
</body>
</html>
<message edited by longbow22 on Wednesday, January 18, 2012 2:56 AM>