Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Navigating a Windows Program via CMD Batch?  (Read 7013 times)

0 Members and 1 Guest are viewing this topic.

pheNom

    Topic Starter


    Starter

    Navigating a Windows Program via CMD Batch?
    « on: February 11, 2009, 08:21:40 AM »
    My first post on your boards, but I've spent the past few days making this site and forum my bible for Batching :P

    There's one thing I've not been able to find, however, and that is;

    Am I able to navigate a windows program with a GUI via CMD batch files?

    I'm attempting to make a batch file that will;

    1) Run Fraps, change the "Destination" path for saving captured footage to a folder with the date, for example. Doesn't have to be, all I want is a new subdirectory automatically created so I don't "forget" and save new footage with old footage
    2) Run Ventrilo, connect to a server, and automatically join the channel I want
    3) Run World of Warcraft


    The idea is that while I'm logging into WoW and loading, the batch file will do all the Ventrilo and Fraps tedium for me quietly in the background.

    Is this possible?

    I've made the script to run each of those programs seperately, or all in sequence (via "CHOICE.COM") calling multiple batch files, however, I just can't figure out how to emulate actions within a program through the batch.

    Could anyone tell me if this is possible? Or if not, does anyone know of a link to a compendium of the ASCII codes for emulating keystrokes in CMD with "StuffIt"? That would absolve the need for me to use CMD for that step... the program was just written in 1991 so there isn't a lot of documentation floating around anymore.


    Thank you in advance if anyone can help with this. I am extremely new to Batch scripting so I don't actually know everything that is possible through Batch files.

    I can post my script when I get off work if it would make anyones lives easier.

    GuruGary



      Adviser
      Re: Navigating a Windows Program via CMD Batch?
      « Reply #1 on: February 11, 2009, 09:01:58 AM »
      Batch files are probably not what you want for what you are trying to do in #1 and #2.  You can probably use VBS with SENDKEYS to do what you are looking for, but not being familiar with any of the programs you listed, I can't really help.

      Can you provide more details on what you want?  For example, what is the full path to the file that runs Fraps, and what keys do you press (without using the mouse) to change the destination path? And similar details on the other 2 tasks.

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: Navigating a Windows Program via CMD Batch?
      « Reply #2 on: February 11, 2009, 09:05:54 AM »
      VBS doesn't have sendkeys.
      I was trying to dereference Null Pointers before it was cool.

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: Navigating a Windows Program via CMD Batch?
      « Reply #3 on: February 11, 2009, 09:25:51 AM »
      Code: [Select]
      Syntax
      Visual Basic (Declaration)
      Public Class SendKeys

      Visual Basic (Usage)
      Dim instance As SendKeys

      C#
      public class SendKeys

      Visual C++
      public ref class SendKeys



      pheNom

        Topic Starter


        Starter

        Re: Navigating a Windows Program via CMD Batch?
        « Reply #4 on: February 11, 2009, 10:09:31 AM »
        Batch files are probably not what you want for what you are trying to do in #1 and #2.  You can probably use VBS with SENDKEYS to do what you are looking for, but not being familiar with any of the programs you listed, I can't really help.

        Can you provide more details on what you want?  For example, what is the full path to the file that runs Fraps, and what keys do you press (without using the mouse) to change the destination path? And similar details on the other 2 tasks.

        Full path to the file that runs Fraps..

        C:\Fraps  I just used
        Code: [Select]
        cd/
        cd fraps
        START fraps.exe

        The keystrokes to use to navigate Fraps' menu I haven't tried yet, however, for Ventrilo.. which is
        C:\Program Files\Ventrilo
        Code: [Select]
        cd/
        cd "program files\ventrilo"
        START ventrilo.exe
        I would need to hit O (For Connect) and then Tab 9 times, Down Arrow once and Return once to join the desired channel. The StuffIt code for Tab, Down Arrow and Enter is listed, but not O.. and I don't know where to find that so I was kinda stuck there.

        For World of Warcraft it's simple, since I have a "run" shortcut already made for it. I just;
        Code: [Select]
        START wow
        But the path is C:\Users\Public\Games\World of Warcraft\

        If I have to use VB and SendKeys I guess I'll do that, I just didn't want to go through all the extra stuff involved there.. compiling, a GUI,  etc. I just wanted a quick batch job heh.

        Thanks a lot.

        Geek-9pm


          Mastermind
        • Geek After Dark
        • Thanked: 1026
          • Gekk9pm bnlog
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Navigating a Windows Program via CMD Batch?
        « Reply #5 on: February 11, 2009, 10:25:37 AM »
        Quote
        I just wanted a quick batch job heh.

        Wait! Don't go away mad!

        Look at this:
        http://www.download.com/Quick-Macros/3000-2084_4-10254443.html?tag=mncol

        This is but one of a number of "Keyboard Macro"  programs where you define keystrokes, save it in a file, and later can invoke it as a shortcut.
        After a bit of reading, you can do this faster that writing something with Visual Basic. But not as much fun. Somebody else did all the work!


        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: Navigating a Windows Program via CMD Batch?
        « Reply #6 on: February 11, 2009, 10:31:44 AM »
        Code: [Select]
        Syntax
        Visual Basic (Declaration)
        Public Class SendKeys

        Visual Basic (Usage)
        Dim instance As SendKeys

        C#
        public class SendKeys

        Visual C++
        public ref class SendKeys




        First - Visual Basic is NOT VBScript. I tested to make sure sendkeys didn't exist before posting.

        Secondly - that's .NET, which is even further from the roots of VBScript, which originally branched off Visual Basic 5 (and was updated to include the VB6 Functions InstrRev,Split,Join, and so forth later on). (Some may say that it branched off from VBA, but on the other hand VBA was integrated into Visual Basic at version 4)
        And Of course... Visual Basic 5 or 6 aren't easy to find OR free.

        Also sendkeys is busted in the .NET framework. One would need to use the SendInput() APIs instead.
        I was trying to dereference Null Pointers before it was cool.

        GuruGary



          Adviser
          Re: Navigating a Windows Program via CMD Batch?
          « Reply #7 on: February 11, 2009, 11:02:25 AM »
          First - Visual Basic is NOT VBScript. I tested to make sure sendkeys didn't exist before posting.
          I am almost certain that I have used SENDKEYS in VBS before. It's possible that it was VB, but I am pretty sure it was VBS.  I'll try to get in front of that computer and look through my scripts.

          GuruGary



            Adviser
            Re: Navigating a Windows Program via CMD Batch?
            « Reply #8 on: February 11, 2009, 11:12:50 AM »
            SENDKEYS does work in VBS.  Try this as a VBS:

            Code: [Select]
            set WshShell = CreateObject("WScript.Shell")
            WshShell.Run "notepad.exe"
            WScript.Sleep 1000
            WshShell.AppActivate "Notepad"
            WScript.Sleep 200
            WshShell.SendKeys "This should put some text in a notepad document"
            WScript.Sleep 200
            WshShell.SendKeys "%F"
            WScript.Sleep 200
            WshShell.SendKeys "A"
            WScript.Sleep 200
            WshShell.SendKeys "C:\VBS_SendkeysTest.txt"
            WScript.Sleep 200
            WshShell.SendKeys "%S"

            It should start NOTEPAD, enter some text (using SENDKEYS), and then use SENDKEYS to open the File menu -> Save As -> C:\VBS_SendkeysTest.txt and [Alt-S] to save.

            GuruGary



              Adviser
              Re: Navigating a Windows Program via CMD Batch?
              « Reply #9 on: February 11, 2009, 11:32:01 AM »
              I would need to hit O (For Connect) and then Tab 9 times, Down Arrow once and Return once to join the desired channel.
              In VBS, I think you could do something like:
              Code: [Select]
              set WshShell = CreateObject("WScript.Shell")
              WshShell.Run "program files\ventrilo\ventrilo.exe"
              WScript.Sleep 1000
              WshShell.SendKeys "O"
              WScript.Sleep 200
              WshShell.SendKeys "{TAB 9}{DOWN}{ENTER}"

              BC_Programmer


                Mastermind
              • Typing is no substitute for thinking.
              • Thanked: 1140
                • Yes
                • Yes
                • BC-Programming.com
              • Certifications: List
              • Computer: Specs
              • Experience: Beginner
              • OS: Windows 11
              Re: Navigating a Windows Program via CMD Batch?
              « Reply #10 on: February 11, 2009, 11:43:41 AM »
              technically VBScript doesn't have sendkeys- the windows scripting host does- so Javascript,Perl, etc can all use the same sendkeys Appactivate, etc.

              in pure VB it's a statement- same with appactivate, as well as a few other statements...- this is what I was referring to.

              Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

              I was trying to dereference Null Pointers before it was cool.

              Geek-9pm


                Mastermind
              • Geek After Dark
              • Thanked: 1026
                • Gekk9pm bnlog
              • Certifications: List
              • Computer: Specs
              • Experience: Expert
              • OS: Windows 10
              Re: Navigating a Windows Program via CMD Batch?
              « Reply #11 on: February 11, 2009, 12:02:22 PM »
              Quote
              Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

              Sorry about my confusing post.
              It is in the .NET framework class library.

              pheNom

                Topic Starter


                Starter

                Re: Navigating a Windows Program via CMD Batch?
                « Reply #12 on: February 11, 2009, 12:06:39 PM »
                Thank you all very much.

                I'm at work right now so I can't test out that macro program you linked, Geek, but I can't wait to get home and mess around with it.

                Looks like it'll do everything I need it to, AND everything the original batch was already doing. Hah. Easymode :P

                ...but since I love code I'm gonna spend the rest of my day at work with SendKeys in VBS. See what I can do with that.

                God, I love working in IT. Nobody can give you a hard time if your screens are filled with scripts and coding that they don't understand! ...until a printer breaks, or one of their cables gets unplugged. *sigh* -_-

                Love these boards btw. Fastest replies, with actual relevant information, I've ever seen.


                BC_Programmer


                  Mastermind
                • Typing is no substitute for thinking.
                • Thanked: 1140
                  • Yes
                  • Yes
                  • BC-Programming.com
                • Certifications: List
                • Computer: Specs
                • Experience: Beginner
                • OS: Windows 11
                Re: Navigating a Windows Program via CMD Batch?
                « Reply #13 on: February 11, 2009, 01:18:09 PM »
                Quote
                Additionally I was confused as to where Geek9pm found a class called sendkeys, given it's actually a method of the WSH...

                Sorry about my confusing post.
                It is in the .NET framework class library.

                No worries :) An entire class devoted to sending keys... intriguing...

                Assume whenever I say Visual Basic and forget to say which kind, that I mean 6  :)
                I was trying to dereference Null Pointers before it was cool.