HTA to Run multiples Scripts

Guys,

I need help to adapt the following HTA to run multiple scripts and put the result on the right (textarea) and create a log.
For example Click on button "Backup SPS" and when I click execute other vbs file and put the result on the textarea.

This is the HTA file to adapt:
 
<head>
<title>Application Maintenance</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Application Maintanence"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService
Dim colListOfServices, strComputer
Dim arrServices, strService, intReturn
arrServices = Array("Application Service1", "Application Service2", "Application Service3")
arrServices = Array("Windows SharePoint Services Timer")
strComputer = "."     'local computer

Sub stop_Srv
txt_srvstop.Value = ""
For Each strService In arrServices
	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='"& strService & "'")
	For Each objService In colListOfServices
		txt_srvstop.Value = txt_srvstop.Value & "Stopping " & strService & VbCrLf
		If objService.State <> "Stopped" Then
			intReturn = objService.StopService()
			HTASleep 2
			If intReturn = 0 Then
				txt_srvstop.Value = txt_srvstop.Value & strService & " has been stopped." & vbCrLF
			Else
				txt_srvstop.Value = txt_srvstop.Value & strService & " was not stopped." & VbCrLf
			End If
		Else
			txt_srvstop.Value = txt_srvstop.Value & strService & " is already stopped." & vbCrLF
		End If
	Next
Next
txt_srvstop.Value = txt_srvstop.Value & "Finished stopping services"
End Sub

Sub HTASleep(intSeconds)
	Dim objShell
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "ping 127.0.0.1 -n " & intSeconds + 1, 0, True
End Sub

Sub delete_Files
	Dim objFSO
	Dim strFolder
	Dim objFile
	Dim strPath
	txt_deletefiles.Value = ""
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	strFolder = "E:\Application"
	For Each objFile In objFSO.GetFolder(strFolder).Files
		If Right(LCase(objFile.Name), 4) = ".pyc" Then
			strPath = objFile.Path
			On Error Resume Next
			objFSO.DeleteFile strPath, True
			If Err.Number = 0 Then
				txt_deletefiles.Value = txt_deletefiles.Value & "DELETED: " & strPath & VbCrLf
			Else
				txt_deletefiles.Value = txt_deletefiles.Value & "ERROR " & Err.Number & ": " & strPath & VbCrLf
			End If
			Err.Clear
			On Error GoTo 0
		End If
	Next
    	'List all *.pyc files from folder E:\Application\ in textblock on HTA page (around 20 files, so textblock will need vertical scrollbar)
	'Then delete files
End Sub

	
Sub start_Srv
txt_srvstart.Value = ""
For Each strService In arrServices
	Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colListOfServices = objWMIService.ExecQuery ("Select * from Win32_Service Where Name ='"& strService & "'")
	For Each objService In colListOfServices
		txt_srvstart.Value = txt_srvstart.Value & "starting " & strService & VbCrLf
		If objService.State <> "Running" Then
			intReturn = objService.startService()
			HTASleep 2
			If intReturn = 0 Then
				txt_srvstart.Value = txt_srvstart.Value & strService & " has been started." & vbCrLF
			Else
				txt_srvstart.Value = txt_srvstart.Value & strService & " was not started." & VbCrLf
			End If
		Else
			txt_srvstart.Value = txt_srvstart.Value & strService & " is already started." & vbCrLF
		End If
	Next
Next
txt_srvstart.Value = txt_srvstart.Value & "Finished starting services"
End Sub



</script>

<body>
<table border="1">
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="stop_srv_button"  onClick="stop_Srv">
			
		</td>
		<td width="500">
			<textarea name="txt_srvstop" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Restore SPS" name="del_files_button"  onClick="delete_Files">
		</td>
		<td>
			<textarea name="txt_deletefiles" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
	<tr height="100">
		<td>
			<input type="button" value="Start Services" name="start_srv_button"  onClick="start_Srv">
		</td>
		<td>
			<textarea name="txt_srvstart" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window


Script1:
E:\temp\Backups\Backup_SPS_PS.vbs
Contain the following code:
 
