Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How can I impersonate an account in vbscript

Posted on 2011-03-22
5
Medium Priority
?
1,874 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

916 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