Link to home
Start Free TrialLog in
Avatar of Gonzalo Becerra
Gonzalo BecerraFlag for Argentina

asked on

HTA add image and textbox and pass parameter to one vbscript.

Guys,

I finishing this HTA file but I need help to improve with 3 requirements:

1- Add Image as picture show:
 User generated imageThis is the picture to attach:
 User generated image

2- Add a Text Area to type an URL and button to browse when Click Browse open Internet Explorer with the Page and when close the Internet Explorer ask The Web Page load fine? yes or no.
User generated image
3- The Last is I need create a new Text Area (in HTA File) to write a numbers only  example: 5879226
and pass this number as parameter to this vbscript (The idea is understand how to pass a new field value to script and what I need specify in the script to receive the parameter):
 
'*******************************************************************************************************
' Tool for Automate Restore of backups in Sharepoint 2007 - Powered by Gonzalo G. Becerra
'*******************************************************************************************************

Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO, sBackuptoRestore


Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim sRestoreInetpub
Dim sRestoreFolder
Dim sFile
Dim objFSO
Dim WshShell
Dim sa
Dim filesInzip
Dim sSPSRestore
Dim sRestoreHive
Dim sHiveFolder
Dim sHiveFile
Dim sRestoreMetabase
Dim sMetabaseFolder
Dim sMetabaseFile
Dim sMetaRestore
Dim  WshNetwork
Dim strComputer

Set objShell = CreateObject("WScript.Shell")

Dim psexec, psexeccmd, objexec



'------------------------------ Restore Sharepoint (STSADM)------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSPSRestore = WshShell.Popup("Restore Sharepoint STSADM?",, "IIS", 4 + 32)
	if sSPSRestore = 6 Then
		sBackuptoRestore = Inputbox("Enter the BAK File to Restore: e.g.: E:\Temp\Backups\eForms\WO_444.bak","Enter file Location" ,"")
		SiteURL = Inputbox ("Enter the URL to Restore","e.g.: http://url", "http://")
		C_SiteURL = Chr(34) & SiteURL & chr(34)
		Const C_NamePrefix = "SharePoint_"
		Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"
		sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
		sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
		psexec = "E:\Temp\Backups\psexec.exe"
		psexec = fso.getfile(psexec).ShortPath
		psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
		strcmd = fso.GetFolder(C_SharePointBin).ShortPath & "\stsadm.exe -o restore -url " & C_SiteURL & " -filename " & sBackuptoRestore &  " -overwrite"
		'Inputbox "Running command", "Command", psexeccmd & strcmd
		Set objexec = objShell.Exec(psexeccmd & strcmd)
		While objexec.Status = 0
			WScript.Sleep 100
		Wend

	else
	End if
'---------------------------------------------------------------------------------------------------------------


'------------------------------ Restore Inetpub Folder ---------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sRestoreInetpub = WshShell.Popup("Restore Inetpub Folder?",, "IIS", 4 + 32)
	if sRestoreInetpub = 6 Then
	   sRestoreFolder = Inputbox("Enter the Inetpub Folder to Restore","e.g.: E:\Inetpub","E:\Inetpub")
	   sFile = Inputbox("Enter the ZipFile Full Path","e.g.: E:\Temp\Backups\eforms.zip","")
	   set sa = CreateObject("Shell.Application") 
	   set filesInzip=sa.NameSpace(sFile).items 
	   sa.NameSpace(sRestoreFolder).CopyHere(filesInzip)
	else
	End if
'---------------------------------------------------------------------------------------------------------------

'------------------------------ Restore 12 Folder ---------------------------------------------------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
sRestoreHive = WshShell.Popup("Restore 12 Folder?",, "IIS", 4 + 32)
	if sRestoreHive = 6 Then
	   sHiveFolder = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions"
	   sHiveFile = Inputbox("Enter the ZipFile Full Path","e.g.:  E:\Temp\Backups\application-12hive.zip","")
	   set sa = CreateObject("Shell.Application") 
	   set filesInzip=sa.NameSpace(sHiveFile).items 
	   sa.NameSpace(sHiveFolder).CopyHere(filesInzip)
	else
	End if
'---------------------------------------------------------------------------------------------------------------



WScript.Echo "Restore of site collection successful"
msgbox "Restore of site collection successful"
Set objshell = nothing

