Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Run .pbk file in my software



  • Dear friends, I face to a new challenge with QT C++
    I want run .pbk (vpn l2tp ipsec file) run in my code.
    And I don't know how I can run or execute this kind of files and I don't know , how can I pass some parameters such Username / Password / Server(HostName) and.....to this file.
    Is there any one here to help me please?


  • Lifetime Qt Champion

    Hi
    That is a data file. I think its a RAS phone book files.
    In older windows, it was handled by
    c:\Windows\system32\Rasdial.exe
    but nowadays there is also
    rasphone -d "VPN connection name"

    In any case, your app cannot just "execute it"
    You need to use native api or QProcess to call a command line to
    do the connection.
    Some also use powerscripts to setup the connection. i seen on google.



  • @mrjj Dear friends thanks for your help.
    my software get Username / Password and another L2TP/IPsec VPN connection from JSON and then I must pass these data as a parameter to this .pbk file and software connect to the VPN as automatically.
    If I user QProcess I can run and pass parameters to this .pbk file?


  • Lifetime Qt Champion

    @saeidparand
    Hi
    You would run rasdial with QProcess , pointing to the pbk file.
    yes. you can give user name and password.
    https://ss64.com/nt/rasdial.html

    However, this is not very secure. It would be easy to replace the
    rasdial.exe with an evil program that would then be able to steal the
    username and password.



  • @mrjj said in Run .pbk file in my software:

    ss

    thanks for your description.
    you said this is not more secure.....
    what is your opinion for solving this problem?
    because security is very important for this software.



  • @mrjj
    in fact I want to make a VPN connection as L2TP/IPsec in my software background.
    I googled and found , I can use .pbk file and set username / password and host name as parameters in my code.
    How can I handle this problem?
    best regards dear friend.



  • @mrjj
    I have Written this code :

    QProcess process;
    QString program = "F:/dev/wrokspace/QT-PROJECTS/sql_DB/L2TP-Connection.pbk";
    //QString program = "C:/Users/m/AppData/Local/NextVPN/NextVPN.exe";
    QStringList arguments = QStringList();
    
    arguments<< "[VPN]";
    arguments<< "MEDIA=rastapi";
    arguments<< "Port=VPN2-0";
    arguments<< "Device=WAN Miniport (IKEv2)";
    arguments<< "DEVICE=vpn";
    arguments<< "PhoneNumber=123456";
    QString user="user";
    QString pass="pass";
    
    arguments<< "rasdial \"VPN\" " +user + " " + pass + " /phonebook:\"" + program ;
    bool ret= process.startDetached(program,arguments);
    qDebug() << arguments;
    qDebug() << ret; ==> return false If I call the L2TP-Connection.pbk but If I call the NextVPN.exe returns true and of course I want run .pbk file in background , but this code open a new wizard.
    

    How can I solve this problem? :(


  • Lifetime Qt Champion

    Hi
    I dont know what NextVPN.exe is.
    It might take a parameter to be hidden.
    if not, there is nothing to do about it.

    rasdial is an exe file and normally not an argument so
    not sure i understand what you code tries.
    NextVPN needs other exe to work or why are you give rasdial.exe to next vpn ??


  • Lifetime Qt Champion

    Hi
    Had to try it.
    alt text

    I took empty pbk file.
    added a connection called MYNAME with the server settings
    and did not store username and password
    then i called it via rasdial
    rasdial MYNAME username password /PHONEBOOK:e:\secret.pbk
    and it just connected without show any dialogs etc.



  • @mrjj
    I use this command , unfortunately It doesn't work.
    It's thrown 623 Error code. even though I use this command in CMD as you wrote.
    can I use this command in QT
    system("rasdial ...............")
    ?


  • Lifetime Qt Champion

    Hi

    error 623 - System could not find the phone book entry for this connection

    so i think you are just trying random stuff and hope it works.

    the MYNAME in my example is the actual name of the connection entry in the phone book.
    you must match the name you used when you created the entry.

    you can use QProcess to run it as i did in the cmd prompt.
    system() also works but its considered bad pratice.
    besides - QProcess give far better feedback options.

    make sure all data matches up.
    both entry name and location of the pbk file.



  • @mrjj
    I know that error 623 is about phone book , but I am wonder that pbk file is exist and my path I'm sure is correct even all the input parameters are correct I'm sure but I don't know what the CMD thrown this error code.



  • @mrjj
    It has solved.
    thanks for your help.
    I just copy the .pbk file into this path. windows/system32/rast
    best regards dear friends


  • Lifetime Qt Champion

    @saeidparand
    that is good to hear :)


Log in to reply