Jump to content

How can i create Dllstructure??


Go to solution Solved by Starstar,

Recommended Posts

Try this:

Local Const $UNLEN=256
Local Const $PWLEN = 256
Local Const $CNLEN =15
Local Const $DNLEN =$CNLEN


$sTagRASCREDENTIALS = "dword dwSize;dword dwMask;wchar szUserName[" & $UNLEN+1 & "];wchar szPassword["& $PWLEN+1 & "];wchar szDomain[" & $DNLEN+1 &"]"
Local $tTRASCREDENTIALS=DllStructCreate($sTagRASCREDENTIALS)
DllStructSetData($tTRASCREDENTIALS,"dwSize",DllStructGetSize($tTRASCREDENTIALS))
DllStructSetData($tTRASCREDENTIALS,"dwMask",10)
DllStructSetData($tTRASCREDENTIALS,"szUserName","gh1010")
DllStructSetData($tTRASCREDENTIALS,"szPassword","aghh0")
DllStructSetData($tTRASCREDENTIALS,"szDomain","")
$phnbook ="C:\Users\Adnan\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk"
$entry ="hm"
$msg = DllCall("Rasapi32.dll","DWORD","RasSetCredentialsW","wstr",$phnbook,"wstr",$entry,"ptr",DllStructGetPtr($tTRASCREDENTIALS),"BOOl",true)
MsgBox(0,@error,$msg[0])

Saludos

Link to comment
Share on other sites

You got this:

ERROR_ACCESS_DENIED

One of the following conditions occurred:

  • The calling application attempted to set default credentials for a per-user connection. Default credentials can be set only for an all-user connection.
  • The user does not have the correct privileges to set pre-shared keys or credentials for all users in case of all-user connectoids. Only administrators can complete these tasks.

 ERROR_ACCESS_DENIED = 5 !

 

Updated your code a bit:

Global Const $UNLEN = 256
Global Const $PWLEN = 256
Global Const $CNLEN = 15
Global Const $DNLEN = $CNLEN

Global Const $RASCM_UserName = 0x00000001
Global Const $RASCM_Password = 0x00000002
Global Const $RASCM_Domain = 0x00000004
Global Const $RASCM_DefaultCreds = 0x00000008
Global Const $RASCM_PreSharedKey = 0x00000010
Global Const $RASCM_ServerPreSharedKey = 0x00000020
Global Const $RASCM_DDMPreSharedKey = 0x00000040

Global Const $RASBASE = 600
Global Const $ERROR_CANNOT_OPEN_PHONEBOOK = $RASBASE + 21
Global Const $ERROR_CANNOT_FIND_PHONEBOOK_ENTRY = $RASBASE + 23

Global Const $sTagRASCREDENTIALS = "dword dwSize;dword dwMask;wchar szUserName[" & $UNLEN + 1 & "];wchar szPassword[" & $PWLEN + 1 & "];wchar szDomain[" & $DNLEN + 1 & "]"


Global $tTRASCREDENTIALS = DllStructCreate($sTagRASCREDENTIALS)
DllStructSetData($tTRASCREDENTIALS, "dwSize", DllStructGetSize($tTRASCREDENTIALS))
DllStructSetData($tTRASCREDENTIALS, "dwMask", BitOR($RASCM_DefaultCreds, $RASCM_Password))
DllStructSetData($tTRASCREDENTIALS, "szUserName", "gh1010")
DllStructSetData($tTRASCREDENTIALS, "szPassword", "aghh0")
DllStructSetData($tTRASCREDENTIALS, "szDomain", "")

Global $phnbook = "C:\Users\Adnan\AppData\Roaming\Microsoft\Network\Connections\Pbk\rasphone.pbk"   ;select phonebook
$phnbook = 0    ; or use default phonebook
Global $entry = "hm"
Global $fClearCredentials = True


Global $aRet
If $phnbook Then
    $aRet = DllCall("Rasapi32.dll", "DWORD", "RasSetCredentialsW", "wstr", $phnbook, "wstr", $entry, "ptr", DllStructGetPtr($tTRASCREDENTIALS), "BOOL", $fClearCredentials)
Else
    $aRet = DllCall("Rasapi32.dll", "DWORD", "RasSetCredentialsW", "ptr", 0, "wstr", $entry, "ptr", DllStructGetPtr($tTRASCREDENTIALS), "BOOL", $fClearCredentials)
EndIf

MsgBox(0, "", $aRet[0])

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

funkey you are wright................i think 

i does not have the correct privileges to set pre-shared keys or credentials for all users in case of all-user connectoids. Only administrators can complete these tasks.

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Topic Title is (@error) Sorry Error is 0 Retrun array is 5.

look at image i uploaded........

post-76662-0-54498400-1398875691.jpg

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

  • Solution

Thanks a lot of you all especially thanks to Funkey and Danyfirex. At the last Error bad parameter solved........Correct and healthy Code is.........

Local Const $UNLEN=256
Local Const $PWLEN = 256
Local Const $CNLEN =15
Local Const $DNLEN =$CNLEN

$sTagRASCREDENTIALS = "struct;dword dwSize;dword dwMask;wchar szUserName[" & $UNLEN+1 & "];wchar szPassword["& $PWLEN+1 & "];wchar szDomain[" & $DNLEN+1 &"];endstruct"
Local $tTRASCREDENTIALS=DllStructCreate($sTagRASCREDENTIALS)
DllStructSetData($tTRASCREDENTIALS,"dwSize",DllStructGetSize($tTRASCREDENTIALS))
DllStructSetData($tTRASCREDENTIALS,"dwMask",1+2) ; 1 for Username and 2 for Password +3 if you need to enter domain
DllStructSetData($tTRASCREDENTIALS,"szUserName","test")
DllStructSetData($tTRASCREDENTIALS,"szPassword","test")
DllStructSetData($tTRASCREDENTIALS,"szDomain","")
$phnbook =@AppDataDir & "Microsoft\Network\Connections\Pbk\rasphone.pbk"
$entry ="hm"
$msg = DllCall("Rasapi32.dll","DWORD","RasSetCredentialsW","wstr",$phnbook,"wstr",$entry,"struct*",$tTRASCREDENTIALS,"BOOl",FALSE)
MsgBox(0,@error,$msg[0])
Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

Link to comment
Share on other sites

Hi. Do not pass false as string. just use False.

Saludos

ok and thanks.............

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...