FileSystem.WriteAllText (broken methodl)

J

Jared

Hi - I am trying to dynamically write vbscript file to c drive. But it will
not execute. I have notice some crap in windiff which suggest that VB has
unusual way of creating a file. Anyway it doesn't work and I was hoping to
use the script to bypass some chunky .NET schedule task code.

Anyone know about creating VBS file from VB.NET?

'--code below

Dim c As Char = """"c
Dim s As String
s = "WScript.Echo " + c + "Hello World" + c
My.Computer.FileSystem.WriteAllText("c:\test.vbs", s, False)
 
H

Herfried K. Wagner [MVP]

Jared said:
Hi - I am trying to dynamically write vbscript file to c drive. But it
will not execute. I have notice some crap in windiff which suggest that
VB has unusual way of creating a file.

Maybe you are seeing an UTF-8 BOM (Byte Order Mark) at the beginning of the
file.
 
J

Jared

WriteAllText is poor method

use StreamWriter ...

Dim writer As IO.StreamWriter = IO.File.CreateText(xPath)

writer.WriteLine(xText)
writer.Close()
 
H

Herfried K. Wagner [MVP]

Addendum:
Maybe you are seeing an UTF-8 BOM (Byte Order Mark) at the beginning of
the file.

The overloaded version of 'WriteAllText' accepts an 'Encoding' object. Pass
in 'System.Text.Encoding.Default' to use the systems ANSI CP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top