Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with error message
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01344973
Message ID:
01345241
Views:
17
Hi Mark,

>Is it possible to impersonate the current user into another user on the fly?

Depends on the operating system. If the user is a regular user you need Windows XP or later. On Windows 2000 and earlier you need to be an administrator to impersonate. You need to test, though, whether impersonation helps in this case. I'm not sure if network authentication data is stored with the process or the user token. Windows remembers which user name it used to communicate with any given computer, because it needs to authenticate itself with requests. As this happens automatically, you can only connect with one user name to each computer on the network share level. What I'm unsure is if this is relative to the user account (for every user name you can have one user name on the remote server) or the process (whatever user name you used to first connect to the server would be used). If it's the former, there's no problem. Otherwise you might have to be careful no to connect to the server before impersonation. Here's some code to handle impersonation:
* Based on an idea by Alf Borrmann
CLEAR 

LOCAL lnOK, lnHandle
DECLARE Long LogonUser IN WIN32API ;
	String, String, String, Long, Long, Long@
DECLARE LONG GetLastError IN WIN32API

lnHandle = 0	
* SeNetworkLogonRight
* SeTcbPrivilege (up to Windows 2000)
lnOK = LogOnUser( "test", "", "test", 3, 0, @lnHandle )
IF m.lnOK == 0
	? "Error with LogOnUser ", GetLastError()
	RETURN
ENDIF

DECLARE Long ImpersonateLoggedOnUser IN WIN32API Long
DECLARE Long RevertToSelf IN WIN32API

? SYS(0)
lnOK = ImpersonateLoggedOnUser( lnHandle )
IF m.lnOK == 0
	? "Impersonation failed"
ELSE
	? SYS(0)
	RevertToSelf()
	? SYS(0)
ENDIF 

DECLARE Long CloseHandle IN WIN32API Long 
CloseHandle(lnHandle)
--
Christof
Previous
Reply
Map
View

Click here to load this message in the networking platform