Hello,
OK, let's test your skills because mine are cak.
Can someone turn that into a VBS file, preferably so if there are any errors, it doesn't skip to the end of the file (the issue I'm having now, if it fails, it still deletes the folder)
cd c:\local
set /P username="Enter Target Username"
takeown.exe C:\Users\%username% /D Y /F
cacls c:\users\%username% /t /e /g Administrators:f
robocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1
remprof %username%
rd /s /q c:\users\%username%
Here's my attempt:
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:\local\profilebackup\localprofile /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
Page 1 of 1
VPS Script - Takeown + Robocopy Assistance compiling script
#2
Posted 18 February 2013 - 12:02 PM
Are you running this with admin rights from a CMD window or just double clicking?
#3
Posted 18 February 2013 - 12:21 PM
I could be wrong but
1:\strsUsername varible name you are trying to pass
2:\&sUsername& varible name in script
3:\&sUsername& varible name in script
would cause the script to use a varible that does not have any information.
Here is a script that prevents the Input from being close using the Cancel Button or
the X and only process the Input if it 2 characters or longer.
The only thing I have not tested is the Takeown and RoboCopy, the rest of the script
runs without errors.
UserIn_Takeown_RoboCopy.vbs
Rename UserIn_Takeown_RoboCopy.vbs.txt to UserIn_Takeown_RoboCopy.vbs to make active
UserIn_Takeown_RoboCopy.vbs.txt (1.16K)
Number of downloads: 1
1:\strsUsername varible name you are trying to pass
2:\&sUsername& varible name in script
3:\&sUsername& varible name in script
would cause the script to use a varible that does not have any information.
Here is a script that prevents the Input from being close using the Cancel Button or
the X and only process the Input if it 2 characters or longer.
The only thing I have not tested is the Takeown and RoboCopy, the rest of the script
runs without errors.
UserIn_Takeown_RoboCopy.vbs
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim User
GetInput()
Function GetInput()
User = InputBox(_
"Type in the target User Name" & vbCrLf & vbCrLf & _
"To exit or quit type Exit or Quit","","",6500,5500)
If User <> "" And Len(User) >= 2 Then
'->Make Sure Input More Then 2 Characters
If InStr(LCase(User),"exit") Or _
InStr(LCase(User),"quit") Then
'-> Exit Or Quit Script
WScript.Quit()
Else
'-> Code Here For Takeown
Act.Run("takeown.exe /F C:\users\" & User),0,True
'-> Code Here For RoboCopy
Act.Run("robocopy.exe c:\users\" & User & _
" c:\local\profilebackup\localprofile /e /zb /R:3 /W:2")0,True
'-> End Of Script Popup Will Self Close In 5 Seconds
Act.Popup "Script Completed",5,"Finshed",4128
End If
Else
'-> To Disable Red X,Cancel And Prevent No Text,And Less 2 Characters
MsgBox vbtab & "Error" & vbcrlf & vbcrlf & _
"The Cancel, Red X have been disable" & vbCrLf & _
"or no Text was filled in or less then 2" & vbCrLf & _
"characters where inputted",4128,"Error"
GetInput()
End If
End Function
Rename UserIn_Takeown_RoboCopy.vbs.txt to UserIn_Takeown_RoboCopy.vbs to make active
UserIn_Takeown_RoboCopy.vbs.txt (1.16K)
Number of downloads: 1
#4
Posted 18 February 2013 - 02:05 PM
lloydie2009, on 18 February 2013 - 09:19 AM, said:
Can someone turn that into a VBS file, preferably so if there are any errors, it doesn't skip to the end of the file (the issue I'm having now, if it fails, it still deletes the folder)
Why not simply introduce some error control?
Quote
cd c:\local
:loop
SET username=MickeyMouse
set /P username="Enter Target Username"
IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :loop
takeown.exe C:\Users\%username% /D Y /F
cacls c:\users\%username% /t /e /g Administrators:f
robocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1
remprof %username%
rd /s /q c:\users\%username%
:loop
SET username=MickeyMouse
set /P username="Enter Target Username"
IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :loop
takeown.exe C:\Users\%username% /D Y /F
cacls c:\users\%username% /t /e /g Administrators:f
robocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1
remprof %username%
rd /s /q c:\users\%username%
This assumes that username has no spaces (and that an user name "MickeyMouse" does not exist on that system
jaclaz
#5
Posted 18 February 2013 - 04:42 PM
jaclaz, on 18 February 2013 - 02:05 PM, said:
lloydie2009, on 18 February 2013 - 09:19 AM, said:
Can someone turn that into a VBS file, preferably so if there are any errors, it doesn't skip to the end of the file (the issue I'm having now, if it fails, it still deletes the folder)
Why not simply introduce some error control?
Quote
cd c:\local
:loop
SET username=MickeyMouse
set /P username="Enter Target Username"
IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :loop
takeown.exe C:\Users\%username% /D Y /F
cacls c:\users\%username% /t /e /g Administrators:f
robocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1
remprof %username%
rd /s /q c:\users\%username%
:loop
SET username=MickeyMouse
set /P username="Enter Target Username"
IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :loop
takeown.exe C:\Users\%username% /D Y /F
cacls c:\users\%username% /t /e /g Administrators:f
robocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1
remprof %username%
rd /s /q c:\users\%username%
This assumes that username has no spaces (and that an user name "MickeyMouse" does not exist on that system
jaclaz
You would have to add more checks to the batch file before the "rd /s /q" so won't lose data. You need to be sure that at least the robocopy worked successfully (ie: copied all data) and most likely need to parse robocopy log file properly and it could be a hassle in pure batch.
Share this topic:
Page 1 of 1



Help
Back to top










