Need help with "TextFile (.vbs) Write From String"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • mystica
    No longer a forum member
    • May 2007
    • 1548

    Need help with "TextFile (.vbs) Write From String"

    I'm trying to get my button to write a textfile to the user's temp-folder (but I want the file to be appended with a .vbs extension instead of .txt extension).

    This is the contents of the file that I'm trying to write:

    Code:
    on error resume next
    
    Const TEMPORARY_INTERNET_FILES = &H20&
    
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace("Temporary Internet Files")
    Set objFolderItem = objFolder.Self
    strPath = objFolderItem.Path & "\*.*"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    Wscript.Echo objFolderItem.Path
    objFSO.DeleteFile(strPath)
    I've tried using "TextFile.WriteFromString" (making the necessary adjustment to get the .vbs extension) ... but I can't get it to work because it won't accept this content as a string.

    Can anyone help me out here? I'm sure the solution is really basic and staring me in the face ... but i just can't get my head around it.
  • ShadowUK
    No longer a forum member
    • Oct 2007
    • 1322

    #2
    Code:
    TextFile.WriteFromString(_SourceDrive.."\\file.vbs", "on error resume next\r\n\r\nConst TEMPORARY_INTERNET_FILES = &H20&\r\n\r\nSet objShell = CreateObject(\"Shell.Application\")\r\nSet objFolder = objShell.Namespace(\"Temporary Internet Files\")\r\nSet objFolderItem = objFolder.Self\r\nstrPath = objFolderItem.Path & \"\\*.*\"\r\n\r\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\r\n\r\nWscript.Echo objFolderItem.Path\r\nobjFSO.DeleteFile(strPath)", false);
    Edit:

    Oh wait, I see what you mean. It does not write .vbs files.

    Comment

    • mystica
      No longer a forum member
      • May 2007
      • 1548

      #3
      Oh wait, I see what you mean. It does not write .vbs files.
      Sure it does, ShadowUK ... you just change the .txt part to .vbs, within the command. In fact it will write a 'textfile' with ANY extension. That's not the problem.

      My problem is that I can't get it to accept the CONTENT of the file into the string. I can produce a simple .vbs-file with a single line of code, but NOT with the code (see my last post) that I want it to write. When I try, AMS thinks my VBS-code is LUA and gets confused.

      There must be some way to do it ... perhaps by storing it in an "invisible" ParagraphObject first, or something along these lines.

      Let's simplify things for the sake of arguement:

      Let's pretend I want to produce a text-file (not a vbs-file) with the exact same content. How would I do that? My first thoughts would be to write it from a string. But it don't work ... you try!)

      Comment

      • mystica
        No longer a forum member
        • May 2007
        • 1548

        #4
        Oh wow, hang on a sec ... I've just had a closer look at your code ShadowUK ... and it seems to be working now. I changed the destination for the vbs-file to:

        Code:
        TextFile.WriteFromString(_TempFolder .."\\file.vbs", "on error resume next\r\n\r\nConst TEMPORARY_INTERNET_FILES = &H20&\r\n\r\nSet objShell = CreateObject(\"Shell.Application\")\r\nSet objFolder = objShell.Namespace(\"Temporary Internet Files\")\r\nSet objFolderItem = objFolder.Self\r\nstrPath = objFolderItem.Path & \"\\*.*\"\r\n\r\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\r\n\r\nWscript.Echo objFolderItem.Path\r\nobjFSO.DeleteFile(strPath)", false);
        ... and now it seems to be working fine. That was weird. Anyway, problem solved ... I think. Thanks for your help ShadowUK.
        Last edited by mystica; 07-23-2008, 02:06 AM.

        Comment

        Working...
        X