Vinu Posted July 13, 2009 Share Posted July 13, 2009 (edited) I am not an expert but I have written code to change the IPSec preshared key password for L2TP / Automatic Vpn connection. Pls see code below Func SetRASKey() $RASCREDENTIALS=DllStructCreate("dword dwSize;dword dwMask;char szUserName[256];char szPassword[256];char szDomain[16]") If @error Then Return(False) EndIf DllStructSetData($RASCREDENTIALS,"dwMask",16) DllStructSetData($RASCREDENTIALS,"szUserName","") DllStructSetData($RASCREDENTIALS,"szPassword",<PreShared Key>) DllStructSetData($RASCREDENTIALS,"szDomain","") DllStructSetData($RASCREDENTIALS,"dwSize",DllStructGetSize($RASCREDENTIALS)) $ret=DllCall("rasapi32.dll","dword","RasSetCredentialsA","str","","str",<VPN Name>,"ptr",DllStructGetPtr($RASCREDENTIALS),"long",0) If Not @error Then If $ret[0] <> 0 Then Return(False) Else Return(True) EndIf Else Return(False) EndIf EndFunc As per MS Documentation the function returns 0 if successful and any non zero number error if failed. I correctly get this as 0 when parameters are correct and non zero when I change anything, but still the preshared key for the VPN I created in the Network Connections in control panel does not change..any ideas..?? I think we need to have RAS API translated into AutoIT in future versions as its very difficult otherwise P.S the 16 passed to dwMask to tell the function that Preshared key is to be set otherwise it sets the username password domain for that connection. You can see Microsoft doc at http://msdn.microsoft.com/en-us/library/aa377811(VS.85).aspx for more info on this function.Its used to set the Preshared Key/Username credentials for a connection entry(usually VPN) in the Network Connections panel in Windows control panel) any help to make this function work would be greatly appreciated. Edited July 13, 2009 by Vinu Link to comment Share on other sites More sharing options...
Vinu Posted July 14, 2009 Author Share Posted July 14, 2009 Ok I progressed to this point. This code seems to work but it does'nt completely. The issue is that the GetDllStructSize does not return correct size so I've passed size as 540 (constant). This does'nt throw up error but still the password is not set correctly ...any one with better ideas ??? ..Please help Func SetRASKey() $RASCREDENTIALS=DllStructCreate("dword dwSize;dword dwMask;char szUserName[257];char szPassword[257];char szDomain[16]") If @error Then Return(False) EndIf DllStructSetData($RASCREDENTIALS,"dwMask",16) DllStructSetData($RASCREDENTIALS,"szUserName","") DllStructSetData($RASCREDENTIALS,"szPassword",<Presharedkey> & Chr(0)) DllStructSetData($RASCREDENTIALS,"szDomain","") DllStructSetData($RASCREDENTIALS,"dwSize",540) $ret=DllCall("rasapi32.dll","dword","RasSetCredentialsA","str","","str",<VPN Name>,"ptr",DllStructGetPtr($RASCREDENTIALS),"long",0) If Not @error Then If $ret[0] <> 0 Then Return(False) Else Return(True) EndIf Else Return(False) EndIf EndFunc Link to comment Share on other sites More sharing options...
Vinu Posted July 16, 2009 Author Share Posted July 16, 2009 I am not an expert but I have written code to change the IPSec preshared key password for L2TP / Automatic Vpn connection. Pls see code below Func SetRASKey() $RASCREDENTIALS=DllStructCreate("dword dwSize;dword dwMask;char szUserName[256];char szPassword[256];char szDomain[16]") If @error Then Return(False) EndIf DllStructSetData($RASCREDENTIALS,"dwMask",16) DllStructSetData($RASCREDENTIALS,"szUserName","") DllStructSetData($RASCREDENTIALS,"szPassword",<PreShared Key>) DllStructSetData($RASCREDENTIALS,"szDomain","") DllStructSetData($RASCREDENTIALS,"dwSize",DllStructGetSize($RASCREDENTIALS)) $ret=DllCall("rasapi32.dll","dword","RasSetCredentialsA","str","","str",<VPN Name>,"ptr",DllStructGetPtr($RASCREDENTIALS),"long",0) If Not @error Then If $ret[0] <> 0 Then Return(False) Else Return(True) EndIf Else Return(False) EndIf EndFunc As per MS Documentation the function returns 0 if successful and any non zero number error if failed. I correctly get this as 0 when parameters are correct and non zero when I change anything, but still the preshared key for the VPN I created in the Network Connections in control panel does not change..any ideas..?? I think we need to have RAS API translated into AutoIT in future versions as its very difficult otherwise P.S the 16 passed to dwMask to tell the function that Preshared key is to be set otherwise it sets the username password domain for that connection. You can see Microsoft doc at http://msdn.microsoft.com/en-us/library/aa377811(VS.85).aspx for more info on this function.Its used to set the Preshared Key/Username credentials for a connection entry(usually VPN) in the Network Connections panel in Windows control panel) any help to make this function work would be greatly appreciated. Ok...Got it working finally. There is an entry called AuthRestrictions in rasphone.pbk(the file where connection details of Network conenctions are stored.It has the format of an .ini file) we should set this to 608 for L2TP and automatic protocol. Only then preshared key setting will be correctly used. I a mwriting this in case anyone has a similar issue they can apply the same settings Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted March 10, 2011 Share Posted March 10, 2011 Hi, I know this is a rather old post .. but does someone know the solution.. i'm unable to get a positive result I modified the Function in order to support Unicode (RasSetCredentialsW instead of RasSetCredentialsA)but still i'm unable to change the PreSharedKeyRasApi Error CodesFunc SetRASKey() $RASCREDENTIALS = DllStructCreate("dword dwSize;dword dwMask;char szUserName[256];char szPassword[256];char szDomain[16]") If @error Then Return (False) EndIf DllStructSetData($RASCREDENTIALS, "dwMask", 16) DllStructSetData($RASCREDENTIALS, "szUserName", "") DllStructSetData($RASCREDENTIALS, "szPassword", <PreSharedKey>) DllStructSetData($RASCREDENTIALS, "szDomain", "") DllStructSetData($RASCREDENTIALS, "dwSize", DllStructGetSize($RASCREDENTIALS)) $ret = DllCall("rasapi32.dll", "dword", "RasSetCredentialsW", "str", "", "str", <VPNEntry>, "ptr", DllStructGetPtr $RASCREDENTIALS), "long", 0) If Not @error Then If $ret[0] <> 0 Then Return (False & " : " & $ret[0]) Else Return (True) EndIf Else Return (False) EndIf EndFunc ;==>SetRASKey $Test = SetRASKey () Msgbox (0, "test", $Test) Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted March 11, 2011 Share Posted March 11, 2011 Solution found szUserName[256];char szPassword[256] must be changed into szUserName[257];char szPassword[257] and RasSetCredentialsA is correct Best Regards, Emiel Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
kubi Posted April 21, 2011 Share Posted April 21, 2011 I have code Func SetRASKey() $RASCREDENTIALS = DllStructCreate("dword dwSize;dword dwMask;char szUserName[257];char szPassword[257];char szDomain[16]") If @error Then Return (False) EndIf DllStructSetData($RASCREDENTIALS, "dwMask", 16) DllStructSetData($RASCREDENTIALS, "szUserName", "") DllStructSetData($RASCREDENTIALS, "szPassword","1234") DllStructSetData($RASCREDENTIALS, "szDomain", "IP number") DllStructSetData($RASCREDENTIALS, "dwSize", DllStructGetSize($RASCREDENTIALS)) $ret=DllCall("rasapi32.dll","dword","RasSetCredentialsA","str","","str","VPN Connection","ptr",DllStructGetPtr($RASCREDENTIALS),"long",0) If Not @error Then If $ret[0] <> 0 Then Return (False & " : " & $ret[0]) Else Return (True) EndIf Else Return (False) EndIf EndFunc ;==>SetRASKey $Test = SetRASKey () Msgbox (0, "test", $Test) me when you run codes got error message 621(Cannot open the phone book file.), help solution, please thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now