kgreer Posted September 19, 2014 Share Posted September 19, 2014 I am writing a script to reset Local Group Policy settings which will first backup related registry keys and folders before removing them. It will end with running gpupdate /force. My issue is I am not able to copy the two below folders. I have tried dircopy() and runwait() with robocopy. I am running windows 8.1 but mainly this script will run on Windows 7 computers. C:\Windows\System32\GroupPolicy C:\Windows\System32\GroupPolicyUsers If I manually run the below commands the copy works, but I can't get the command to work within the script: robocopy.exe C:\Windows\System32\GroupPolicy C:UsersusernameDesktopResetGroupPolicyGroupPolicy /e robocopy.exe C:\Windows\System32\GroupPolicyUsers C:UsersusernameDesktopResetGroupPolicyGroupPolicyUsers /e Does anyone have any ideas how I can get the above commands to work whether it's with robocopy or dircopy(). The method does not matter, I just need some function to work. Thank you for assisting! #RequireAdmin #include <array.au3> Dim $LogDirectory = @DesktopDir & "\ResetGroupPolicy" Dim $arrKeysToDelete[6] = ["HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft", _ "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy", _ "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies", _ "HKEY_CURRENT_USER\Software\Policies\Microsoft", _ "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Group Policy", _ "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies"] DirCreate($LogDirectory) For $i = 0 To UBound($arrKeysToDelete) - 1 ShellExecuteWait("regedit.exe", "/e " & $i + 1 & ".reg """ & $arrKeysToDelete[$i] & """", @DesktopDir & "\ResetGroupPolicy\") Next DirCreate($LogDirectory & '\GroupPolicy') RunWait(@ComSpec & ' /c robocopy.exe ' & 'C:\Windows\System32\GroupPolicy ' & $LogDirectory & '\GroupPolicy /e /log+:c:\test.log') DirCreate($LogDirectory & '\GroupPolicyUsers') RunWait(@ComSpec & ' /c robocopy.exe ' & 'C:\Windows\System32\GroupPolicyUsers ' & $LogDirectory & '\GroupPolicyUsers /e /log+:c:\test.log') ;Delete Registry keys ;Delete Folders ;Run gpudate /force Here are the the errors i get in the robocopy log file. ------------------------------------------------------------------------------- ROBOCOPY :: Robust File Copy for Windows ------------------------------------------------------------------------------- Started : Friday, September 19, 2014 12:19:15 PM Source : C:\Windows\System32\GroupPolicy\ Dest : C:\Users\kgreer\Desktop\ResetGroupPolicy\GroupPolicy\ Files : *.* Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 ------------------------------------------------------------------------------ 2014/09/19 12:19:15 ERROR 2 (0x00000002) Accessing Source Directory C:\Windows\System32\GroupPolicy\ The system cannot find the file specified. ------------------------------------------------------------------------------- ROBOCOPY :: Robust File Copy for Windows ------------------------------------------------------------------------------- Started : Friday, September 19, 2014 12:19:15 PM Source : C:\Windows\System32\GroupPolicyUsers\ Dest : C:\Users\kgreer\Desktop\ResetGroupPolicy\GroupPolicyUsers\ Files : *.* Options : *.* /S /E /DCOPY:DA /COPY:DAT /R:1000000 /W:30 ------------------------------------------------------------------------------ 2014/09/19 12:19:15 ERROR 2 (0x00000002) Accessing Source Directory C:\Windows\System32\GroupPolicyUsers\ The system cannot find the file specified. Link to comment Share on other sites More sharing options...
Bert Posted September 19, 2014 Share Posted September 19, 2014 1. Do you have rights to do what you want? 2. Can you do this manually? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
kgreer Posted September 22, 2014 Author Share Posted September 22, 2014 Yes, I have rights. I am a local administrator on the computer and I can manually perform the tasks. Link to comment Share on other sites More sharing options...
Bert Posted September 22, 2014 Share Posted September 22, 2014 do you have "ownership" of the folder? The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
iamtheky Posted September 22, 2014 Share Posted September 22, 2014 (edited) How about a simple one line filecopy script, acting on a file inside the root of the grouppolicy folder like gpt.ini, if it exists? If this works can you use Melba's _RecFileListToArray and enumerate all files/folders/subfolders? Once enumerated can you start walking through the array copying items until it breaks? Edited September 22, 2014 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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