0

Cmd command doesn’t work at startup folder it doesn’t delete itself please help if I double click on it itself delete but if it run runs at startup it shows the message but it won’t self delete.

Echo off 
Hello world

start /b "" cmd /c del "%~f0"&exit /b
aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • `Hello world` is not a valid command line. And why are you using `start` to open another `cmd.exe` instance which to delete the batch file in? – aschipfl Dec 15 '20 at 14:29
  • There are two __Startup__ folders on Windows Vista and newer Windows versions: `%ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup` for all users which is by default write and deletion protected and `%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup` for the current user. In which of these two directories is the batch file stored which should delete itself? What about `del /A /F "%~f0" & exit`? – Mofi Dec 15 '20 at 15:52
  • %ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup this is the one that i am trying to use – Enrique Tellez Dec 15 '20 at 16:05
  • A standard user has not the permissions to delete files in `%ProgramData%\Microsoft\Windows\Start Menu\Programs\Startup`. This explains why the self-deletion does not work. I suppose as you tested your batch file with double clicking it, it was not stored in that directory. The only possibility that a batch file in this directory can delete itself is that the user account belongs to the security group of local administrators and the user has disabled user account control, i.e. the user is using Windows permanent in elevated administrator mode. So your self-deletion issue cannot be solved. – Mofi Dec 17 '20 at 13:56

2 Answers2

1

There is a simple delete command start del Filename.bat or del filemname.bat

Crazy God
  • 11
  • 2
0

I've always found this to work:

(GoTo) 2> NUL & Del "%~f0"
Compo
  • 36,585
  • 5
  • 27
  • 39