VBS Ownership & Copy

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 1
Joined: Sun Feb 17, 2013 7:41 pm

VBS Ownership & Copy

Post by lloydie2009 » Sun Feb 17, 2013 7:41 pm


I am trying to create a VBS to take ownership of a user input parameter folder, and then copy that to another location however am having issues.

I think it's the ownership bit that causing a problem which if run in a single script works fine, and is only when trying to add the robocopy section of the script I am having issues.

I'm afraid I have limited knowledge, and there is no error that appears, it prompts for the username as it should, and then closes a few moments later, it would appear when it hit's the robocopy section, however if you then look at c:users, ownership has not been taken.

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strsUsername = InputBox ("please enter target username")

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "takeown.exe /F C:users"&sUsername&""

objShell.Run "robocopy.exe c:users"&sUsername&" c:localprofilebackuplocalprofile /e /zb /R:3 /W:2"

Any suggestions on how i can accomplish this would be great, i need to have a InputBox as this is for Admin to use from different accounts, so the script cannot auto-determine the folders.

Many Thanks

User avatar
Posts: 13266
Joined: Tue May 22, 2007 9:57 am

VBS Ownership & Copy

Post by jvierra » Mon Feb 18, 2013 5:19 am

Hi lloyd,

There are a couple of things her3e that will give you trouble. YOU do not allow any space around the & signs which is required and the re is no need to add an empty string to the end.

Only an admnistrator can run this command.

Try the following.

strsUsername = InputBox ("please enter target username")

Set objShell = CreateObject("Wscript.Shell")
strCmd = "takeown.exe /F C:users" & sUsername
ret = objShell.Run( strCmd, 1, True )
if ret = 0 Then
strCmd = "robocopy.exe c:users" & sUsername & " c:localprofilebackuplocalprofile /e /zb /R:3 /W:2"
ret = objShell.Run( strCmd, 1, True)
msgbox ret
MsgBox "Command failed:" & ret
End If