Solved

How can I impersonate an account in vbscript

Posted on 2011-03-22
5
1,612 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
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:holthd
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now