如何启动vpn拨号实际上后来我发现了通过启用windows的一个拨号程序加上拨号名可以打开vpn拨号。 WinExec('rasphone.exe -h '+cns_VPN,SW_SHOWNORMAL); 'cns_VPN 拨号名称常数 另外,拨号的快捷方式比较特殊,看不到调用的程序。也不能通过shellexecute调用快捷方式。 还有,这个拨号程序或者直接把拨号加入启动都不会自动连线,而是出现拨号的登录画面,所以需要一小段程序自动在拨号按钮上点击: function TForm1.openVPN: boolean; var hMain,hChild:HWND; begin Result := false; hMain:=FindWindow(nil,Pchar(edit1.text)); '标题 if hMain<>0 then begin hChild := FindWindowEx(hMain,0,'BUTTON',pCHAR(edit2.text)); '按钮上的文字 if hChild<>0 then begin SendMessage(hChild,WM_LBUTTONDOWN,10,10); SendMessage(hChild,WM_LBUTTONUP,10,10); Result := true; end; end; end;
WinExec('rasphone.exe -h '+cns_VPN,SW_SHOWNORMAL);
'cns_VPN 拨号名称常数
另外,拨号的快捷方式比较特殊,看不到调用的程序。也不能通过shellexecute调用快捷方式。
还有,这个拨号程序或者直接把拨号加入启动都不会自动连线,而是出现拨号的登录画面,所以需要一小段程序自动在拨号按钮上点击:
function TForm1.openVPN: boolean;
var
hMain,hChild:HWND;
begin
Result := false;
hMain:=FindWindow(nil,Pchar(edit1.text)); '标题
if hMain<>0 then begin
hChild := FindWindowEx(hMain,0,'BUTTON',pCHAR(edit2.text)); '按钮上的文字
if hChild<>0 then begin
SendMessage(hChild,WM_LBUTTONDOWN,10,10);
SendMessage(hChild,WM_LBUTTONUP,10,10);
Result := true;
end;
end;
end;
断线
WinExec('rasphone.exe -d '+cns_VPN,SW_SHOWNORMAL);