Option Explicit
Dim SiteURL, C_SiteURL, sAplic, 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://eforms.app.pmi", "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. pmi\s-itsc-shrmoss","Enter the Service Account", "")
sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
SPBackupFile = "E:\Temp\Backups"
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:\Temp\Backups\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


Script2:
E:\temp\Backups\Restore_SPS_PS.vbs
Contain the following code:
 
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://eforms.app.pmi", "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. pmi\s-itsc-shrmoss","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\eforms.app.pmi-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


I would like this HTA to concentrate multiple scripts in one file and generate a log with all executions.

Log file similar as:
25/04/2011 12:05 PM Backup SPS
25/04/2011 13:05 PM Restore SPS
LVL 1
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAsked:
Who is Participating?
 
rlandquistCommented:
This will check if the log file exists and append otherwise create new.
<HTML>
	<HEAD>
		<TITLE>HTA Application Template</TITLE>
		<HTA:APPLICATION 
  			ID="MyApp" 
			APPLICATIONNAME="ASE Application Template"
			BORDER="thick"
			BORDERSTYLE="complex"
			CAPTION="yes"
			CONTEXTMENU="no"
			ICON="http://Your URL/your icon.ico"
			INNERBORDER="yes"
			MAXIMIZEBUTTON="yes"
			MINIMIZEBUTTON="yes"
			NAVIGABLE="no"
			SCROLL="no"
			SHOWINTASKBAR="yes"
			SINGLEINSTANCE="yes"
			SYSMENU="yes"
			VERSION="1.0"
			WINDOWSTATE="maximized"/>
	</HEAD>
	
	<SCRIPT Language="VBScript">
    Const ForReading = 1, ForWriting = 2, ForAppending = 8 

    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strLogFile = "C:\Scripts\LogFile.txt"
    DQ = Chr(34)
    
    strCommand = "%comspec% /k cscript.exe "
    strScript1 = "C:\TEMP\RunScript1.vbs"
    
    Sub RunScript1
    If objFSO.FileExists(strLogFile) Then
    Set objLogFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
    Else
    Set objFile = objFSO.CreateTextFile(strLogFile)
    End If
       
    objFile.WriteLine Date & " Script 1 Ran"
    
    objShell.Run strCommand & DQ & strScript1 & DQ,1,True
    objFile.Close
    
    End Sub
    
	</SCRIPT>
	
	<BODY>
    This is a test HTA, Click the button to run the script<p></p>
        <input type="button" value="Click Me" name="btnClickMe"  onClick="vbs:RunScript1">

	</BODY>
</HTML>

Open in new window

0
 
dan_nealCommented:
If your wanting to keep these as separate files, you will need to call each script from a shell object.  You can then capture the the stdout property that will be the results of the script.  See example below (calls a powershell script but same concept).  Make sure to close the StdIn otherwise script will just sit there.

The StdOut will be a result of the "Echo" statments the script produces.

Hope this helps.  Let me know if you need any clarifications on the code.
dim pscmd, os, ret, ex, pspath, sto, ws
ddl_DBS.options.length = 1

'path to powershell script
pspath = app_path & "scripts\listdbs.ps1"

'***************************************************************************
'command to call powershell script
'important flags:
'	-windowstyle hidden 	= does not show powershell window when script is fired.  also allows command prompt window to close
'  -file						= tells powershell that it is executing the content of a file
'***************************************************************************
pscmd = "powershell.exe -noprofile -windowstyle hidden -file " & pspath & " " & t_svr.value & " " & t_sqllogin.value & " " & t_sqlpassword.value

'create shell object
Set os = CreateObject("WScript.Shell")