Open in new window



This is the HTA File:
 
<head>
<title>Collaboration Service Checklist</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Collaboration Service Checklist"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile, UserID
Dim colListOfServices, strComputer
Dim arrServices, strService, intReturn
arrServices = Array("Application Service1", "Application Service2", "Application Service3")
arrServices = Array("spooler", "spooler")
strComputer = "."     'local computer

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strLogFile = "E:\Temp\LogFile.txt"
DQ = Chr(34)
UserID = "Domain\" & CreateObject("WScript.Network").Username
strCommand = "wscript.exe "
strScript1 = "E:\Temp\Backup_SPS_PS.vbs"


Sub Check_EventVwr
	Dim Evtchk
	Const ForAppending = 8 
	Start_chk_bkp.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	Evtchk = objShell.Run("eventvwr")
		if Evtchk = 0 then
			objFile.WriteLine date & " " & time & " The Event Viewer was checked by " & UserID
			Start_chk_bkp.Value = date & " " & time & " The Event Viewer was checked by " & UserID
		End if
	objFile.Close

End Sub


Sub Check_SPS_Solutions_Before
	Dim obj
	Const ForAppending = 8 
	Check_Solution_Before.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	Set obj = CreateObject("InternetExplorer.Application")
	obj.navigate "http://localhost:2000/_admin/Solutions.aspx"
	obj.Visible = True
	objFile.WriteLine date & " " & time & " The solution before start was checked by " & UserID
	Check_Solution_Before.Value = date & " " & time & " The solution before start was checked by " & UserID
	objFile.Close

End Sub

Sub BackupSPS
	dim StrbkpSPS
	Const ForAppending = 8 
	BKP_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	objShell.Run strCommand & DQ & strScript1 & DQ,1,True
	objFile.WriteLine date & " " & time & " The Backup SPS Script was Runned by " & UserID
	BKP_Aco_Script.Value = date & " " & time & " The Backup SPS Script was Runned by " & UserID
	objFile.Close

End Sub

Sub ACO_Script
	Dim StrAco
	Const ForAppending = 8 
	Start_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	StrAco = objShell.Run("E:\Sources\ACO-SRVS\Script_Cosmos\Deploy_INT_v1.3.bat")
		if StrAco = 0 then
		objFile.WriteLine date & " " & time & " The ACO Script was started by " & UserID
		Start_Aco_Script.Value = date & " " & time & " The ACO Script was started by " & UserID
		End if
	objFile.Close

End Sub

Sub ACO_Script_Finish
	Dim StrAco
	Const ForAppending = 8 
	Finish_Aco_Script.Value = ""
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	
	StrAco = objShell.Run("E:\Sources\ACO-SRVS\Script_Cosmos\Deploy_INT_v1.3.bat")
		if StrAco = 0 then
		objFile.WriteLine date & " " & time & " The ACO Script was Finished correctly by " & UserID
		Finish_Aco_Script.Value = date & " " & time & " The ACO Script was Finished by " & UserID
		End if
	objFile.Close

End Sub


</script>

<body>
<h1 align='center'>Collaboration Service Checklist</h1>
<BODY BGCOLOR="#D4D0C8">
<table border="1">
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	Before the Deployment
</td>
		</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check EventViewer" name="backup_sps_button"  onClick="Check_EventVwr">
			
		</td>
		<td width="500">
			<textarea name="Start_chk_bkp" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Check SPS Solutions" name="backup_sps_button"  onClick="Check_SPS_Solutions_Before">
			
		</td>
		<td width="500">
			<textarea name="Check_Solution_Before" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Start ACO Script" name="backup_sps_button"  onClick="ACO_Script">
			
		</td>
		<td width="500">
			<textarea name="Start_ACO_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="BackupSPS">
			
		</td>
		<td width="500">
			<textarea name="BKP_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Permissions snapshot" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			
		</td>
		<td width="500">
		</td>
	</tr>
<tr>
	<td align="center" style="font-family: arial; font-size: 16px; font-weight: bold;">
	After the Deployment
</td>
	<tr height="100">
		<td>
			<input type="button" value="Finish ACO Script" name="backup_sps_button"  onClick="ACO_Script_Finish">
			
		</td>
		<td width="500">
			<textarea name="Finish_Aco_Script" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window




