Windows 7 Forums

Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Delate, rename through batch files?

16 May 2011   #1
sidfreed

Windows 7 32 & Ubuntu 11.04
 
 
Delate, rename through batch files?

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 System SpecsSystem Spec
.
16 May 2011   #2
Brink

64-bit Windows 10 Pro
 
 

Hello Sidfreed, and welcome to Seven Forums.

You might give this a try to see if it may work. If not, also see if right clicking on the BAT file and clicking on "Run as administrator" may.

File - Delete from Command Prompt

Code:
del /F /S /Q /A sethc.exe
ren sethc2.exe sethc.exe
del %0
Hope this helps,
Shawn
My System SpecsSystem Spec
16 May 2011   #3
sidfreed

Windows 7 32 & Ubuntu 11.04
 
 

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 System SpecsSystem Spec
.

16 May 2011   #4
Dwarf

Windows 8.1 Pro RTM x64
 
 

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 System SpecsSystem Spec
16 May 2011   #5
sidfreed

Windows 7 32 & Ubuntu 11.04
 
 

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 System SpecsSystem Spec
16 May 2011   #6
Brink

64-bit Windows 10 Pro
 
 

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 System SpecsSystem Spec
16 May 2011   #7
sidfreed

Windows 7 32 & Ubuntu 11.04
 
 

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?
My System SpecsSystem Spec
Reply

 Delate, rename through batch files?




Thread Tools




Similar help and support threads
Thread Forum
Multi files rename
Dear All, I have a question related renaming Multi-files for examples, I have 10 shortcut files end all by the word "shortcut" and i want to delete the word shorcut from those end files, so how can i do only one time? Hello world1-shortcut Hello world2-shortcut Hello world3-shortcut...
General Discussion
Won't let me rename or copy files
I decided to try some themes and the one I installed I didn't really like it so I decided to go an uninstall it. I restored my backup explorer.exe but then delete the one from the theme but it wouldn't let me. It didn't give me any errors. It showed the screen with the progress bar of it being...
General Discussion
Can't seem to rename files in AVG Rescue
I am following this guide . I am on step 4 and I seem to be stuck. For some reason when I press the F6 key it won't let me rename the file. I am trying to get into safe mode , that's what I am trying but the last file that is loading is avgidsha.sys . After that it just reboots. I have a feeling...
System Security
Batch rename in DOS or Windows Powershell
Hi - sorry if this is not the right forum - please feel free to move this is need be. So, I have this for batch renaming files in a folder: Dir | rename-item -newname { $_.name -replace "oldname","newname" } And it works like a charm. The thing I can not figure out how to do is add...
General Discussion
Batch file or Exe to copy & rename directory and update files
I require a batch file or free utility that i can redistribute from my web site to other users, (gamers) that will copy the contents of a directory inside their game to a new location and re-name the directory at the same time. Something like this; Copy "Genesis\Vehicles\truck\diesel\4tonbaker"...
General Discussion
Cannot rename files with url extension
The strange thing is, I was able to do it 1 time. I dragged a web address off and Windows created a shortcut. I was able to change the extension to .txt. The icon changed to that for a text file, and I could open the file and read it. Since then, though, the url extension does not show up. If I...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 14:33.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App