Solved A little Batch Help Please


TechnoMage2021

Retired PC Builder/Tech
Power User
VIP
Local time
6:26 AM
Posts
1,001
Location
Central Florida, USA
OS
Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
I want to use the Rename (ren) command in a batch file, to rename four files of the same name, that are located in four different directories, throughout Windows. Unlike several other DOS commands, REN does not allow for the /s switch, which would allow it to do it's work in many sub directories.
So my question: Is there some way, in DOS batch file language, where I can first run the DIR (Directory) command to find the location of the four files that I want to rename, and then send that info to the REN command, to rename those four files?

It's been too many years, since I've written anything but the most basic Batch Files, and I'm suffering from the "Use it or loose it" syndrome.

In the instance that I've eluded to above, I could possibly write a four line batch file, to rename the four program files, however, two of the paths are so long they would run off of the side of the CMD box. It would be great, if I could just write a one-liner to do the whole job.
Any and all help would be greatly appreciated.

Thank You,
TechnoMage :cool:
 

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.
This is how I would approach the task.
- It is possible to take other approaches but I always choose to send the For command's output to a sub-routine so I can check exactly what gets passed around and how each stage of the renaming process manipulates the parameter. I find that the extra lines in the script {compared to other approaches} are more than compensated for by the ease of script development & debugging.
- You can change the *.* to, for example, *.txt in order to limit the files passed for processing.
- The method I've used to escape a blank variable can also be used to escape from a variable value that does not fit any particular pattern that you are trying to work with. I wrap the passed parameter in FF because you cannot run an If command on an empty value - FF & FFFF are never empty values, they always contain text.

Put the highest level folder path in place of my D:\Wherever and then you'll be able to run it & watch its progress entirely non-destructively - nothing happens other than a repeated-once echo of each passed parameter.

For /F "tokens=*" %%V in (' Dir "D:\Wherever\*.*" /s /b ') do Call :ProcessFiles "%%V" GoTo EndProcessing :ProcessFiles :: Check the passed parameter, which will be the full path, name and ext of each file found :: I urge you to always wrap the passed parameter in "" if there is any possibility that the full path, name and ext of each file found might contain any spaces or special characters such as ampersands echo "%~1" :: Whilst I don't expect it to apply in your case, I always check for an empty variable being passed so that I can escape from that situation before trying to manipulate a blank variable If "FF%~1FF"=="FFFF" GoTo :EOF :: I often find it useful to set a new variable name so I can avoid further use of %~1 in processing Set "ThisVar=%~1" echo "%ThisVar%" :: Now work out your renaming command GoTo :EOF :EndProcessing Pause at EndProcessing during testing


