Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Impersonating an Account
Message
 
À
15/03/2006 11:48:18
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
01104564
Message ID:
01104688
Vues:
13
Here's a bit of code I stumbled across one time to do the job in Visual Foxpro. It's just API stuff that should be easy enough to convert to dot nyet.

...Art
* If the table "Products" is in a protected folder, for example and the user "ProdAdmin" has rights to the folder, then:
if Impersonate("ProdAdmin", "ProdPassword")
   * I use a mapped drive just as an example, of course it is not needed or desireble
   USE X:\ProductFolder\Products
endif
* Do some process
EndImpersonate()

FUNCTION Impersonate(UserName As String, UserPassword As String) As Boolean
   Declare Integer LogonUser IN advapi32 ;
   	String lpszUsername, ;
   	String lpszDomain, ;
   	String lpszPassword, ;
   	Integer dwLogonType, ;
   	Integer dwLogonProvider, ;
   	Long @phToken
   Declare Integer ImpersonateLoggedOnUser IN WIN32API Long ptr   
   Declare RevertToSelf IN ADVAPI32

   LOCAL nToken, loNet
   nToken = 0
   loNET  = CREATEOBJECT('wscript.Network')
   IF LogonUser(UserName, loNET.UserDomain, UserPassword, 2, 0, @nToken) > 0
      IF ImpersonateLoggedOnUser(nToken) > 0
         CLEAR DLLS
         loNet.MapNetworkDrive('X:', '\\skyapps\apps') && Map all network drives is necessary
         RETURN .t.
      ENDIF
   ENDIF
   CLEAR DLLS
   RETURN .F.
ENDFUNC

FUNCTION EndImpersonate() As Boolean
   Declare RevertToSelf IN ADVAPI32
   RevertToSelf()
   CLEAR DLLS
ENDFUNC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform