How can I restore Cmd.exe (Command Prompt) if it doesn't exist?

9,581

Solution 1

You can run the System File Checker tool (SFC.exe) which will repair missing or corrupted system files:

  1. Open PowerShell as administrator.
  2. Enter sfc /scannow.

From Microsoft:

The sfc /scannow command will scan all protected system files, and replace corrupted files with a cached copy that is located in a compressed folder at %WinDir%\System32\dllcache. The %WinDir% placeholder represents the Windows operating system folder. For example, C:\Windows.

Solution 2

If it was not deleted too long ago, you can retrieve it from a windows restore snapshot. Open Explorer, go to the properties of the folder C:\Windows\System32 (via the right-click menu), and go to "Previous Versions", from which you can open any snapshot of that folder. Snapshots that were taken before a file was deleted would contain that file.

Solution 3

As requested in the comments, I'm posting this as an answer:

There's a website called Winbindex that provides links for Windows 10 binaries. The links are to Microsoft servers, so you don't need to trust a third party service as long as you verify that the links lead to Microsoft servers (if you don't know what that means, I don't recommend to use the service).

For example, here are various cmd.exe versions to download: https://winbindex.m417z.com/?file=cmd.exe

All links lead to msdl.microsoft.com, for example: https://msdl.microsoft.com/download/symbols/cmd.exe/E1CBFC5367000/cmd.exe

Share:
9,581

Related videos on Youtube

111nk111
Author by

111nk111

Updated on September 18, 2022

Comments

  • 111nk111
    111nk111 over 1 year

    cmd.exe is not in the directory C:\Windows\System32. I think that I accidentally deleted it while messing with the environment variables, I don't know.

    It's not launching from PowerShell, and I also tried Run (Win + R), but it still doesn't work.

    I think reinstalling Windows is an option, but I don't know what can happen.

    I'm using Windows 10.

    How can I recover/restore cmd.exe?

    • Moab
      Moab about 3 years
      copy cmd.exe from another W10 PC.
    • gronostaj
      gronostaj about 3 years
      @Paul I'd be hesitant to download Windows components from 3rd party sites when a known good copy can most likely be restored with built in tools
    • Paul
      Paul about 3 years
      @gronostaj the links are to Microsoft servers, e.g. latest version of Windows 10 2004: msdl.microsoft.com/download/symbols/cmd.exe/E1CBFC5367000/…
    • phuclv
      phuclv about 3 years
    • Brian Drake
      Brian Drake about 3 years
      @Paul That is an answer, and should be posted as such. Now we cannot vote on it, but we can write comments like: Ideally, we would not worry about where we download software from, but rather perform verification on the download itself. But that is not really an option for the average user. Verifying URLs is not really an option for the average user either, despite extraordinary efforts at education over many years. That is, the average user cannot be trusted to verify that the m417z site actually links to Microsoft’s site. And even if that site is legitimate today, it might not be tomorrow.
    • Brian Drake
      Brian Drake about 3 years
      @Moab That is an answer, and should be posted as such.
    • Paul
      Paul about 3 years
      @BrianDrake I don't know all the technical details behind this service, and posting a link as an answer is a bit terse. I understand what you're saying, but still, it can be useful for power users (or, rather, Super Users) who are able to verify the links.
    • Brian Drake
      Brian Drake about 3 years
      @Paul Obviously, when you post this as an answer, you should label the link as an example, explain the idea of downloading files from sites like this, and include the sort of warning that gronostaj and I are looking for.
  • MendelG
    MendelG about 3 years
    See the provided link for even more details on sfc.
  • Brian Drake
    Brian Drake about 3 years
    “you don't need to trust a third party service” You need to trust that Winbindex, a third party service, still points to Microsoft servers when you access it. Alternatively, you can verify every link before using it, but bitter experience has shown that the average user cannot be trusted to do this.
  • Paul
    Paul about 3 years
    @BrianDrake you are of course correct. I'd recommend to use it only to users that understand your point and are able to verify the links.
  • Brian Drake
    Brian Drake about 3 years
    Your post, in its current state, implicitly recommends this site to everyone. If there are such serious issues with this site that it is recommended only for experts, then this information needs to be in the answer itself, in big bold letters.
  • user21820
    user21820 about 3 years
    It's exactly as @BrianDrake says. History has proven to us time and time again that 'good' people/sites can go real bad with no warning. Such as AdBlock white-listing paid ads, NoScript showing ads for malware, PDFCreator downloading malware, and so on. And even that knowledge is not necessary to know that your statement "you don't need to trust a third-party service" is FALSE simply because winbindex.m417z.com IS a third-party service.
  • user21820
    user21820 about 3 years
    An advantage of this method is that it works for all files that were accessible using Explorer, way beyond just system files.
  • Paul
    Paul about 3 years
    I added a clarification about trusting this service and verifying the links
  • Andrew Leach
    Andrew Leach about 3 years
    It's not just the links it contains though. The site itself may do something nefarious, and you do need to trust that third-party site, as @user21820 says. Browsers are supposedly getting better at stopping direct attacks, and hopefully each visitor has their own anti-malware protection, but still...
  • gronostaj
    gronostaj about 3 years
    @AndrewLeach You're technically correct, but every website is a third-party site. If someone has superuser.com open in their browser then they're (consciously or not) accepting that risk.
  • NotThatGuy
    NotThatGuy about 3 years
    There are still plenty of ways a malicious site can trick you: misspelling the domain, having the link/hover text be a URL that's different from the actual URL or putting the string that's supposed to be the legitimate domain as a subdomain of a malicious domain instead (msdl.microsoft.com.baddomain.com).
  • Hobbamok
    Hobbamok about 3 years
    IF windows restore was enabled that is. But if it is: safest and easiest solution possible
  • Brian Drake
    Brian Drake about 3 years
    @NotThatGuy This is not a complete list: I live in Australia, so if they were targeting me, they might try msdl.microsoft.com.au. I am guessing that Microsoft actually controls that domain, but how can I be sure? This is why I have repeatedly commented that link verification needs to be left to security experts; everyone else should simply avoid sites like this. I think the current warning is good, but does not go far enough.