While it was restarting I had time to translate this routine to PB.
PB 5.31 to 5.60 32 bit ONLY
Code: Select all
;Unicode & ansi write to credential manager
;just change sPwrd$, sUname$ and sDomain$
; Variable translation from c# to PB: http://purebasic.fr/english/viewtopic.php?p=151705#p151705
;
EnableExplicit
; THESE ARE THE VARIABLES YOU WANT TO CHANGE
Global sPwrd$="OrangeSenility"
Global sUname$="POTUS"
Global sDomain$="back2USSR"
Global sComent$=""
#dllAdvapi32=256 ; any number
;CRED_TYPE
#CRED_TYPE_GENERIC = 1
#CRED_TYPE_DOMAIN_PASSWORD = 2
#CRED_TYPE_DOMAIN_CERTIFICATE = 3
#CRED_TYPE_DOMAIN_VISIBLE_PASSWORD = 4
;CRED_PERSIST
#CRED_PERSIST_SESSION = 1
#CRED_PERSIST_LOCAL_MACHINE = 2
#CRED_PERSIST_ENTERPRISE = 3
;CRED_
#CRED_PRESERVE_CREDENTIAL_BLOB = 1
Structure _CREDENTIAL_ATTRIBUTE ;not really needed
Keyword.l ;LPTSTR
Flags.l
ValueSize.l
Value.l ;LPBYTE
EndStructure
Structure _credential
flags.l
type.l
targetName.l ;LPTSTR
comment.l
LastWritten.FILETIME
credentialSize.l
credentialBlob.l ; LPBYTE
persist.l
attributeCount.l
attributes.l ;pointer to _CREDENTIAL_ATTRIBUTE if needed
targetAlias.l
UserName.l
EndStructure
Prototype CredWriteW( credential.l, flags.l = 0)
Prototype CredReadW( TargetName$, Type.l, Flags.l, *Credential)
If OpenLibrary(#dllAdvapi32, "advapi32.dll")
CompilerIf #PB_Compiler_Unicode
Define CredWriteW_.CredWriteW = GetFunction(#dllAdvapi32, "CredWriteW")
Define CredReadW_.CredreadW = GetFunction(#dllAdvapi32, "CredReadW") ; didn't have time to add CredReadW sample
CompilerElse
Define CredWriteW_.CredWriteW = GetFunction(#dllAdvapi32, "CredWriteA")
Define CredReadW_.CredreadW = GetFunction(#dllAdvapi32, "CredReadA")
CompilerEndIf
Define cred._credential
With cred
\flags=0
\type=#CRED_TYPE_DOMAIN_PASSWORD
\targetName=@sDomain$
\UserName=@sUname$
\comment=@sComent$
\attributeCount=0
\attributes=0
\targetAlias=0
\persist=#CRED_PERSIST_LOCAL_MACHINE
\credentialSize=StringByteLength(sPwrd$)
\credentialBlob=@sPwrd$
EndWith
If CredWriteW_(@cred)
Debug "Created credentials for: " + sDomain$
Else
Debug "look up error code:"+ Str(GetLastError_())+ " @ https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx"
EndIf
EndIf
Hope some one finds a use for this.
Latest Symantec is killing my PB stuff so now I disable the antivirus for the period of time I am trying to compile something in PB.
Norm.