Is it possible to embed and execute VBScript within a batch file without using a temporary file?

Note – jump to the UPDATE 2014-04-27 section at the bottom of this answer for the best solution. I used to think the answer was no. But then DosTips user Liviu discovered that the <SUB> character (Ctrl-Z, 0x1A, decimal 26) has bizare effects when embedded within a batch file. If functions somewhat like a line … Read more

How do I include a common file in VBScript (similar to C #include)?

You can create a (relatively) small function in each file that you want to include other files into, as follows: sub includeFile (fSpec) dim fileSys, file, fileData set fileSys = createObject (“Scripting.FileSystemObject”) set file = fileSys.openTextFile (fSpec) fileData = file.readAll () file.close executeGlobal fileData set file = nothing set fileSys = nothing end sub and … Read more

Creating and writing lines to a file

Set objFSO=CreateObject(“Scripting.FileSystemObject”) ‘ How to write file outFile=”c:\test\autorun.inf” Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write “test string” & vbCrLf objFile.Close ‘How to read a file strFile = “c:\test\file” Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine= objFile.ReadLine Wscript.Echo strLine Loop objFile.Close ‘to get file path without drive letter, assuming drive letters are c:, d:, etc strFile=”c:\test\file” s … Read more

Getting current directory in VBScript

You can use WScript.ScriptFullName which will return the full path of the executing script. You can then use string manipulation (jscript example) : scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) Or get help from FileSystemObject, (vbscript example) : scriptdir = CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName)

How to set delay in vbscript

Work this end (XP). Create a new file, call it test.vbs. Put this in it. WScript.Sleep 1000 MsgBox “TEST” Run it, notice the delay before the message box is shown. Note, the number is in Milliseconds, so 1000 is 1 second.