CMD: Wild card for all folder and sub folder - cmd

I am trying to use a cmd command for all folder and its subfolder.
cacls "F:\Testing\*" /e /c /d %username%
all the folders and files in Testing are affected but the sub folders of those affected folder
F:\Testing\Folder\a
F:\Testing\Folder\b
etc..
are not affected by the command.
I also try
cacls "F:\Testing\*\*" /e /c /d %username%
but it does not work either.
Is there any wildcard that work for all sub-sub-... folders?

I've never used the CACLS command, but the built in help (cacls /?) indicates you want the /T option.
/T Changes ACLs of specified files in
the current directory and all subdirectories.
Whenever you have a question on how to use a Windows console command, you should always first check the built in help. Nearly all commands support the /? option to display help.

Related

Windows command line change folder permission

The scenario is as follows:
A program that's executed with admin rights creates a folder, "C:\my folder".
In cmd, I want to grant full control of this folder to everyone.
How can I do it? I tried
cacls "C:\my folder" /E /P "*S-1-1-0":F
and didn't work. I also tried
cacls "C:\my folder" /E /P "Everyone":F
and didn't work. Yet,
cacls "C:\my folder" /E /P "Todos":F
did work -- where "Todos" stands for "Everyone" in a Spanish installation of Windows. How can I accomplish this no matter what language Windows was installed with?
NOTE: I know cacls is supposed to be deprecated in favour of icacls. I don't mind. Please, don't waste your time pointing it out, unless there is a way to achieve this in icacls.
Try this one:
icacls "C:\my folder" /grant Everyone:M
Taken from here.
In my own dispare, I finally managed to figure it out:
icacls "C:\my folder" /GRANT *S-1-1-0:F
This is funny: I figured it out by means of technet.microsoft.com, YET, THEIR OWN DOCUMENTATION IS WRONG!!!
IN https://technet.microsoft.com/es-es/library/cc753525(v=ws.10).aspx they state you should use
Icacls test2 GRANT *S-1-1-0:(d,wdac)
when you should actually use
Icacls test2 /GRANT *S-1-1-0:(d,wdac)

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

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.

Cannot fully delete ProgramData from Windows 8 installation within WinPE

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.

Copy files to network computers on windows command line

I am trying to create a script on Windows which when run on an admin PC:
Copies a folder from the admin PC into a group of network PCs by specifying the ip address / range
For each destination PC, Navigate into the folder and run another script file.
Using the method described by seanyboy here:
net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}
I'm not sure on how i can write a 'for' loop to go through each 'dest-machine' and perform step 2. Any ideas would be greatly appreciated.
check Robocopy:
ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT
make sure you check what robocopy parameter you want. this is just an example.
type robocopy /? in a comandline/powershell on your windows system.
Below command will work in command prompt:
copy c:\folder\file.ext \\dest-machine\destfolder /Z /Y
To Copy all files:
copy c:\folder\*.* \\dest-machine\destfolder /Z /Y
Why for? What do you want to iterate? Try this.
call :cpy pc-name-1
call :cpy pc-name-2
...
:cpy
net use \\%1\{destfolder} {password} /user:{username}
copy {file} \\%1\{destfolder}
goto :EOF
Regarding step 2., check manual for psexec command (sysinternal tools)

Resources