| View previous topic :: View next topic |
| Author |
Message |
bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Wed Mar 10, 2004 3:39 pm Post subject: VDSUG API Help |
|
|
I decided to dive into the API thing and I need help. PLEASE
The first part of code is some I found on the net for LOGON to a domain or inpersonate. The VDS part is what I sort of put together.
I kind of get what’s going on here but I not sure how to finish it or if I'm even on the right track. I would appreciate a little code help to get me started.
| Code: |
' --------------------
Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" ( _
ByVal username As String, _
ByVal domain As String, _
ByVal password As String, _
ByVal logonType As Integer, _
ByVal logonProvider As Integer, _
ByRef token As IntPtr _
) As Integer
Private Const LOGON32_LOGON_NETWORK As Integer = 3
Private Const LOGON32_PROVIDER_DEFAULT As Integer = 0
Private Sub DoSomething()
' Log on a specific user.
Dim token As IntPtr
Dim bSuccess As Boolean = Convert.ToBoolean( _
LogonUser( _
"authorisedusername", "DOMAIN-NAME", "password", _
LOGON32_LOGON_NETWORK, _
LOGON32_PROVIDER_DEFAULT, token))
' bSuccess is True at this point.
' Create a Windows principal from the logon token.
Dim ident As New System.Security.Principal.WindowsIdentity(token)
' The Name property of ident is set correctly at this point, and the
' AuthenticationType property is "NTLM". However, the IsAuthenticated
' property is False.
Dim ctx As System.Security.Principal.WindowsImpersonationContext = _
ident.Impersonate()
Response.Redirect("http://localhost/test/success.htm";)
End Sub
'----------------------
|
| Code: |
EXTERNAL @path(%0)vdsug.dll
UG DLLLOAD, 1, advapi32.dll
UG DLLINITFUNC, 1, 1, LogonUserA
OPTION SCALE, 96
TITLE test
DIALOG CREATE,Test,-1,0,361,213
DIALOG ADD,BUTTON,Test,4,292,60,22
DIALOG ADD,EDIT,EDIT1,16,68,180,19,username
DIALOG ADD,EDIT,EDIT2,42,68,180,19,domain
DIALOG ADD,EDIT,EDIT3,68,68,180,19,password
DIALOG ADD,EDIT,EDIT4,94,68,180,19,logontype
DIALOG ADD,EDIT,EDIT5,120,68,180,19,logonprovider
DIALOG SHOW
%%username = @dlgtext(edit1)
%%domain = @dlgtext(edit2)
%%password = @dlgtext(edit3)
%%logontype = @dlgtext(edit4)
%%logonprovider = @dlgtext(edit5)
:EVLOOP
WAIT EVENT
goto @event()
:TestBUTTON
%%username = @ug(DLLFUNC, username, str)
%%domain = @ug(DLLFUNC, domain, str)
%%password = @ug(DLLFUNC, password, str)
%%logontype = @ug(DLLFUNC, logonType, int)
%%logonprovider = @ug(DLLFUNC, logonProvider, int)
goto evloop
:CLOSE
exit
|
|
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Wed Mar 10, 2004 5:47 pm Post subject: |
|
|
Did U take a look at that DSU - it comes with full source code.
I am too busy to convert it to VDSUG
may be U can try my dll also - using VDSUG that would be a single line of code with VDSUG _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Wed Mar 10, 2004 5:48 pm Post subject: |
|
|
I'll take a look
Thanks |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Wed Mar 10, 2004 6:53 pm Post subject: |
|
|
Hi bbelcher
I have not used vdsug for quite sometime but feel my syntax is correct but still seems not to work. May be the last paramter has a problem.
To learn API prolly you can try sipmler fuctions first.
The dll I mentioned works same a RunAs and will run any app as a different user under Win 2k/XP/2003. If U want I can convert it to a vds dll.
BTW I think this thread is more suitable in Advanced Discussion Forums. So it has been moved.
| Code: | DIRECTORY CHANGE,@PATH(%0)
EXTERNAL VDSUG
UG DLLLOAD,1,advapi32.dll
UG DLLINITFUNC,1,1,LogonUserA
DIALOG CREATE,RunAs Demo,-1,0,257,268
DIALOG ADD,EDIT,EDIT1,22,26,180,19
DIALOG ADD,EDIT,EDIT2,61,27,180,19
DIALOG ADD,EDIT,EDIT3,100,27,180,19,,,PASSWORD
DIALOG ADD,EDIT,EDIT4,143,26,180,19
DIALOG ADD,BUTTON,BUTTON1,177,23,187,37,Logon,,DEFAULT
DIALOG ADD,BUTTON,BUTTON2,227,23,187,37,Revert
DIALOG ADD,TEXT,TEXT1,7,27,,,UserName
DIALOG ADD,TEXT,TEXT2,47,27,56,13,Domain
DIALOG ADD,TEXT,TEXT3,84,28,52,13,Password
DIALOG ADD,TEXT,TEXT4,125,25,,,Enter path to run a prgram:
DIALOG SHOW
:EVLOOP
WAIT EVENT
GOTO @EVENT()
:BUTTON1BUTTON
%%User = @DLGTEXT(EDIT1)
%%Domain = @DLGTEXT(EDIT2)
%%Password = @DLGTEXT(EDIT3)
%%filenameandcommandline = @DLGTEXT(EDIT4)
%%path = @PATH(%0)
REM Avoid crash caused by a empty param
IF @NOT(%%Domain)
%%Domain = 0
END
OPTION ERRORTRAP,err1
UG SETSTR,0,%%User
UG SETSTR,1,%%Domain
UG SETSTR,2,%%Password
REM LOGON32_LOGON_INTERACTIVE = 2
REM LOGON32_LOGON_NETWORK = 3
REM LOGON32_PROVIDER_DEFAULT = 0
%A = @UG(DLLFUNC,LogonUserA,int,STRBUF,STRBUF,STRBUF,int:2,int:0,INTBUF)
:err1
%I = @ug(GETINT,5)
REM I should be a valid Integer value
REM I guess the function is not working because INTBUF is unable to recieve the pHandle
INFO %I is the handle to the user token to be used in next calls - ImpersonateLoggedOnUser/CreateProcessAsUser
GOTO EVLOOP
:BUTTON2BUTTON
GOTO EVLOOP
:CLOSE
EXIT |
_________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Wed Mar 10, 2004 7:04 pm Post subject: |
|
|
| I've been trying to use your impersonate dsu but I keep receiving error 1314 or "A required privlege is not held by the client." |
|
| Back to top |
|
 |
CodeScript Moderator Team

Joined: 08 Jun 2003 Posts: 1060 Location: India
|
Posted: Wed Mar 10, 2004 7:25 pm Post subject: |
|
|
I c I don't have the network environment to test it.
On XP local account seems to work well.
Does the dll do the same I guess not ? _________________ Regards
- CodeScript
Give your application a professional look with the VDSGUI Extension |
|
| Back to top |
|
 |
bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Wed Mar 10, 2004 7:28 pm Post subject: |
|
|
| No it works fine |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|