Search code examples
vbscript

Writing a VBS via another VBS


I'm trying to create a VBS via another VBS, but cant handle the quotation marks, and would love to know if it's even possible.

That's the 1 line I need in my new VBS:

CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False

Main VBS code that doesn't work:

    Dim oFSO, vbFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set vbFile = oFSO.CreateTextFile("try.vbs", True)
    vbFile.WriteLine ""CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False""
    vbFile.Close

Solution

  • Thanks to Sorceri, I managed to make it work by writing the following code:

    Dim oFSO, vbFile
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    Set vbFile = oFSO.CreateTextFile("try.vbs", True)
    vbFile.WriteLine "CreateObject(" & Chr(34) & "Wscript.Shell" & Chr(34) & ").Run """""""" & WScript.Arguments(0) & """""""", 0, False"
    vbFile.Close