Run and RunWait Commands And The COMSPEC Variable

AutoIt

Q #1: How do I run an external command like MS Word?

      ---------------------------------------------------------------------

A #1: Try:

      Run, C:\\Program Files\\Microsoft Office\\Office\\Winword.exe

      Or

      Run, %COMSPEC% /c C:\\Program Files\\Microsoft Office\\Office\\Winword.exe

      Or

      Send, ^{ESC}Rwinword{ENTER}

      The Run command can be substituted by RunWait.  The only difference
      is that RunWait suspends the AutoIt script until the DOS command has
      finished, and the Run command allows the AutoIt script to continue at
      the same time as the DOS command.

-----------------------------------------------------------------------------

Q #2: Is there a way to activate the Run box (Winkey-R) dialogue quickly
      (to execute the contents of the clipboard).  Anyone know of some kind
      of Rundll32 sequence that will do this (activate the Run dialogue
      box) or other programs that will do this?

      I know the Run dialogue box on the start menu and can Winkey to it
      that way but it's kind of iffy especially if you have other programs
      starting with R.

      I've tried the "Run %Clipboard%" etc., but nothing is as effective as
      the Run dialogue box for figuring out the syntax of various commands
      and understanding spaces etc.

      I think I've tried just about everything for executing text
      (specifically for "executing the clipboard text contents"). Nothing
      works as effectively for executing a wide variety of text commands as
      that Run dialogue box.  As an example let me illustrate as the
      following 2 lines of text:

      Notepad "C:\File with spaces in it.txt"
      C:\File with spaces in it.txt

      That Run dialogue box is the only thing I know of that will run
      either line without problems.  Using your suggestion it seems I'd be
      doing something like:

      SetEnv, variable, %COMSPEC% /c %CLIPBOARD%
      Run, %variable%

      Or possibly more simply:
      Run, %COMSPEC% /c %CLIPBOARD%

      This will work for the first line:
      Notepad "C:\File with spaces in it.txt"

      But not the second:
      C:\File with spaces in it.txt

      If one tries to add the extra quotes for the second line, then the
      first line won't work.

      ---------------------------------------------------------------------

A #1: If you want to do Winkey+R, try

      send, {LWIN}R

      {LWIN}R  = Left Windows key + R
      (although it isn't the same as actually hitting the winkey and R
      together)

      ---------------------------------------------------------------------