'update status message to alert user of actions
sStatus.innerhtml = "Attempting to connect to SQL server """ & t_svr.value & """"

'pause script to allow interface to update
ccSleep 1

'use shell.execute to call command
set ex = os.EXEC(pscmd)

'close input, must be done in order to retrieve results from powershell script
ex.stdin.close

'get output object
set sto = ex.stdout

'read output creating list of non-system databases
while not sto.atendofstream
	set o = document.createelement("OPTION")
	ret = sto.readline
	o.text = ret
	o.value = ret
	ddl_DBS.add o
	set o = nothing
wend
if ddl_dbs.options.length = 1 then
	sStatus.innerhtml = "Server could not be found or invalid credentials.  Please try again"
else
	sStatus.innerhtml = "Server connected.  Received list of Non-System databases"
end if
set sto = nothing
set ex = nothing
set sh = nothing

Open in new window

0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Thanks Dan, Sorry but I don't understood good how to call .vbs from HTA (because this code is not HTA file)?; and how to generate a log when I click on button "Backup SPS".

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Do you have a simple example from HTA File to how to call a vbs file and generate a log when click on button of the vbs?.
0
 
rlandquistCommented:
Here is a simple example of an HTA calling a vbscript and writing a log file
<HTML>
	<HEAD>
		<TITLE>HTA Application Template</TITLE>
		<HTA:APPLICATION 
  			ID="MyApp" 
			APPLICATIONNAME="ASE Application Template"
			BORDER="thick"
			BORDERSTYLE="complex"
			CAPTION="yes"
			CONTEXTMENU="no"
			ICON="http://Your URL/your icon.ico"
			INNERBORDER="yes"
			MAXIMIZEBUTTON="yes"
			MINIMIZEBUTTON="yes"
			NAVIGABLE="no"
			SCROLL="no"
			SHOWINTASKBAR="yes"
			SINGLEINSTANCE="yes"
			SYSMENU="yes"
			VERSION="1.0"
			WINDOWSTATE="maximized"/>
	</HEAD>
	
	<SCRIPT Language="VBScript">
    Set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strLogFile = "C:\Scripts\LogFile.txt"
    DQ = Chr(34)
    
    strCommand = "%comspec% /k cscript.exe "
    strScript1 = "C:\TEMP\RunScript1.vbs"
    
    Sub RunScript1
    Set objFile = objFSO.CreateTextFile(strLogFile)
    objFile.WriteLine Date & " Script 1 Ran"
    
    objShell.Run strCommand & DQ & strScript1 & DQ,1,True
    objFile.Close
    
    End Sub
    
	</SCRIPT>
	
	<BODY>
    This is a test HTA, Click the button to run the script<p></p>
        <input type="button" value="Click Me" name="btnClickMe"  onClick="vbs:RunScript1">

	</BODY>
</HTML>

Open in new window

0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Cool work fine, I would like to know do you have one example from stdout? to capture the output?
0
 
rlandquistCommented:
Can you clarify that?  You want to capture the output of the called vbscript?  What do you want to do with it?
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Other question sorry, I would like to know to add lines in the log because always create a new log and don't have the past information
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Yes sorry,

I have this HTA. I would like to do the following actions:

1- Always add information to the log because when execute the script create a new log.
2- Capture the result of the execution and put if the script finish fine put "The script was executed correctly" on the right text area.


This is my HTA:
 
<head>
<title>Application Maintenance</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Application Maintanence"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile
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:\a-gbecerra\LogFile.txt"
DQ = Chr(34)
    
'strCommand = "%comspec% /k wscript.exe "
strCommand = "wscript.exe "
strScript1 = "E:\a-gbecerra\grupos.vbs"


Sub RunScript1
	Set objFile = objFSO.CreateTextFile(strLogFile)
	objFile.WriteLine Date & " The backup script was executed"
	
	objShell.Run strCommand & DQ & strScript1 & DQ,1,True
	objFile.Close

End Sub




</script>

<body>
<table border="1">
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="RunScript1">
			
		</td>
		<td width="500">
			<textarea name="txt_srvstop" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window


This is the script to run from HTA for example:
 
Dim GRPArray(256)

Set fso = CreateObject("Scripting.FileSystemObject")

Usuario = InputBox("Ingresar ID de usuario",,"gbecerra")
Dominio = InputBox("Ingresar Dominio",,"pmi")

	QueryGroup="NULL"
	Set usr = GetObject("WinNT://" & dominio & "/" & usuario & ",user")
        A=0
        For Each grp In usr.Groups		
           GRPArray(A) = (grp.name)
           A = A + 1
	Next
B = A - 1

A = 0
Set ArcTemp = fso.CreateTextFile("C:\" & usuario & ".txt",True)

   ArcTemp.WriteLine("Usuario: " & Usuario)
   ArcTemp.WriteLine("Dominio: " & Dominio)
   ArcTemp.WriteLine("----------------------")

 For A = 0 to B
  ArcTemp.WriteLine(GRPArray(A))
 Next
ArcTemp.Close

Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "notepad.exe C:\" & usuario & ".txt"


set usr = nothing
Set fso = nothing
Set oShell = nothing

Open in new window

0
 
rlandquistCommented:
The best way to deal with the script output being shown in the HTA is to put the scripts in the HTA as Subs rather than calling outside scripts.
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Ok no problem we can put the scripts as Subs.

How can I adapt as Sub? It's ok my way?
 
<head>
<title>Application Maintenance</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Application Maintanence"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile, ForAppending
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:\a-gbecerra\LogFile.txt"
DQ = Chr(34)
    
'strCommand = "%comspec% /k wscript.exe "
strCommand = "wscript.exe "
strScript1 = "E:\a-gbecerra\grupos.vbs"


Sub RunScript1
	If objFSO.FileExists(strLogFile) Then
		Set objLogFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	   
	objFile.WriteLine Date & " Script 1 Ran"
				Dim GRPArray(256)
			
			Set fso = CreateObject("Scripting.FileSystemObject")
			
			Usuario = InputBox("Ingresar ID de usuario",,"gbecerra")
			Dominio = InputBox("Ingresar Dominio",,"pmi")
			
				QueryGroup="NULL"
				Set usr = GetObject("WinNT://" & dominio & "/" & usuario & ",user")
			        A=0
			        For Each grp In usr.Groups		
			           GRPArray(A) = (grp.name)
			           A = A + 1
				Next
			B = A - 1
			
			A = 0
			Set ArcTemp = fso.CreateTextFile("C:\" & usuario & ".txt",True)
			
			   ArcTemp.WriteLine("Usuario: " & Usuario)
			   ArcTemp.WriteLine("Dominio: " & Dominio)
			   ArcTemp.WriteLine("----------------------")
			
			 For A = 0 to B
			  ArcTemp.WriteLine(GRPArray(A))
			 Next
			ArcTemp.Close
			
			Set oShell = WScript.CreateObject ("WSCript.shell")
			oShell.run "notepad.exe C:\" & usuario & ".txt"
			
			
			set usr = nothing
			Set fso = nothing
			Set oShell = nothing

	objFile.Close
End Sub


</script>

<body>
<table border="1">
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="RunScript1">
			
		</td>
		<td width="500">
			<textarea name="txt_srvstop" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window



I think we have a problem with the append because I receive an error:
 Error
0
 
rlandquistCommented:
You are missing the constant

Const ForAppending = 8
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
I have this error now:


This is the HTA now:

 
<head>
<title>Application Maintenance</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Application Maintanence"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile
Dim colListOfServices, strComputer
Dim arrServices, strService, intReturn
Const ForAppending = 8
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:\a-gbecerra\LogFile.txt"
DQ = Chr(34)
    
'strCommand = "%comspec% /k wscript.exe "
strCommand = "wscript.exe "
strScript1 = "E:\a-gbecerra\grupos.vbs"


Sub RunScript1
	If objFSO.FileExists(strLogFile) Then
		Set objLogFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	   
	objFile.WriteLine Date & " Script 1 Ran"
				Dim GRPArray(256)
			
			Set fso = CreateObject("Scripting.FileSystemObject")
			
			Usuario = InputBox("Ingresar ID de usuario",,"gbecerra")
			Dominio = InputBox("Ingresar Dominio",,"pmi")
			
				QueryGroup="NULL"
				Set usr = GetObject("WinNT://" & dominio & "/" & usuario & ",user")
			        A=0
			        For Each grp In usr.Groups		
			           GRPArray(A) = (grp.name)
			           A = A + 1
				Next
			B = A - 1
			
			A = 0
			Set ArcTemp = fso.CreateTextFile("C:\" & usuario & ".txt",True)
			
			   ArcTemp.WriteLine("Usuario: " & Usuario)
			   ArcTemp.WriteLine("Dominio: " & Dominio)
			   ArcTemp.WriteLine("----------------------")
			
			 For A = 0 to B
			  ArcTemp.WriteLine(GRPArray(A))
			 Next
			ArcTemp.Close
			
			Set oShell = WScript.CreateObject ("WSCript.shell")
			oShell.run "notepad.exe C:\" & usuario & ".txt"
			
			
			set usr = nothing
			Set fso = nothing
			Set oShell = nothing

	objFile.Close
End Sub


</script>

<body>
<table border="1">
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="RunScript1">
			
		</td>
		<td width="500">
			<textarea name="txt_srvstop" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window



Sorry for my mistake I don't have much experience with this. Thanks a lot for help me :)
 Error
0
 
rlandquistCommented:
log file names are different (my typo), change line 33:
objLogFile to objFile
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
I have this error:



 Error
0
 
rlandquistCommented:
Change line 67 from:
Set oShell = WScript.CreateObject ("WSCript.shell")

to:
 Set oShell = CreateObject("WScript.Shell")
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Great is working finw without error :).

The last question is I need add in the right panel the result of the exection for example is the script work fine add The Script was executed correctly.
0
 
rlandquistCommented:
Like I said before, instead of calling external scripts, put the contents of the script in a sub routine inside the HTA
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
OK thanks a lot for your help and sorry for my poor knowledge :)

I already adapt my script Backup SPS to the HTA File I have one issue only. I think is related with wscript but I don't understand what exactly.

 Error
This is my finish HTA:
 
<head>
<title>Application Maintenance</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Application Maintanence"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
>
</head>

<script language="VBScript">

Option Explicit
Dim objWMIService, objItem, objService, objShell, objFSO, strLogFile, DQ, strCommand,strScript1, objFile, wscript
Dim colListOfServices, strComputer
Dim arrServices, strService, intReturn
Const ForAppending = 8
arrServices = Array("Application Service1", "Application Service2", "Application Service3")
arrServices = Array("spooler", "spooler")
strComputer = "."     'local computer
strLogFile = "E:\a-gbecerra\LogFile.txt"
DQ = Chr(34)
strCommand = "wscript.exe "
strScript1 = "E:\a-gbecerra\grupos.vbs"

Set objFSO = CreateObject("Scripting.FileSystemObject")


Sub RunScript1
	If objFSO.FileExists(strLogFile) Then
		Set objFile = objFSO.OpenTextFile(strLogFile,ForAppending,True)
	Else
		Set objFile = objFSO.CreateTextFile(strLogFile)
	End If
	   
	objFile.WriteLine Date & " Script 1 Ran"
			
			Set objShell = CreateObject("WScript.Shell")
			Dim SiteURL, C_SiteURL, sAplic, 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://eforms.app.pmi", "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. pmi\s-itsc-shrmoss","Enter the Service Account", "")
			sPwd = Inputbox("Enter the password for: " & sUserName,"Enter the Service Account Password", "")
			SPBackupFile = "E:\Temp\Backups"
			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:\Temp\Backups\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
			
			objShell.Echo "Backup of site collection successful"
			Set objshell = nothing
	objFile.Close
End Sub


</script>

<body>
<table border="1">
	<tr height="100">
		<td>
			<input type="button" value="Backup SPS" name="backup_sps_button"  onClick="RunScript1">
			
		</td>
		<td width="500">
			<textarea name="txt_srvstop" rows="5" cols="60" readOnly="yes"></textarea>
		</td>
	</tr>
</table>
</body>

Open in new window


This is my last question and I will close the question.

Thanks again your all your help :)
0
 
rlandquistCommented:
You can't use wscript.echo in HTAs.  Use msgbox instead.
Also, wscript.quit will not work in an HTA
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Thanks a lot for all your help :D Excellent
0
 
Gonzalo BecerraSharePoint - Technical Lead for Operations & Engineering Team - Superrvising AssociateAuthor Commented:
Excellent thanks for all your help
0
 
rlandquistCommented:
No problem, glad to help.  Thanks for the grade.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.