How can I programmatically create a Windows VPN connection?

后端 未结 7 908
小鲜肉
小鲜肉 2021-02-01 22:23

I have a support environment where we connect to many of our customers\' systems using VPN and Remote Desktop. Right now, support personnel have to manually set up the VPN conne

7条回答
  •  深忆病人
    2021-02-01 22:50

    I know the question is very old but i had same issue and solve it with this C# code. Maybe it helps to somebody.

    First, create vpn connection in your personal computer. It will be storage in %userprofile%\AppData\Roaming\Microsoft\Network\Connections\PBK

    then open the rasphone.pbk file with a text editor ( for ex. Notepad++) and copy your connect informations. But don't forget. Before this step, you have to be completed to your connection settings. And then, copy your connection informations from rasphone.pbk file and paste into the script (to rasphone string). Tip: rasphone.pbk file contains just settings. No username and passwords...

    In my code, I create a connection with these settings;
    Connection Name : RAS -> At first Line [RAS]
    Connection Ip : ras.ugurturhal.com
    VPN Type: PPTP, supported CHAP and MS-CHAP v2 protocols

    The code is check your VPN connections. If you have a connection which name is RAS or IP adress is ras.ugurturhal.com, code changes nothing and warn to you. If you have a lot of VPN connections and none of them have same settings (on above), it will also "ADD" this VPN. And the last thing, if you have no VPN connection, it will be create a new one.

    Note: You can't see the VPN connection which you created by C# on your networks. But it will be work. And after the restart to computer, will see it on your networks :)

    I hope it will helps to somebody..

    And you can download of my project file from my Web Host..

    Regards.

    PS : I tried to add all of my codes to here but very new in stackoverflow. Please forgive me. You can download the sample ;)

    PS2 : Or you can check it from GitHub. Thanks @axrwkr

提交回复
热议问题