Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a batch file from a VBSCRIPT

Status
Not open for further replies.

ironpawz

IS-IT--Management
Oct 8, 2002
44
NZ
I want to make a batch file from a VBscript. There are some things that are just easier for me to do in dos (I don't want to spend a week learning to do em in vbs).

In dos i go
echo wscript.echo "this is sweet" >> c:\temp\temp.vbs

I have tried

dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\zzz.txt", True)
path = filesys.GetAbsolutePathName("c:\zzz.txt")
getname = filesys.GetFileName(path)

filetxt.WriteLine("REM QD Audit by Bruce Taylor")

and that works fine but thing like

filetxt.WriteLine("for /f "tokens=3" %%I in ('ping %ipaddr% ^|find "Reply from"') do set replied=%%I")

don't work because it hits a " in the text and looks for the variable (I guess). I want to be able to create a .bat file with literal lines echoed into it no matter what the syntax (which I imagine is simple to a true vbs'r).

Can you clue me in please??

Thanx
[2thumbsup]
 
Use the Chr() Function to generate the ". It wrote the line to the text file in my test.

Like this:

filetxt.WriteLine("for /f" & Chr(34) & "tokens=3" & Chr(34) & " %%I in ('ping %ipaddr% ^|find " & Chr(34) & "Reply from" & Chr(34) & "') do set replied=%%I")

Regards,

mapman04
 
Mapman04 thanks mate this worked perfectly. I had to have a play to get all the other characters I use like ^ etc so this is for anyone who makes it here with similar questions.

Create and run this vbs and then look at c:\zzz.txt and the script to work out what character is what. I know it is nasty but I'm lazy sue me ;-)

Thanks again


dim filesys, filetxt, getname, path
Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.CreateTextFile("c:\zzz.txt", True)
path = filesys.GetAbsolutePathName("c:\zzz.txt")
getname = filesys.GetFileName(path)

filetxt.WriteLine("REM QD Character Set by Ironpaw")

filetxt.WriteLine(" "& Chr(1) & Chr(2) & Chr(3) & Chr(4) & Chr(5) & Chr(6) & Chr(7) & Chr(8) & Chr(9) & Chr(10) & Chr(11) & Chr(12) & Chr(13) & Chr(14) & " ")
filetxt.WriteLine(" "& Chr(15) & Chr(16) & Chr(17) & Chr(18) & Chr(19) & Chr(20) & Chr(21) & " ")

filetxt.WriteLine(" "& Chr(23) & Chr(24) & Chr(25) & Chr(26) & Chr(27) & Chr(28) & Chr(29) & Chr(30) & Chr(31) & Chr(32) & Chr(33) & Chr(34) & Chr(35) & Chr(36) & " ")
filetxt.WriteLine(" "& Chr(37) & Chr(38) & Chr(39) & Chr(40) & Chr(41) & Chr(42) & Chr(44) & " ")
filetxt.WriteLine(" "& Chr(44) & Chr(45) & Chr(46) & Chr(47) & Chr(48) & Chr(49) & Chr(50) & Chr(51) & Chr(52) & Chr(53) & Chr(54) & Chr(55) & Chr(56) & Chr(57) & " ")
filetxt.WriteLine(" "& Chr(58) & Chr(59) & Chr(60) & Chr(61) & Chr(62) & Chr(63) & Chr(64) & " ")
filetxt.WriteLine(" "& Chr(65) & Chr(66) & Chr(67) & Chr(68) & Chr(69) & Chr(70) & Chr(71) & Chr(72) & Chr(73) & Chr(74) & Chr(75) & Chr(76) & Chr(77) & Chr(78) & " ")
filetxt.WriteLine(" "& Chr(79) & Chr(80) & Chr(81) & Chr(82) & Chr(83) & Chr(84) & Chr(85) & " ")
filetxt.WriteLine(" "& Chr(86) & Chr(87) & Chr(88) & Chr(89) & Chr(90) & Chr(91) & Chr(92) & Chr(93) & Chr(94) & Chr(95) & Chr(96) & Chr(97) & Chr(98) & Chr(99) & " ")
filetxt.WriteLine(" "& Chr(100) & Chr(101) & Chr(102) & Chr(103) & Chr(104) & Chr(105) & Chr(106) & " ")
filetxt.WriteLine(" ")
filetxt.WriteLine(" ")
filetxt.WriteLine(" "& Chr(34) & Chr(34) & Chr(34) & " ")
filetxt.WriteLine(" "& Chr(94) & Chr(94) & Chr(94) & " ")
filetxt.WriteLine(" "& Chr(39) & Chr(39) & Chr(39) & " ")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top