Delate, rename through batch files?

sidfreed

New member
Local time
5:32 PM
Messages
4
Hi all,

So I'm trying to make a personal shortcut on my computer to change a password using the shiftkeys .exe (C:\Windows\System32\sethc.exe) which can be done from setup. I'm looking to design this because I frequently deal with friends and family who have forgotten passwords, as well as my purchasing used computers. I want to automate the process, but I've hit a problem, which is making the batch file remove itself.

Here's the problem. I have a .exe file replace sethc.exe, with sethc.exe renamed to sethc.exe. I'm using the following lines
Code:
del sethc.exe
ren sethc2.exe sethc.exe
del %0

The batch file deletes itself successfully (del %0), but it's completely failing at the removal of the .exe and the renaming. I've tried changing the targeting, checking the syntax, but as far as I can tell, everything checks out, yet it still fails.

Any ideas?
 

My Computer

OS
Windows 7 32 & Ubuntu 11.04

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
The function of replacing \sethc.exe is interesting; since you can initiate stickykeys on login, you can run the program from login (which means it defaults to running as administrative). Thanks for the help, but for hte sake of learning, what do the options do?

I'll check it out right now.

---Sid
 

My Computer

OS
Windows 7 32 & Ubuntu 11.04
If you mean the switches in the code given by Shawn, then here you go:

/F Force deleting of read-only files
/S Delete specified files from all subdirectories
/Q Quiet mode, do not ask if ok to delete on global wildcard
/A Selects files to delete based on attributes
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dwarf Dwf/11/2012 r09/2013
OS
Windows 8.1 Pro RTM x64
CPU
Intel Core-i5-3570K 4-core @ 3.4GHz (Ivy Bridge) (OC 4.4GHz)
Motherboard
ASRock Z77 Extreme4-M
Memory
4 x 4GB DDR3-1600 Corsair Vengeance CMZ8GX3M2A1600C9B (16GB)
Graphics Card(s)
MSI GeForce GTX770 Gaming OC 2GB
Sound Card
Realtek High Definition on board solution (ALC 898)
Monitor(s) Displays
ViewSonic VA1912w Widescreen (VGA)
Screen Resolution
1440x900
Hard Drives
OCZ Agility 3 SSD 120GB SATA III x2 (RAID 0)
Samsung HD501LJ 500GB SATA II x2
Hitachi HDS721010CLA332 1TB SATA II
Iomega 1.5TB Ext USB 2.0
WD 2.0TB Ext USB 3.0
PSU
XFX Pro Series 850W Semi-Modular
Case
Gigabyte IF233
Cooling
1 x 120mm Front Inlet 1 x 120mm Rear Exhaust
Keyboard
Microsoft Comfort Curve Keyboard 3000 (USB)
Mouse
Microsoft Comfort Mouse 3000 for Business (USB)
Internet Speed
NetGear DG834Gv3 ADSL Modem/Router (Ethernet) ~4.0 Mb/s (O2)
Antivirus
Avast! 8.0.1497
Browser
IE 11
Other Info
Optical Drive: HL-DT-ST BD-RE BH10LS30 SATA Bluray
Lexmark S305 Printer/Scanner/Copier (USB)
WEI Score: 8.1/8.1/8.5/8.5/8.25
Asus Eee PC 1011PX Netbook (Windows 7 x86 Starter)
Thanks for the code, but I'm still having no luck...

Code:
del /F /S /Q /A sethc.exe
ren sethc2.exe sethc.exe
pause
del %0
This is the input I have right now. sethc.exe is never deleted, and hence I think is the reason sethc2.exe is never renamed. when i run the batch.....
Code:
...
C:\Windows\system32>del /F /S /Q /A sethc.exe
C:\Windows\System32\sethc.exe
Is the only response I get, i don't see anything else.

Is there something else I'm missing? Most of the command-line work I do is in shell, and I feel like I'm missing something simple.
 

My Computer

OS
Windows 7 32 & Ubuntu 11.04
Sid,

sethc.exe is owned by TrustedInstaller. Have you already taking ownership of the file, and set the file's permissions to "Allow" your user account "Full Control" of the file?

If not, then this is why it's not being deleted.
 

My Computer

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Self built custom
OS
64-bit Windows 11 Pro for Workstations
CPU
Intel i7-8700K OC'd to 5 GHz
Motherboard
ASUS ROG Maximus XI Formula Z390
Memory
64 GB (4x16GB) G.SKILL TridentZ RGB DDR4 3600 MHz
Graphics Card(s)
ASUS ROG-STRIX-GTX1080TI-O11G-GAMING
Sound Card
Integrated
Monitor(s) Displays
2 x Samsung Odyssey G7 27"
Screen Resolution
2560x1440
Hard Drives
1TB Samsung 990 PRO M.2,
4TB Samsung 990 PRO PRO M.2,
TerraMaster F8 SSD Plus NAS
PSU
Seasonic Prime Titanium 850W
Case
Thermaltake Core P3
Cooling
Corsair Hydro H115i
Keyboard
Logitech wireless K800
Mouse
Logitech MX Master 4
Internet Speed
2 Gb/s Download and 100 Mb/s Upload
Antivirus
Malwarebyte Anti-Malware Premium
Browser
Google Chrome
Other Info
Logitech Z625 speaker system,
Logitech BRIO 4K Pro webcam,
HP Color LaserJet Pro MFP M477fdn,
APC SMART-UPS RT 1000 XL - SURT1000XLI,
Galaxy S23 Plus phone
This must be it, as I've inserted the file through a linux liveUSB. The goal of the script I'm writing is to not leave any fluff, so that I (or the people I'm helping) can run this on their own. Most of the file moving is done within linux, which is why I haven't been getting any results.

However, when running the two commands on an admin command prompt launched normally in windows, it still works; either way, is there a way to set and reset the permissions?

Also, is there a way to use the runas command to bypass the ownership?
 
Last edited:

My Computer

OS
Windows 7 32 & Ubuntu 11.04
Back
Top