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

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
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

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

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

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

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
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

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

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 for2: Delate, rename through batch files?
Thread Forum
Can't seem to rename files in AVG Rescue System Security
Batch rename in DOS or Windows Powershell General Discussion
Batch file or Exe to copy & rename directory and update files General Discussion
Can't rename files 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 05:39 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33