Solved

How can I impersonate an account in vbscript

Posted on 2011-03-22
5
1,657 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
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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

777 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