A #2: What about putting the application to be executed in an .INI file,
      which can have variables specified how you want them (but again they
      must follow the specific criteria you've already built into your
      script (i.e. Are they going to have quotes or not, Will they call the
      program and the file, or let the OS judge which program to open the
      file, etc...)

      If the variable of %CLIPBOARD% itself is such an uncontrolable factor
      (possibly entered by the user, which it may or may not have Quotes,
      or may or may not have the application followed by the filename) Then
      perhaps you should put limitations into the variable which reject any
      input given by the user that does not have quotes around it, or list
      some examples for the user so they know what format is accepted, and
      what is not.

      NOTE: Another very interesting thing I've found, is that IF the
            variable you want executed is in an .INI file (or any text
            file for that matter), the variable DOES NOT need to have the
            obligatory ' \ ' preceeding any special character. the script
            reads the variable from the .INI file or equiv., then that
            variable then becomes....'converted' to Auto-It
            accepted-lingo.

      try this;

      setenv, variable, %COMSPEC% /c
            c:\\program files\\mydirectory\\myfile.exe \/switch1 \/switch2
      run, %variable%

      i.e.

      instead of;                   you can have this;
      ----------------------------------------------------------------
      \\\\server\\share\\file.exe         \\Server\share\file.exe
      c:\\directory\\file.exe C:\directory\file.exe
                  %comspec% \/c c:\\directory\\file.exe %comspec% /c c:\directory\file.exe

      etc...
      If anyone finds any flaws in this, please let me know...
      I have a variable path depending on which system I plan to run
      scripts from, and it tries first one of the paths. If it finds it it
      executes it, if not it tries the next path/file location (as
      specificed in the .INI file) in sequence.

-----------------------------------------------------------------------------

Q #3: How do I play a WAV file from within AutoIt?

      ---------------------------------------------------------------------

A #1: use:

      Run, C:\windows\media\logoff.wav

      and the WAV file will "hijack" whatever sound player you use to play
      the sound.  I know there is a system call for the sounds but I don't
      know what it is.

      ---------------------------------------------------------------------

A #2: This is the line that windows uses to play a wav file.

      "C:\Program Files\Windows Media Player\mplayer2.exe"  /Play "%L"

      The way to get this information is to:
      *     open any folder in windows explorer.
      *     Click on the view menu and choose options,
      *     click the file types tab
      *     scroll down to the file type you want (in this case .wav).
      *     Click on the edit button
      *     Click play and edit again.

      Now you will see the application used to perform this action and in
      that window you will see the above line.

      replace "%L" with "c:\windows\media\hi.wav" or whatever your wav file
      is.


-----------------------------------------------------------------------------

Q #4: Why doesn't the DOS command window close when I do this?

      Run, "net" "use r: \\\\hotfurn1\\bin"  doesn't work

      ---------------------------------------------------------------------

A #1: Try using:

      Run, %COMSPEC% /c net use  r: \\\\hotfurn1\\bin

      Using "%comspec% /C" has the advantage of closing the window after the
      command finishes instead of leaving it open.

-----------------------------------------------------------------------------

Q #5: Using the script below, how can I make sure that the default browser
      opens the hotmail site? I  would like to have this just for the
      default browser. I took a look at the Open command for HTMLFile in
      the registry and it had this: {Registry key:

      HKEY_CLASSES_ROOT\htmlfile\shell\open\command}
      "C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe" -nohome

      {Registry key:

      HKEY_CLASSES_ROOT\http\shell\open\command}
            "C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe" -nohome

      How would I strip the -nohome from the variable? Are there any string
      manipulation functions in AutoIt?

      Using this line does not work with either browser as default...
      Run, http://www.hotmail.com,,

      ; ======= Script Starts Here =======
      ; ============================================================
      ; Logs into a Hotmail account
      ; ========================={ES 11/01/00}======================

      ; Get the path to Netscape from the registry
      ; ========================={ES 01/11/01}======================
      ;RegRead, NSPath, REG_SZ, HKEY_LOCAL_MACHINE,

SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Netscape.exe,

;Run,%NSPath% http://www.hotmail.com,,

      ; Get the path to IE from the registry
      ; ========================={ES 11/01/00}======================
      ;RegRead, IEPath, REG_SZ, HKEY_LOCAL_MACHINE,
            SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\IEXPLORE.EXE,
      ;Run,%IEPath% http://www.hotmail.com,,

      WinWaitActive, Hotmail
      ; ========================={ES 11/01/00}======================
      ; Wait 5 seconds
      ; ========================={ES 11/01/00}======================
      Sleep, 5000

      ; ========================={ES 11/01/00}======================
      ; No longer needed as Hotmail now uses javascript to
      ; move the cursor to the UserID field
      ; ========================={ES 11/01/00}======================
      ; You may have to change these coordinates depending upon your screen resolution
      ;LeftClick, 260, 210

      ; Replace xxxxxxxx with your username:
      Send, xxxxxxxx
      Send, {TAB}
      ; ========================={ES 11/01/00}======================
      ; Extra tab is now needed
      ; ========================={ES 11/01/00}======================
      Send, {TAB}

      ; Replace yyyyyyyy with your password:
      Send, yyyyyyyy
      Send, {TAB}
      Send, {ENTER}
      ; ======= Script Ends Here =======

      ---------------------------------------------------------------------

A #1: Try this:

      run, %comspec% /c start http://www.hotmail.com,, min