• Hi there and welcome to PC Help Forum (PCHF), a more effective way to get the Tech Support you need!
    We have Experts in all areas of Tech, including Malware Removal, Crash Fixing and BSOD's , Microsoft Windows, Computer DIY and PC Hardware, Networking, Gaming, Tablets and iPads, General and Specific Software Support and so much more.

    Why not Click Here To Sign Up and start enjoying great FREE Tech Support.

    This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with DIR command & Registry

Status
Not open for further replies.
Hi
I made cascade context menu to create list of files but there's some issues and questions :)

1. Why both 2 options that include subfolders make empty list?
Batch files work when I run them manually by double clicking.

2. What exactly %1 does in batch files?
I removed them and there was no difference.

3. How can I type multiple lines in command/default key so I will be able to add ron this commands without batch files?
 
%1 is for passing variables to a script.
so %1 is the first variable passed, %2 the second, and so on.

if you posted your script, we’ll be able to help more.
Admins delete files I don't no why but if they tell me the reason I will upload them again but let me type them
 
There are 4 batch files in "C:\Windows\System32" as follows:

Copy File List (Include Subfolders).bat
{
chcp 65001
@echo off
dir %1 /b /s /a /o:gn | clip
}

Copy File List.bat
{
chcp 65001
@echo off
dir %1 /b /a /o:gn | clip
}

Create File List (Include Subfolders).bat
{
chcp 65001
@echo off
dir %1 /b /s /a /o:gn > "%temp%\fileList.txt"
start notepad "%temp%\fileList.txt"
}

Create File List.bat
{
chcp 65001
@echo off
dir %1 /b /a /o:gn > "%temp%\fileList.txt"
start notepad "%temp%\fileList.txt"
}

And the Registry file

Attached file removed security reasons
 
Last edited by a moderator:
Attached file removed security reasons
The Registry file:
File List.reg
{
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\File List]
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell]

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List]
"MUIVerb"="Create File List"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List\command]
@="C:\\Windows\\System32\\Create File List.bat \"%1\""

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)]
"MUIVerb"="Create File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)\command]
@="C:\\Windows\\System32\\Create File List (Include Subfolders).bat \"%1\""

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List]
"MUIVerb"="Copy File List"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List\command]
@="C:\\Windows\\System32\\Copy File List.bat \"%1\""

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)]
"MUIVerb"="Copy File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)\command]
@="C:\\Windows\\System32\\Copy File List (Include Subfolders).bat \"%1\""

[HKEY_CLASSES_ROOT\Directory\background\shell\File List]
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell]

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List]
"MUIVerb"="Create File List"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List\command]
@="C:\\Windows\\System32\\Create File List.bat"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)]
"MUIVerb"="Create File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)\command]
@="C:\\Windows\\System32\\Create File List (Include Subfolders).bat"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List]
"MUIVerb"="Copy File List"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List\command]
@="C:\\Windows\\System32\\Copy File List.bat"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)]
"MUIVerb"="Copy File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)\command]
@="C:\\Windows\\System32\\Copy File List (Include Subfolders).bat"

}

What is the security reason? :/
 
Security reasson is REG and BAT files can cause malicious behaviour.

when you start your batch files, if you aren’t passing a parameter to it, then %1 means nothing, therefore the command dir %1 would get the files from the current directory, and because you have the bat file in the \system32 folder, you will get those files.

so I have to ask, why are you putting four BAT files in the system folder and why are you hacking the registry?
 
so I have to ask, why are you putting four BAT files in the system folder and why are you hacking the registry?
System folder is my chosen directory, doesn't matter where BAT files are stored.

I add these commands because I need files list frequently and it's much easier to have the option in context menu.
And as I said if anyone can help me to write multiple lines in string value there would be no need to batch files at all. (It's not possible to write multiple lines in string edit gui panel and haven't test to write them down in .reg file and then try to import it.)

At first there was no BAT file and the Registry file was like this:
{
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\background\shell\Copy File List]
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\Copy File List\command]
@="cmd /c dir /b /s /a /o:gn | clip"

[HKEY_CLASSES_ROOT\Directory\shell\Copy File List]
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\Copy File List\command]
@="cmd /c dir \"%1\" /b /s /a / o:gn | clip"
}

But there was some problem with file's name containing unicode characters.

Security reasson is REG and BAT files can cause malicious behaviour.
So why users are able to upload Registry files? I knew that BAT files are not allowed and I just typed them
Anyway...
 
Let’s back up a moment here, what is it you are trying to get the BAT file to do?

your first one lists all files in the \system32 folder (since you aren’t passing the script any parameters) and pipes the output to the clipboard.
The second does the same but without sub folders.
the third, same as first but now the output gets directed to a text file and then opened in notepad.
the fourth, same as third but without sub folders.

what is the file list used for, and do you only want it to list that system folder?
 
No I want it to list every folder that I right click on and the 1st & 3rd are working but 2 other option returns empty list with using batch files.

I could get rid of batch files & everything is working fine.
But if anybody can improve this method I appreciate it.

Here is the Registry file

{
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\File List]
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell]

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List]
"MUIVerb"="Create File List"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\1Create File List\command]
@="cmd /u /c dir \"%1\" /b /a /o:gn > C:\\Windows\\Temp\\fileList.txt && start notepad C:\\Windows\\Temp\\fileList.txt"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)]
"MUIVerb"="Create File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\2Create File List (Include Subfolders)\command]
@="cmd /u /c dir \"%1\" /b /s /a /o:gn > C:\\Windows\\Temp\\fileList.txt && start notepad C:\\Windows\\Temp\\fileList.txt"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List]
"MUIVerb"="Copy File List"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\3Copy File List\command]
@="cmd /c chcp 65001 && dir \"%1\" /b /a /o:gn | clip"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)]
"MUIVerb"="Copy File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\shell\File List\shell\4Copy File List (Include Subfolders)\command]
@="cmd /c chcp 65001 && dir \"%1\" /b /s /a /o:gn | clip"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List]
"SubCommands"=""
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell]

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List]
"MUIVerb"="Create File List"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\1Create File List\command]
@="cmd /u /c dir /b /a /o:gn > C:\\Windows\\Temp\\fileList.txt && start notepad C:\\Windows\\Temp\\fileList.txt"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)]
"MUIVerb"="Create File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\2Create File List (Include Subfolders)\command]
@="cmd /u /c dir /b /s /a /o:gn > C:\\Windows\\Temp\\fileList.txt && start notepad C:\\Windows\\Temp\\fileList.txt"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List]
"MUIVerb"="Copy File List"
"CommandFlags"=dword:00000020

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\3Copy File List\command]
@="cmd /c chcp 65001 && dir /b /a /o:gn | clip"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)]
"MUIVerb"="Copy File List (Include Subfolders)"

[HKEY_CLASSES_ROOT\Directory\background\shell\File List\shell\4Copy File List (Include Subfolders)\command]
@="cmd /c chcp 65001 && dir /b /s /a /o:gn | clip"
}

I don't know why but Windows wasn't able to create text file in %temp% so I just changed it to "C:\Windows\Temp"
 
Status
Not open for further replies.