Advertisement
omegastripes

Extract_Script.vbs

Dec 26th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Const FileFormat = 0 ' -2 - System default, -1 - Unicode, 0 - ASCII
  2.  
  3. strCurDir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName) & "\"
  4. strPath = strCurDir & "child.vbs"
  5. strFnName = "ChildScript"
  6.  
  7. WriteTextFile split(split(ReadTextFile(WScript.ScriptFullName, FileFormat), "Function " & strFnName & "()" & vbCrLf)(1), "End Function")(0), strPath, FileFormat
  8.  
  9. Function ChildScript()
  10.     MsgBox "Extracted Child Script"
  11. End Function
  12.  
  13. Function ReadTextFile(strPath, lngFormat)
  14.     ' lngFormat -2 - System default, -1 - Unicode, 0 - ASCII
  15.     With CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath, 1, False, lngFormat)
  16.         ReadTextFile = ""
  17.         If Not .AtEndOfStream Then ReadTextFile = .ReadAll
  18.         .Close
  19.     End With
  20. End Function
  21.  
  22. Sub WriteTextFile(strContent, strPath, lngFormat)
  23.     ' lngFormat -2 - System default, -1 - Unicode, 0 - ASCII
  24.     With CreateObject("Scripting.FileSystemObject").OpenTextFile(strPath, 2, True, lngFormat)
  25.         .Write (strContent)
  26.         .Close
  27.     End With
  28. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement