Results 1 to 8 of 8

Thread: keep cmd in focus

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Sydney
    Posts
    69

    Resolved keep cmd in focus

    Hi All,

    I'm executing a Shell() command to open a cmd terminal execute a file with arguments to login to a server. Now that works all fine. The problem arises when I try to send subsequent commands to the open connection because the cmd terminal closes as soon as the command is executed...

    so, in a typical cmd terminal box, I would execute the login command, as soon as it connects, it feeds a line and expects commands to be thrown at it.. it's kindof like a socket connection except it's got some funny login handling, which is why i'm not using winsock1.

    so is there a way I can keep the focus to the cmd prompt open, so that I can feed it commands after the initial login connection??

    thanks a lot

    Mike
    Last edited by mikepol; Nov 17th, 2004 at 06:21 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    If you shell the CMD.exe with /K (Keep open) and your bat file as
    the second parameter it will accomplish what you want. You will
    probably need to use complete file paths for all.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Sydney
    Posts
    69
    thanks for the reply!

    It worked half way -

    I executed cmd.exe /k and sent the inital parameters as a second argument and it worked fine.

    my issue is that I then want to send subsequent strings to the open cmd window.. they are not program names as such, but commands that are to be sent to the program that expects them to come in via the opened cmd window.

    getting there- just one more step..

    THANKS!

    m.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Can send all the commands as the second parameter?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Sydney
    Posts
    69
    I wish I could, that would be the end of the problem

    what happens is that using the second parameter, I simply 'login' to the program that I'm interfacing with, then the subsequent commands that I send to the program are sent after the login has authenticated... and those subsequent commands are expected to be sent form the same cmd terminal window that initiated the login...

    I guess all I need to do is to target the same cmd window and send strings to it... strings that are not executables or commands as such but strings that are expected to be accepted...

    my head right now >>

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Write a batch file with all the commands and shell it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Sydney
    Posts
    69
    okay, after a longish stint off because of other things, I finally did this.

    i placed the logon string as the first command, followed by a carriage return and the string that is to be sent to the logged in connection

    what happens is that the first commad executes fine and 'holds' the connection open, so that the second line of the bat file nexer executes, it's as if the first command executes and does not come back to the prompt to be able to execute the second command in the bat file...

    how can I send additional strings to the opened program in the cmd window?

    thanks for the help robDog

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2003
    Location
    Sydney
    Posts
    69

    Resolved

    i ended up using an ugly work around

    used FindWindow to get the cmd box handle and SendKeys to send subsequent strings/commands to it..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width