lloydie2009 Posted February 18, 2013 Share Posted February 18, 2013 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:\localset /P username="Enter Target Username"takeown.exe C:\Users\%username% /D Y /Fcacls c:\users\%username% /t /e /g Administrators:frobocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1remprof %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 Link to comment Share on other sites More sharing options...
IcemanND Posted February 18, 2013 Share Posted February 18, 2013 Are you running this with admin rights from a CMD window or just double clicking? Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 18, 2013 Share Posted February 18, 2013 I could be wrong but1:\strsUsername varible name you are trying to pass2:\&sUsername& varible name in script3:\&sUsername& varible name in scriptwould 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 orthe 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 scriptruns without errors.UserIn_Takeown_RoboCopy.vbs'-> This code is property of Gunsmokingman and Or Jake1Eye and you must have his permission to use.'-> This is only posted as example code and meant only to used as such.Dim Act :Set Act = CreateObject("Wscript.Shell")Dim UserGetInput()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 CharactersIf InStr(LCase(User),"exit") Or _InStr(LCase(User),"quit") Then'-> Exit Or Quit ScriptWScript.Quit()Else'-> Code Here For TakeownAct.Run("takeown.exe /F C:\users\" & User),0,True'-> Code Here For RoboCopyAct.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 SecondsAct.Popup "Script Completed",5,"Finshed",4128End IfElse'-> To Disable Red X,Cancel And Prevent No Text,And Less 2 CharactersMsgBox 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 IfEnd Function Link to comment Share on other sites More sharing options...
jaclaz Posted February 18, 2013 Share Posted February 18, 2013 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?cd c:\local:loopSET username=MickeyMouseset /P username="Enter Target Username"IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :looptakeown.exe C:\Users\%username% /D Y /Fcacls c:\users\%username% /t /e /g Administrators:frobocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1remprof %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 Link to comment Share on other sites More sharing options...
allen2 Posted February 18, 2013 Share Posted February 18, 2013 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?cd c:\local:loopSET username=MickeyMouseset /P username="Enter Target Username"IF NOT EXIST c:\users\%username% ECHO NO such username&GOTO :looptakeown.exe C:\Users\%username% /D Y /Fcacls c:\users\%username% /t /e /g Administrators:frobocopy c:\users\%username% c:\local\profilebackup\%username% /E /R:1 /W:1remprof %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 )jaclazYou 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now