Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How can I impersonate an account in vbscript

Posted on 2011-03-22
5
Medium Priority
?
1,825 Views
Last Modified: 2012-05-11
I am trying to configure some VBScripts to run within a third-party system.  I need to impersonate a domain user from within the script.  How can this be done?  Normally the WMI classes allow impersonate, but, I am trying to use the Scripting.FileSystemObject.
0
Comment
Question by:wls3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:holthd
ID: 35194809
Is it an possiblity to run the entire script as another user? If so you can achieve this using Windows' built-in 'runas.exe' or a scheduled task, depending on your scenario.

If you trigger it remotely you can use 'psexec.exe' by Sysinternals (Microsoft).

If you need to trigger only a portion of the script as userA while the main script runs as userB you can allways re-call a portion of the script through WshShell.Run "Runas.exe <args> C:\Scripts\PortionOfMainScript.vbs". Might get messy. Use arguments to pass variables to the portion script.

-Daniel
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 35195355
If you want to do it with the FileSystemObject, you need to create a pipe, using alternate credentials.

            
		On Error Resume Next
		objNetwork.RemoveNetworkDrive "\\" & strComputer & "\IPC$", True, False
		Err.Clear
		On Error GoTo 0
		objNetwork.MapNetworkDrive "", "\\" & strComputer & "\IPC$", False, strUsername, strPassword
		' Use FSO methods now
		

Open in new window


Regards,

Rob.
0
 
LVL 10

Author Comment

by:wls3
ID: 35199016
Thanks Rob.  I had not had to dig into those NetworkDrive methods before.  I am checking them out on MSDN now.  Appreciate the pointer.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35202815
Thanks for the grade, you'll also want to remove the mapping again after you use the FSO methods.

Rob.
0
 
LVL 10

Author Comment

by:wls3
ID: 35203336
Appreciate the follow up comment.  I had seen some other folks suggesting something along these lines, but, I didn't know this was essentially creating a pipe.  From what I had seen I just assumed the close was to dispose of the object, not a pipe.  Again, thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question