?
Solved

Redirect Output in HTA

Posted on 2011-05-02
2
Medium Priority
?
980 Views
Last Modified: 2012-05-11
Hi guys,

I need help to know how can I redirect the output from HTA to a File e.g. ipconfig > test.txt

Because I tried with this script:
 
|<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

Sub Snapshot_Permissions
	Dim StrAco, strrun
	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
	strrun = "%comspec% /c C:\windows\system32\cacls.exe " & chr(34) & "E:\Inetpub\eforms\*" & chr(34) & " >" & chr(34) & "C:\permisos.txt" & chr(34)
'	objShell.Run strrun
'		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



</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>
</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="Snapshot_Permissions">
			
		</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


But in Line (131)
      strrun = "%comspec% /c C:\windows\system32\cacls.exe " & chr(34) & "E:\Inetpub\eforms\*" & chr(34) & " >" & chr(34) & "C:\permisos.txt" & chr(34) > does not work
0
Comment
Question by:Gonzalo Becerra
2 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 35509605
Hi, that line is formed correctly, and should definately work, provided that
a) C:\windows\system32\cacls.exe exists
b) E:\inetpub\eforms\ exists

I also assume you have uncommented line 132:
'      objShell.Run strrun

Above that, you can try this:
InputBox "Prompt", "Title", strRun

then when the input box comes up, copy that text, and paste it into a command prompt without the %comspec%....

Wait a second.....the shell won't know what the %comspec% is....try this instead:

      strrun = objShell.ExpandEnvironmentStrings("%comspec%") & " /c C:\windows\system32\cacls.exe " & chr(34) & "E:\Inetpub\eforms\*" & chr(34) & " >" & chr(34) & "C:\permisos.txt" & chr(34)


Regards,

Rob.
0
 
LVL 1

Author Closing Comment

by:Gonzalo Becerra
ID: 35509828
Excellent thanks a lot for your help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question