• Getting VBScript to open Notepad

    • This topic has 2 replies, 2 voices, and was last updated 16 years ago.
    Author
    Topic
    #459266

    I have a VBScript which does some calculations and writes the results to a text file. The last thing it does is pops up a message saying ‘Now open C:Text2.txt’ What I would really like it to do is open Notepad itself and display the file on screen. I have Windows XP Annoyances by David Karp (my favourite technical author alongside John Walkenbach!) which gives some code for doing this:

    Call Runprogram(“notepad c:/temp2.txt”, False)
    .
    .
    .
    Sub RunProgram(filename, Wait)
    Set WshShell = WScript.CreateObject(“WScript.Shell”)
    RetVal = WshShell.Run(filename, Wait)
    End Sub

    …but it doesn’t work. It doesn’t crash but nothing happens. I have noticed, however, that after the script has run Task Manager shows Notepad running as a process. Does this mean that all that is required is to make the Notepad execution visible?

    TC

    Viewing 0 reply threads
    Author
    Replies
    • #1157580

      That is correct. You can accomplish this by changing the line

      RetVal = WshShell.Run(filename, Wait)

      to

      RetVal = WshShell.Run(filename, 1, Wait)

      1 = “Activates and displays a window”. See Run Method (Windows Script Host).

      • #1157585

        That is correct. You can accomplish this by changing the line

        RetVal = WshShell.Run(filename, Wait)

        to

        RetVal = WshShell.Run(filename, 1, Wait)

        1 = “Activates and displays a window”. See Run Method (Windows Script Host).

        Thanks Hans, just tested it and it works as desired!

        TC

    Viewing 0 reply threads
    Reply To: Getting VBScript to open Notepad

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: