Delate, rename through batch files?


  1. Posts : 4
    Windows 7 32 & Ubuntu 11.04
       #1

    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 Computer


  2. Posts : 71,977
    64-bit Windows 11 Pro for Workstations
       #2

    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 Computer


  3. Posts : 4
    Windows 7 32 & Ubuntu 11.04
    Thread Starter
       #3

    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


  4. Posts : 9,582
    Windows 8.1 Pro RTM x64
       #4

    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


  5. Posts : 4
    Windows 7 32 & Ubuntu 11.04
    Thread Starter
       #5

    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


  6. Posts : 71,977
    64-bit Windows 11 Pro for Workstations
       #6

    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


  7. Posts : 4
    Windows 7 32 & Ubuntu 11.04
    Thread Starter
       #7

    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 by sidfreed; 16 May 2011 at 15:26. Reason: updating post
      My Computer


 

  Related Discussions
Our Sites
Site Links
About 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 06:29.
Find Us