Results 1 to 8 of 8

Thread: Closing a command window [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349

    Closing a command window [RESOLVED]

    Guys,
    I really need help on closing a command window that i have created using the following code:

    VB Code:
    1. Public Function ExecCmd(cmdline$)
    2.     Dim proc As PROCESS_INFORMATION
    3.     Dim start As STARTUPINFO
    4.     Dim ret&
    5.     start.cb = Len(start)
    6.     ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
    7.     ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    8.     ret& = CloseHandle(proc.hProcess)
    9. End Function

    This is the usage of it:
    VB Code:
    1. Call ExecCmd(App.Path & "\rar a " & rarName & ".rar " & "*.*")

    Now the problem is that when i run the code on my XP machine it works perfectly, the window appears and compresses my files and then automatically closes itself. However, when i run it on a Win2K machine, the window appears, but does not close itself, rather i have to close it manually, which i don't want my users to have to do.

    Can anyone tell me why this code doesn't perform on 2K, or if there is a way to check if the window has closed and close it if it hasn't closed?

    Any help with this problem would be greatly appreciated, my boss is practically screaming for this to be finished.
    Last edited by Blinky Bill; Oct 29th, 2002 at 07:48 PM.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  2. #2
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    What's the program you're using to do this?
    Please rate my post.

  3. #3

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    A compression program called 'rar'
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  4. #4

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    *bump*
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  5. #5
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Debugging needed:
    VB Code:
    1. Public Function ExecCmd(cmdline$)
    2.     Dim proc As PROCESS_INFORMATION
    3.     Dim start As STARTUPINFO
    4.     Dim ret&
    5.     start.cb = Len(start)
    6. 'What is START at this point? Is it sensible?
    7. 'What is cmdline$ at this point? Is it correct and sensible?
    8.  
    9.     ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
    10. 'What is ret& at this point? Is it sensible?
    11. ' Has the process started correctly?
    12. ' What is proc at this point? Is it sensible?
    13. ' What is proc.hProcess at this point? Is it sensible?
    14.  
    15.     ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    16. 'What is ret& at this point? Is it sensible?
    17.  
    18.     ret& = CloseHandle(proc.hProcess)
    19. 'What is ret& at this point? Is it sensible?
    20.  
    21. End Function

  6. #6

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    cmdline$ is good and proper, because it works fine on every system. The program works fine on XP, i just tested it on another XP system, so i think it doesn't work on 98, 2K, etc. Is there some other method to achieve what i want that works on the older oses?

    Unfortunately, i cannot test on the 2K system because it has gone walkies for the day.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  7. #7

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Okay, i've just managed to test the code on the 2K machine, and i get identical results as on the XP machine, but the program doesn't close automatically.

    What happens is that in the following code
    VB Code:
    1. Public Function ExecCmd(cmdline$)
    2.     Dim proc As PROCESS_INFORMATION
    3.     Dim start As STARTUPINFO
    4.     Dim ret&
    5.     start.cb = Len(start)
    6.     MsgBox (start.cb)
    7.     ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
    8.     MsgBox (ret&)
    9.     ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    10.     MsgBox (ret&)
    11.     ret& = CloseHandle(proc.hProcess)
    12.     MsgBox (ret&)
    13. End Function

    i get the values 68, 1, 0, 1 on both systems, but i have to close the external app before i get the last two values.

    Does anyone know what this means? Cause i'm banging my head against a brick wall here at the moment.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

  8. #8

    Thread Starter
    Hyperactive Member Blinky Bill's Avatar
    Join Date
    Mar 2002
    Location
    Happily munching on the greenery in your garden
    Posts
    349
    Okay, thanx guys, but i finally got a solution to the problem, well a hack to solve this one, but whatever works right?

    What i ended up doing was creating a pif file for the dos program i am running that told the os to close it on exit. Don't know why the code i was given didn't do exactly that like it was supposed to, but anyway, it works and that is a good thing.

    Thanx all for the help.
    We don't know what's wrong. . . So the best bet might be to remove something surgically.

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