Hello,

Sorry by writting directly to devel list, but I'm not being able to solve
this problem I'm in and thought maybe you would be so kind to take a look.
Thanks in advance :)

I'm having trouble in finding how to end openvpn programmatically in
windows. If I run openvpn in command line, I can end it graciously with F4.
What I want to do is to make my python program (or batch file/executable
program, can be in C/C++) do the same thing: end it gracioulsy, allow for
openvpn to do it's cleanup tasks.
Yet the only thing available to stop the process is taskkill /F /PID
<PID_NUMBER> that ends it immediately without allowing openvpn to do it's
cleanup tasks. If I don't use /F switch, it just ignores the command. I
tried  also with /T (Tree Kill). No luck.
I also tried to get openvpn pid and send it a signal using this python code
(it's python but it's easily understandable by anyone:

import ctypes
PROCESS_TERMINATE = 33
handle = ctypes.windll.kernel32.
OpenProcess(PROCESS_TERMINATE, False, <PID>)
ctypes.windll.kernel32.TerminateProcess(handle, -1)
ctypes.windll.kernel32.CloseHandle(handle)

I tried all signals ranging from 0 to 33. None did the job. Some are
plainly ignored, some terminate the processe forcefully.

A colleague of mine remembered that openvpn-gui does it the right way. I'm
also a c/C++ programmer, so I grab the source-code and try to find how it
does the trick, but I find it's a bit more hidden than I thought.
As far as I understood, the disconnect button calls the StopOpenVPN
funcion, which sets the o.cnn[config].connect_status field to DISCONNECT*ING
* and WatchOpenVPNProcess function tracks it and then disconnects. But if
i'm groking this right, the only thing it does besides setting
connect_status to DISCONECT*ED* is the following command:

     SendMessage(o.cnn[config].hwndStatus, WM_CLOSE, 0, 0);

Just closing the window, finishes it graciously ? why ? Am I missing the
point here ? Can you please tell me how you do the trick ?
If anyone else has some idea, I'll love to read it.

Thanx,
-Nelson

Reply via email to