Link to home
Start Free TrialLog in
Avatar of Taconvino
Taconvino

asked on

Impersonate user with VBScript

Hi,

I need to impersonate a domain user from VBScript.  The reason is I need to move some files from the server the script is runnin in to another server, and the logged on user on the first server has no permissions to create files in the shared folder.  There's no way network admins will change this... any help will be greatly appriciated.

Thanks!
TCV
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Taconvino
Taconvino

ASKER

Thanks for your reply BlueDevil, but as far as I know, RunAs command wil not take the user's password as a parameter... although I have not tested this, I think it displays a User/Password screen asking for the password.  This will not work for me, as the script should run unattended.

TCV
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's a great idea dlwyatt82!  I'll get back to you as soon as I test this.

TCV
Sorry dlwyatt82.... I'm getting some "conflicting credentials" error...

TCV
that means you already have a drive mapped to that particular server with a different user name / password combination.  Unfortunately Windows doesn't allow for that... you'd need to unmap whatever your existing drive is first.
Yes, that's probably the case, but I can't unmap any existing mappings, as this server runs different processes for different systems.  

Anyway, both solutions provided here work under certain conditions, and since I'm using RUNAS anyway, I'm splitting points between both experts that helped me out here!

Just for future reference, there's another solution that involves creating a DLL to impersonate a user.  This is done by calling three APIs:

ImpersonateLoggedOnUser
LogonUser
RevertToSelf

This is a little more complex, and requires certain privileges for the user trying to impersonate another to be granted (secpol).  

Thanks a lot for your help!

TCV