Page 1 of 1

VBS Ownership & Copy

Posted: Sun Feb 17, 2013 6:41 pm
by lloydie2009

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

VBS Ownership & Copy

Posted: Mon Feb 18, 2013 4:19 am
by jvierra
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