1

So I was messing around with batch and I wanted to make a kinda trash folder in any subdirectory I want, You will understand after I show you the code.

@echo off
set "var=%cd%"
if not EXIST trash goto create
if EXIST trash goto exists

:create
mkdir trash
echo [.ShellClassInfo] IconResource=C:\WINDOWS\System32\SHELL32.dll,63 [ViewState] Mode= Vid= FolderType=Generic > trash\desktop.ini
attrib +h +s trash\desktop.ini
cd ..
attrib +r +s %var%\trash
goto end

:exists
echo Would you like to delete the files inside of the trash? (y/n)
set /p YESNO=" "
if not %YESNO%==y goto end
if %YESNO%==y goto check

:check
echo Please state the correct password
set /p PASSWORD=" "
if %PASSWORD%==1243 del trash\*.* /s /f /q
goto end

:end

In the create area I was trying to give it a Recycle Bin logo thing and you need to give desktop.ini the hidden and system attributes and that worked, but giving the trash folder itself the Read-Only and system attributes didn't work. The reason I can't just use any old direct path is because I want you to be able to use it in any path.

CJendantix
  • 23
  • 7
  • Is there a particular reason why you deleted [your last question](https://stackoverflow.com/q/67188168)? Not only was there a link to other useful information, I provided an answer to it, which included some correct syntax, which you've failed to replicate in your new code above. I would also suggest, that asking me a question, and then promptly deleting the post, was counter-intuative, because I could then not respond within a deleted question. Your code is very poorly designed with unsafe syntax, please revisit my answer in your previously deleted question, and look up each of its commands. – Compo Apr 21 '21 at 13:29
  • Ok, I deleted it because it said that it was like other questions and it told me to delete it, could I have kept it up? – CJendantix Apr 21 '21 at 13:32
  • I undeleted it. – CJendantix Apr 21 '21 at 13:35
  • The part about defining your variable without the unwanted whitespace was your main issue, and hence correctly closed as a duplicate, however, my answer was included to provide you with some useful commands, syntax and structure, to greatly improve your experience moving forward. If you open a Command prompt window, type a command followed by `/?`, it will show you its syntax, options and other information. – Compo Apr 21 '21 at 13:36
  • Literally 4 questions down from this one is another [question](https://stackoverflow.com/questions/67194506/folder-icon-using-mkdir-batch) asking about how to create folder ICONs. If you would have searched the site for `[batch-file] folder icon`. it would have lead you to this [question](https://stackoverflow.com/questions/17988115/windows-command-batch-and-automated-folder-icon-changer). – Squashman Apr 21 '21 at 13:37
  • That question tells you nothing – CJendantix Apr 21 '21 at 13:49
  • @Compo I wish I could understand your explanation on my other question, But I just don't and comments here aren't for chatting. Wish I could message you on discord or something. – CJendantix Apr 21 '21 at 13:51
  • When you say that question tells us nothing, what it shows me, quite clearly, is that `echo [.ShellClassInfo] IconResource=C:\WINDOWS\System32\SHELL32.dll,63 [ViewState] Mode= Vid= FolderType=Generic > trash\desktop.ini` is wrong! and everything else can be replaced with my answer to your last question! I'm not a personal tutor, what I'd ask is that you begin by just using what I posted, with no changes, additions or omissions, then research the commands, etc. before adding your folder icon part to it! – Compo Apr 21 '21 at 13:52
  • ok, I am actually rather impressed that young people want to learn something and ask questions. So let me give you a few hints. Consider the real reasons why you would even need to create variables. So if not needed, do not create them. as an example `set var=%cd%` is completely unwanted. you can use `attrib +r +s "%cd%\trash"` without defining another variable. Notice the double quotes as well around the path. – Gerhard Apr 21 '21 at 13:53
  • @Connor so you are telling me that you cannot see the code difference in how the `desktop.ini` file is being created? – Squashman Apr 21 '21 at 13:54
  • oh! I actually just copied and pasted that from a different question so I didn't know lol, and yes, I don't see the code difference – CJendantix Apr 21 '21 at 15:34
  • can there be a solution? lets think back to the reason I posted this. I need to make the folder have a trash icon automatically – CJendantix Apr 21 '21 at 15:49

1 Answers1

0

Sorry but i am not familiar with stackoverflow, so i can't make it that understandable, but i hope that this is enough.

First of all, you have lots of errors handling variables and the idea with a password is quite good, but impractical. Batch was not made for that. I teach software security and pentesting classes and literally have a similar script for students to crack their password. Not to mention that you will have many problems with deleting and recovering files, and the user does not need to go through your program to do what you want, in addition to being extremely practical using the common trash. Excellent idea, I can help you with this if you want without price, but I don't think it would be so useful outside of handling content in a preferential, casual and personal way.

Well, the first mistake in your script was not giving spaces between the desktop.ini codes and not correctly assigning values to it with attrib, probably not using the correct trash can icon code either.

The Windows have some bugs with the desktop.ini file and a big delay, but here is what you need to do:

@echo off
set "var=%cd%"
if not EXIST trash goto create
if EXIST trash goto exists

:create
mkdir trash
set katorn=%random%
md "%temp%\%katorn%"
:: As we can see bellow, SHELL32.dll,31 means empty trash ico, SHELL32.dll,32 means full trash ico.
(
echo [.ShellClassInfo]
echo IconResource=C:\Windows\system32\SHELL32.dll,31
echo [ViewState]
echo Mode=
echo Vid=
echo FolderType=Generic
)>"%temp%\%katorn%\desktop.ini"
attrib +S +H "%temp%\%katorn%\desktop.ini"
del /q /f /s "%var%\trash\desktop.in*"
move "%temp%\%katorn%\desktop.ini" "%var%\trash"
rd /s /q "%temp%\%katorn%"
attrib +r +s %var%\trash
goto end

:exists
echo Would you like to delete the files inside of the trash? (y/n)
set /p YESNO=" "
if not %YESNO%==y goto end
if %YESNO%==y goto check

:check
echo Please state the correct password
set /p PASSWORD=" "
if %PASSWORD%==1243 del trash\*.* /s /f /q
goto end

:end

You can also insert a VBScript to make shortcuts and then insert icons.

Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\ShortcutName.lnk")
Shortcut.WindowStyle = "4" 
Shortcut.IconLocation = "X:\ICoLOcation\icon.ico"
Shortcut.TargetPath = "ProgramToBeOpened\program.exe"
Shortcut.Save

You can use a batch to write and execute the script.

@echo off
:loop
set /p "schname=Shortcut name: "
set /p "schlocation=Shortcut Location: "
set /p "schdestination=Shortcut Destination: "
set /p "schicon=Icon Location: "
set "schname=%schname:"=%"
set "schlocation=%schlocation:"=%"
set "schdestination=%schdestination:"=%"
set "schicon=%schicon:"=%"
echo >>"%temp%\shortcut.vbs" Set WshShell = CreateObject ("Wscript.Shell")
echo >>"%temp%\shortcut.vbs" strDesktop = "%schdestination%"
echo >>"%temp%\shortcut.vbs" Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%shcname%.lnk")
echo >>"%temp%\shortcut.vbs" Shortcut.WindowStyle = "4" 
echo >>"%temp%\shortcut.vbs" Shortcut.IconLocation = "%schicon%"
echo >>"%temp%\shortcut.vbs" Shortcut.TargetPath = "%schlocation%"
echo >>"%temp%\shortcut.vbs" Shortcut.Save
cscript "%temp%\shortcut.vbs"
del /q /f "%temp%\shortcut.vbs"
goto loop

Hope this helps,
K.