0

I have create new file with custom content. But it not run. (Save file name "CustomerList.hta")

Please help me resolve it.

<script language="VBScript">
Dim fso, outFile

Set fso = CreateObject("Scripting.FileSystemObject")

Dim tfolder, tname, tfile
Const TemporaryFolder = 2
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
Set tfile = tfolder.CreateTextFile("Customers.txt")
Set outFile = tfile

outFile.WriteLine "This first line"
outFile.WriteLine "The full path file is: " & tfile
outFile.WriteLine "This is last line"
outFile.Close
</script>
1
  • Remove the <script> tags. Commented Sep 21, 2017 at 17:26

2 Answers 2

0

Refactor to:

'<script language="VBScript">
Dim fso, outFile

Set fso = CreateObject("Scripting.FileSystemObject")

Dim tfolder, tname, tfile
Const TemporaryFolder = 2
Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
'Set tfile = tfolder.CreateTextFile("Customers.txt")
sFSpec = fso.BuildPath(tfolder, "Customers.txt")
WScript.Echo sFSpec
'Set tfile = fso.CreateTextFile("Customers.txt")
Set tfile = fso.CreateTextFile(sFSpec)
Set outFile = tfile

outFile.WriteLine "This first line"
'outFile.WriteLine "The full path file is: " & tfile
outFile.WriteLine "The full path file is: " & sFSpec
outFile.WriteLine "This is last line"
outFile.Close
'</script>

output:

cscript 46349646.vbs
C:\Users\eh\AppData\Local\Temp\Customers.txt

type C:\Users\eh\AppData\Local\Temp\Customers.txt
This first line
The full path file is: C:\Users\eh\AppData\Local\Temp\Customers.txt
This is last line

Use the docs (not wishfull thinking) to determine who can do what.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your script but it not work. I have saved with name .hta file. Its say "Object Require: WScript"
save it as a .vbs, and run it from the command line using: "cscript file.vbs" (without the quotes)
0

A .HTA file is an HTML Application. Your can create that file with notepad (it`s a text format). Check this page for a basic hta structure A basic sample with scripting can be found here

If you need to create dinamically your .hta file you must generate a text file with hta content (basically it is an HTML page).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.