Thanks in advance,
Avatar of Gonzalo Becerra
Gonzalo Becerra
Flag of Argentina image

ASKER

Anyone can help me to understand how can I do ?
SOLUTION
Avatar of rlandquist
rlandquist
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks rlandquist for your help, I would like understand how can I do the step 2 and 3 because I need finish this HTA as soon as possible.
SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rob for your help.
1-  I have this error when I close the Internet Explorer after explore the site.
2- To adapt this script I add this line on my script mentioned in my question?

intNumber = WScript.Arguments(0)

 User generated image

Thanks in advance,
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Dear Rob sorry for the delay I had a Big Issues and I delay with this:

I have this Script (I replaced intNumber by nWO)
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO
nWO = WScript.Arguments(0)
msgbox nWO
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window


But for example I did execute: Backup_SPS_PS.vbs 3333 (3333 is the nWO) and I obtain the following error:
User generated image
@gbecerra

I think you probably need to check that there are arguments before you reference them.
Example:
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If

Open in new window


Reference: http://technet.microsoft.com/en-us/library/ee156618.aspx
@aikimark

Thansk for your help, I don't have more errors but the nWO value is null; if you see in the image I added the msgbox to see the value but is null.


 User generated image
This is the script now:
 
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If
msgbox nWO
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I added that but I have this message:

 User generated image
At least we now know that it isn't recognizing the 43434 argument even exists.  Most curious.
You think I'm wrong how to call script or any in the script?

This is the code:
 
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, nWO, args
Set args = WScript.Arguments
If WScript.Arguments.Count > 0 Then
  nWO = WScript.Arguments(0)
End If
msgbox nWO & ": " & WScript.Arguments.Count
'nWO = InputBox("Enter the WO number","e.g.:1001548 (Only the Number)","")
sAplic = InputBox("Application Name","e.g.: MCM-QA","Application-Enviroment")
Const BackupPath = "E:\Temp\Backups\"
SiteURL = Inputbox ("Enter the URL to Backup","e.g.: http://url", "http://")
C_SiteURL = Chr(34) & SiteURL & chr(34)
Const C_NamePrefix = "SharePoint_"
Const C_SharePointBin = "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\Bin"

Dim fso, folder, filedate, f, file
Dim sBackupPrefix

Set fso = CreateObject("Scripting.FileSystemObject")

if Not fso.FolderExists(BackupPath) then
WScript.Echo "The folder " & BackupPath & " does not exist!"
WScript.Quit
end if

Set folder = fso.GetFolder(BackupPath)
filedate = now
Set f = Nothing

' Assigns a name of the new file
sBackupPrefix = BackupPath & sAplic & "_" & "WO" & nWO & "_" & year(now) & right("00" & Month(now),2) & right("00" & day(now),2)

Set folder = fso.CreateFolder(sBackupPrefix)

Dim objShell
Dim strcmd
Dim runas
Dim sPwd
Dim sUserName
Dim SPBackupFile
Dim sInetpub
sUserName = Inputbox("Enter the Service Account: e.g. Domain\Service Account","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\ACO-Scripts"
sInetpub = Inputbox("Enter the Application Folder: e.g. E:\Inetpub\eforms","Enter the Application Folder", "")
Set objShell = CreateObject("WScript.Shell")


Dim psexec, psexeccmd, objexec
psexec = "E:\ACO-Scripts\psexec.exe"
psexec = fso.getfile(psexec).ShortPath
psexeccmd = psexec & " -accepteula -u " & sUserName & " -p " & sPwd & " \\" & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & " cmd /c " 
strcmd = "Powershell -command " & fso.getfolder(SPBackupFile).ShortPath &"\spbackup.ps1 " & fso.getfolder(SPBackupFile) &"\spbackup.xml " & SiteURL & " " & sBackupPrefix & " " &sInetpub
'Inputbox "Running command", "Command", psexeccmd & strcmd
Set objexec = objShell.exec(psexeccmd & strcmd)

While objexec.Status = 0
	WScript.Sleep 100
Wend

WScript.Echo "Backup of site collection successful"
Set objshell = nothing

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Cool it's Works Thanks A lot!! :D
Excellent, thanks for all
I don't understand how you can have zero arguments, but have an arguments.items(0) value.