I suspect that you might need to separate the path & extension from the filename, check whether or not the filename matches the pattern you are looking for, rename the filename then put the whole lot back together again. These guides should help you.
my ditty and demo for: Manipulating variables in batch files [post #14] - TenForums
my ditty and demo for: Standard passable variables [post #47] - TenForums



Best of luck,
Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Thanks Denis, from the Proper Part of London.

I doubt that a batch file can take into account one thing I've found out about the file I want to rename....the Bugger is locked up tighter than a bulls hind end at fly time.
I can "Take Ownership" of the file, but I still can't rename it from a batch file. "Access Denied". Arggg!
I could easily learn to HATE Windows.

I'll copy your response for future reference. And I do appreciate the effort.

Cheers Mate!
TM :cool:
 

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.
What are the permissions of the folder the files are in?
- Perhaps you can do what you want by running the batch file as Admin?
- Perhaps you can do what you want by running the batch file when booting from a USB that is capable of the necessary commands - a Windows installation USB contains most Windows commands but you'd need to check each one. A quick check could be done by booting from an installation USB then running
For /?
Ren /?
If /?
and so on for the other commands you will need.

Why do you need to rename files within a protected folder?
What's the objective?
How often would you need to run it?
What is the folder path of interest? Something within Program files?


Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Well, it's an exercise in trying to troubleshoot a problem with the Shutdown.exe command. There are four of them, in separate folders.
I can't do anything with the command without permission from "Trusted Installer" which I guess I am not. :devilish:
I guess, life would be easier if I could log in as the "Trusted Installer". Administrator just doesn't seem to be enough, for Windows.
I do have an article someplace, on "God Mode" which I've never tried.

So far, I've tried two so-called Unlocker programs, to no avail.
I do have a way to do what I want with that file, but it gets complicated, and even involves slaving my SSD to another PC.
Which, is NOT easy to do. And I won't do, in this case, since what I'm attempting to do is just an exercise and not a necessity.

I'm thinking that at this point, I need to sit down, relax and rethink just what I'm doing. I feel like I'm jousting with a windmill! :lmao:
I once read a mans sig. line, where he wrote "Anything can be accomplished by the proper application of C-4" !
I don't think he's around anymore!

Thanks again,
TM :cool:
 

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.
We're both typing at the same time. I'm adding links then I'll read your new dits.

There are utilities that can allow you to masquerade as Trusted installer.
- I have used MS SysInternals PSExec. It's not straightforward. No, I used that to masquerade as the System not as the TrustedInstaller.
- I know that I have seen other utilities mentioned and that they have been commended for being easier to use.
How to Run Programs as TrustedInstaller to Write to Certain Registry Keys or Files - WHO
ExecTI - Run Programs as TrustedInstaller - WinAero

But what are you trying to change?
If you cannot use the Shutdown command itself for some reason, you could simply add some replacement utility without trying to alter Shutdown itself.

Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
There are four of them
Four of exactly what?
in separate folders.
In which folders?
I do have a way to do what I want with that file
Which file? What's its full path?
God mode is something completely different that is not relevant to your situation.

I really do suspect that you are trying to reach your objective the wrong way.
If you explain what it is about Shutdown that you are trying to enhance / replace / ... then perhaps I can suggest a different approach.
Please accept that you ought not to replace the Shutdown command so your potential solutions should respect that.

Perhaps you can do what you want by running the batch file when booting from a USB that is capable of the necessary commands
This is feasible but I really would like to understand exactly what you are trying to do.
Windows permissions do not apply when in another OS such as the one temporarily established whilst booted from a Windows installation USB.


All the best,
Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
I'm trying to prove that none of the four instances of Shutdown.exe in windows will open up a box on the desktop, with the offer to Shutdown the PC. Another member was having problems with that very thing. It really makes no difference where the program files are.
There is actually two entirely different Shutdown.exe files, of two different sizes. That should be confusing enough. But then, after I've either renamed or deleted all four of those files, Windows still shuts down normally from several different shutdown buttons.
If all this info is confusing to you, I've been at it all day and I still don't get it. Further more, why on earth does Windows protect those Shutdown.exe files as if they were national secrets. Surely just making them Read Only would suffice. I've tried several Unlocker programs today that wouldn't touch them.
I have no real object here, except to learn how and why Windows does some of the things it does. From what I can see, there are hundreds or even thousands of lines of very complicated code in Win-11 that serves no purpose except to cause BLOAT.
It's no wonder to me, that Win-11 is so big and has to run on a 64 bit cpu.
The code for Windows XP was much simpler, and it ran just fine. And there was just one, shutdown command file.
Just operating Win-11 is bad enough, but working with the internal command structure is mind numbing.
I think I'll just mark this one Solved.
Night all!
TM :cool:
PS: It's become painfully obvious to me, that what I thought maybe could be done in a simple DOS Batch file, cannot be accomplished, because of locked files, etc. But that's OK. It's not the first roadblock I've run into with Windows 11. And, I doubt it will be the last.
 
Last edited:

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.
I'm trying to prove that none of the four instances of Shutdown.exe in windows will open up a box on the desktop, with the offer to Shutdown the PC
They don't.
You are thinking of Alt-F4.
- If you have a window selected at the time it will close it.
- If you don't have a window selected at the time, a shutdown dialog appears.
- This is a Windows component and not shutdown.exe.
- No process is listed for Alt-F4 in TaskList results but would be for an instance of Shutdown.exe running.
Alt-F4.png


Windows XP ... there was just one, shutdown command file.
XP also had that Alt-F4 shutdown dialog as well as shutdown.exe.

locked files, etc
The permissions set on their containing folders are what have been stopping you.
Those permissions are part of the scheme for protecting Windows from corruption.

the four instances of Shutdown.exe
Some of them are not really there but are a sort of hard shortcut pointing to some of the others. Many things deep within the C:\Windows folders are like this.


All the best,
Denis
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
Dennis,
The window that you showed is what the other member was seeing, but it was popping up randomly all by itself. I was trying to finger out just why and how that could happen. I had NO problem of my own, that required a fix. But I've learned a lot in the process.
Thanks for all your help, and now I'm putting this one to bed.
Cheers Mate, (from the Proper Part of London)
TM :cool:
 

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.
The window that you showed is what the other member was seeing, but it was popping up randomly all by itself.
Clean the keyboard keys.
Pay particular attention to the Alt-F4 keys and to those next to them.

Many people use a compressed air can for this.
I just blow at first. Then I use the brush from my electric shaver. I slide its longer bristles in under each key and work my way around so I've swept all the way around underneath.

Denis
 

My Computer

System One

  • OS
    Windows 11 Home x64 Version 23H2 Build 22631.3296
After cleaning literally hundreds of computer keyboards, with a previous employer, I developed my own system.
Blowing air into a keyboard can force dust down into the key-switches themselves. I've also un-soldered and replaced many key-switches that were contaminated by debris.

So my method was to use my technicians vacuum cleaner to suck the dirt out of the keyboard while I loosen it with a soft cleaning brush.
After many years, I finally found a source for Mechanical Keyboards, incorporating individual key switches that 'click' when pressed, I bought three of them. I can type much faster on this new keyboard, but that means I can make mistakes faster too. :lmao:

In short, a person should want to remove the dirt from the keyboard, and not blow it deeper into the switches.

Many of the new style keyboards cannot easily be cleaned, and probably should just be replaced.

I remember when a new keyboard could cost $149, and in those days I cleaned a lot of them. But today a new keyboard costs far less. Thank goodness!

Cheers Mates!
TM :cool:
 

My Computer

System One

  • OS
    Win-11/Pro/64, Optimum 11 V3, 23H2 22631.3085
    Computer type
    PC/Desktop
    Manufacturer/Model
    Home Made w/Gigabyte mobo/DX-10
    CPU
    AMD FX 6350 Six Core
    Motherboard
    Gigabyte, DX-10, GA-78LMT-USB3
    Memory
    Crucial, 16 GB
    Graphics Card(s)
    Onboard, ATI Radeon HD 3000; NVIDEA GeForce 210, 1GB DDR3 Ram.
    Sound Card
    Onboard
    Monitor(s) Displays
    24" Acer
    Screen Resolution
    1280x800
    Hard Drives
    Crucial SSD 500GB, SanDisk 126GB SSD, Toshiba 1TB HD
    PSU
    EVGA 500 W.
    Case
    Pac Man, Mid Tower
    Cooling
    AMD/OEM
    Keyboard
    101 key, Backlit/ Mechanical Switches/
    Mouse
    Logitech USB Wireless M310
    Internet Speed
    Hughes Net speed varies with the weather
    Browser
    Firefox 64x
    Antivirus
    Windows Defender, Super Anti Spyware
    Other Info
    Given to me as DEAD, and irreparable.
    Rebuilt with Gigabyte mobo, AMD cpu, 16GB ram and 500GB Crucial SSD.

Latest Support Threads

Back
Top Bottom