CleanUp Desktop Windows 7 - batch-file

I am searching for a Windows setting (GPO?), scheduled task or a tiny script that enables me either to prevent users to save anything to the Windows desktop or to clean up the entire desktop (shortcuts, files, folders) in a predefined time interval.
The only "hack" I found so far is to restrict user permissions on the desktop folder.
Isn't there a more general solution for clean-up tasks like this?

First, I agree with Ansgar Wiechers: Why delete files and folders of users desktop?
I know, there are some use cases where this makes sense. But such an intervention in the user management should be really explained when asking here on Stack Overflow such a question.
Second, the delete command posted by npocmaka just deletes all files in users desktop folder, but not the subfolders in desktop folder.
Therefore a batch file would need one more line:
#echo off
del /F /Q "%USERPROFILE%\Desktop\*" 2>nul
for /D %%D in ("%USERPROFILE%\Desktop\*") do rd /Q /S "%%~D" 2>nul
After this operation just the items from all users desktop folder are still displayed on desktop of the user.
To prevent users to put files and folders on their own desktop, the string value Desktop in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
and in
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders
could be modified to all users desktop folder which is by default write-protected via appropriate NTFS permissions for standard users.
Of course also the NTFS permissions of folder %USERPROFILE%\Desktop could be changed after the cleanup to prevent a user to put files and folders on own desktop.

Related

Ideas for cmd to delete content of documents folder WIN 10?

I want to create a .bat file with a command line inside that deletes all content of the C:\Users\Documents folder. I only want to delete the entire content of the folder, not the folder itself.
Why do I need this? Our company helps unemployed people find jobs and they use our laptops to create CVs and application lettres. They forget to delete their data (most of them don't really know how to use a computer) so I am trying to automate this process with a .bat file and a scheduled task (run script when user logs in).
If the laptops were WIN10 Pro, I would have used group policies in AD, but these computers are WIN10 home.
Any Ideas? Thank you for your help.
One other way to do it is to copy an empty directory using robocopy to the documents folder. So as an example, Create a directory called none.
In this example, I created the empty directory as D:\none
robocopy "D:\none" "%userprofile%\Documents" /MIR
This will work from cmd and in a batch-file.

How can I make a batch script copy files from the user folder with support for different users?

I would like to use a short batch script to copy files from OneDrive to a different folder, the issue is the OneDrive folder is in the users folder under C:/.
What can I do to have the batch script go into the user folder of the user currently logged in followed by the OneDrive folder to copy a specific file?
Currently this is what I have:
xcopy "C:\jmills\OneDrive\TestFolder\Test_2018.accde" "C:\Test\Test_EXE\" /d
As you can see the user "jmills" is hard coded which makes the batch work with only this specific user.
It is hardcoded because you selected to hardcode it. Note that there is an environment variable called username which holds the username of the user currently logged in. Variables in batch file can be accessed by % or ! when delayed expansion is enabled. I find no reason for using delayed expansion here, so use just percent-signs:
xcopy "C:\%username%\OneDrive\TestFolder\Test_2018.accde" "C:\Test\Test_EXE\" /d

I want to upload only updated files to google drive but XCOPY seems not working

I recently started using Google Drive as a corporate account to backup 10,000+ files.
Once I uploaded everything to G:\My Drive\ with taking 3 days.
Now for the operation, I would like to copy only updated files so I created batch file like following.
set TODAY=%date:~0,4%%date:~5,2%%date:~8,2%
set time2=%time: =0%
set TIME=%time2:~0,2%%time2:~3,2%%time2:~6,2%
set LOGFILEPATH=C:\TEMP\%TODAY%_%TIME%.txt
xcopy Z:\ORIGINAL G:\My Drive\BACKUP /D /S /R /Y /I /K /C /F /H
>>%LOGFILEPATH%
It works for other folders like D drive (internal Hard disk drive) however, if you pointed to G drive (Google virtual drive??) then it does not work. i.e. the batch file does not produce any output.
Do you know any command or tools helping this situation?
Again, I want to copy only updated files to Google drive from internal hard disk drive with all the sub directory etc keeping same shape.
Thank you team,
Kaz
I found the following software resolve the issue.
I am not sure why XCOPY didn't work but the following software works perfectly even on Google drive.
[link]http://synchronicity.sourceforge.net/
if some of you achieved another way please let me know.
Firstly, Google drive is referenced with spaces here and secondly, include /M for incremental backup at the source destination side, below is the command skeleton:
XCopy /M [source loc]\*.* G:\"My Drive"\ShareDir /Y
Where, G: is Google Drive, /M will only picks up files that are new or changed & /Y will suppress prompt
Alternatively, use can use below command as well for incremental backup of entire directory:
ROBOCOPY [source location]\ShareDir G:\\"My Drive"\\ShareDir /MIR
Where, /MIR option will mirror the directory as it is (it takes care of the deleted or renamed files/directories as well). Note the use of double slashes.
It works for me; I keep my songs updated to my Google Drive, which I access through a Cloud Music Player.

xcopy not working the same as ctrl+c/ctrl+v in W10?

I'm trying to write a batch file in Window 10 that will copy a folder to overwrite the C:\Windows\System32\GroupPolicy folder. So I do
xcopy /y /e C:\Backup\GroupPolicy %systemroot%\system32\
and it says it copied all the files. But if I check the group policy using gpedit, my changes aren't there. But if I select the C:\Backup\GroupPolicy folder in the file explorer and use ctrl+c and then go to c:\Windows\System32 and do ctrl+v and say yes to the prompt to overwrite the files, when I check gpedit, my changes are there now. When I do it through the GUI, I do get a prompt saying I need admin permissions to copy the folder, so I'm wondering if xcopy is not being given proper admin permissions even though I'm running it from an administrative command prompt.
Not sure what exactly you mean when you say "my changes aren't there".
If your ACL information is missing, then I think you're missing a switch:
/O Copies file ownership and ACL information.
You might also be hitting 32/64 bit environment problems and actually be looking for C:\Windows\SysWOW64.
I found out that the issue was related to permissions. xcopy has some flags like /o /k /r /h that also copy the metadata of the file. Tried that and got permission denied. Then I found that I could use robocopy instead with the /copy:DATSO (/copyall also gave a permission denied error) flag and that worked.

Delete subdirectories of other subdirectories but keeping the "root" subdirectories

We have a network share that has backups from multiple machines throughout the company. Once a quarter it gets copied off site and then we wipe out the contents. The share has a subdirectoy for each machine and then within that subdirectory are more folders with the backups. The machine subdirectory has sharing enabled and permissions set for that individual machine so we do not want to delete those but we do want to delete all the subdirectories. So it looks like this:
Machine 1
- My Documents
Machine 2
- My Documents
- Database Config
Machine 3
- My Documents
- Desktop
In the above example all the Machine directories are in a folder called Backups and we want to delete all the sub directories of them (My Docs, Database Config, Desktop, etc). There are about 190 machines so manually going into each directory then deleting the contents is very time consuming. This will preferably be a DOS based batch file that will be run manually by a admin. I've been playing with a For Do loop and can't get it to work as expected. Any suggestions?
use a FOR command with the /D option to iterate over all the directories in the network share. Then, for each directory found, use FOR /D again to iterate over all the subdirectories and wipe out them with RD /S
something similar to this...
FOR /D %%a in (*) DO (
PUSHD "%%a"
FOR /D %%b in (*) DO RD /S /Q "%%b"
POPD
)

Resources