Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

VB question

Options
  • 22-11-2001 4:50pm
    #1
    Registered Users Posts: 3,299 ✭✭✭


    what code would i write to shutdown a program,for talks sake i want to shutdown a program with a path "C:\KMD.EXE"
    also is VB case sensitave. thanx i have only started vb


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    well if I was doing it what I would do is
    1: Get the name of thing I want to kill
    2:Get a list of all the running processes on the machine(Win95/98 does this differently from winnt/2000)
    3: Iterate the process and pick the one you want to kill
    4: Then kill it

    there are several API calls that will allow u to do most of this stuff
    look up
    EnumProcesses, OpenProcess, GetVersionExA, TerminateProcess in MSDN. You should get some sample code there.

    if you don't give me a shout as I have some code that will do what you want


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    I think that's a bit advanced for a newbie, but it is the best way.

    Depending on the application you're trying to close, this *might* work:

    AppActivate "My Computer"
    SendKeys "%{F4}"

    That brings up the window whose title begins with "My Computer" and sends it ALT-F4, which will close it.

    This is a bad solution really, but until you can get the hang of the solution suggested by amen, it could do the job.

    VB isn't really case sensitive, you can type in code any old how and it will reformat it and all that for you. Some things are case sensitive, can't think of any right now.


    Oh, and if you were trying to close something like Notepad, where it might give a dialog asking if you want to save, you could use:

    SendKeys "%{F4}n"

    Which will send it alt-f4, and then "n", to select the "no" button on the dialog.

    Hope I've been of some help :)


Advertisement