Option Explicit '''''''''' Declare all the variables and objects we will be using Dim wsh 'As Wscript.Shell Dim ts 'As Scripting.TextStream Dim fs 'As Scripting.FileSystemObject Dim strBatFileName 'As String '''''''''' Get permission to run If MsgBox ("This program will create, run, and delete a simple ""Hello world"" batch file. Continue?", vbOkCancel) = vbCancel Then Wscript.Quit '''''''''' Define all the constants we will (or might) need Const TemporaryFolder = 2 'Scripting.SpecialFolderConst.TemporaryFolder Const ForWriting = 2 'Scripting.IOMode.ForWriting Const WshHide = 0 'IWshRuntimeLibrary.WshWindowStyle.WshHide Const WshNormalFocus = 1 'IWshRuntimeLibrary.WshWindowStyle.WshNormalFocus Const WshMinimizedFocus = 2 'IWshRuntimeLibrary.WshWindowStyle.WshMinimizedNoFocus Const WshMaximizedNoFocus = 3 'IWshRuntimeLibrary.WshWindowStyle.WshMaximizedNoFocus Const WshNormalNoFocus = 4 'IWshRuntimeLibrary.WshWindowStyle.WshNormalNoFocus Const WshMinimizedNoFocus = 6 'IWshRuntimeLibrary.WshWindowStyle.WshMinimizedNoFocus '''''''''' Create the objects we will need Set wsh = CreateObject("Wscript.Shell") Set fs = CreateObject("Scripting.FileSystemObject") '''''''''' Use one of the below four code lines. 'The first one allows you to specify the exact location. 'The second one gives you a file name in the "TEMP" directory. 'The third one gives you a file name in the same directory as the script. 'The fourth line just asks you to type in a name. If the name has already 'been set by previous code, it will show up as the default choice. strBatFileName = "C:\MyBatch.bat" strBatFileName = fs.BuildPath(fs.GetSpecialFolder(TemporaryFolder), "MyBatch.bat") strBatFileName = fs.GetAbsolutePathName(fs.BuildPath(Wscript.ScriptFullName, "..\" & "MyBatch.bat")) strBatFileName = InputBox("Enter the full path and name of the batch file to be created", "Enter File Name", strBatFileName) '''''''''' Open the batch file for writing. Create it if it does not already exist. Set ts = fs.OpenTextFile(strBatFileName, ForWriting, True) 'Write whatever you want into the batch file. Use "" where you want ". ts.WriteLine "@echo off" ts.WriteLine "echo ""HELLO"" WORLD! I'm running a DOS batch file:" ts.WriteLine "ver" ts.WriteLine "pause" ts.WriteLine "cls" 'Close the file to save it to disk ts.Close '''''''''' Now run the batch file. 'The first argument is the batch file name. The second is 'The "window style". Since our batch file uses "pause" and expects user input, it 'should be run in a normal window with focus. The third argument is whether or not 'the script should wait on the batch file to finish. Since we will be deleting 'the batch file during our clean-up phase, we have to wait for it to finish. wsh.Run """" & strBatFileName & """", WshNormalFocus, True '''''''''' Clean up. 'Delete the batch file we created since we are done with it. fs.DeleteFile strBatFileName 'Anything you used "set" in above should be set equal to Nothing here Set wsh = Nothing Set ts = Nothing Set fs = Nothing