JS alert & confirm in Windows Scripts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Little Pete

    JS alert & confirm in Windows Scripts

    I use a simple .js script to shuffle files on my computer to which I'd
    like to add alert and confirmation boxes. Unfortunately I haven't been
    able to figure out what object I need to create that has these methods.
    What is missing from this .js script:

    var source = "source.txt ";
    var destination = "destination.tx t";

    if (confirm("Make Changes?"))
    {
    var fso = new ActiveXObject(" Scripting.FileS ystemObject");
    fso.CopyFile(so urce, destination, true);
    alert("Changes made.");
    }
    else
    {
    alert("No changes made.");
    }

    Thanks, Pete.

  • Martin Honnen

    #2
    Re: JS alert & confirm in Windows Scripts



    Little Pete wrote:
    [color=blue]
    > I use a simple .js script to shuffle files on my computer to which I'd
    > like to add alert and confirmation boxes. Unfortunately I haven't been
    > able to figure out what object I need to create that has these methods.
    > What is missing from this .js script:
    >
    > var source = "source.txt ";
    > var destination = "destination.tx t";
    >
    > if (confirm("Make Changes?"))
    > {
    > var fso = new ActiveXObject(" Scripting.FileS ystemObject");
    > fso.CopyFile(so urce, destination, true);
    > alert("Changes made.");
    > }
    > else
    > {
    > alert("No changes made.");[/color]

    WScript.Echo("N o changes made.")
    will display on the console (when the script is run with cscript) or as
    an alert dialog (when the script is run with wscript).
    To have a confirm dialog you can use the WScript.Popup method, see the
    documentation
    <http://msdn.microsoft. com/library/default.asp?url =/library/en-us/script56/html/wsoriWindowsScr iptHost.asp>
    <http://msdn.microsoft. com/library/default.asp?url =/library/en-us/script56/html/wsMthPopup.asp>

    You can also download that documentation and then you have the help on
    your pc.

    --

    Martin Honnen

    Comment

    • Little Pete

      #3
      Re: JS alert &amp; confirm in Windows Scripts

      Thanks, Martin, that looks like what I needed, especially the links to
      the docs. Without already knowing the keywords, searching the msdn
      library was a nightmare.

      Pete.

      Comment

      Working...