Search code examples
windowsbatch-filecmdregistry

How to hide the CMD console that is launched by a saved command in the system registry?


My question is at the end, at the bottom of the message.

I started using a tool called RemoveDrive by Uwe Sieber on my Windows system

This tool allows you to force eject, for example, your flash drive, etc. when the usual way with windows fails, it looks like this:

enter image description here

Code for Eject drive (forced):

cmd.exe /q /c FOR /F "usebackq" %%i IN ('%V') DO ECHO Preparation %%~di to forced eject...wait... & TITLE Force Eject Disk %%~di & RemoveDrive.exe %%~di -e && (TITLE Drive eject completed successfully) & PAUSE

Code for Eject drive (safe):

cmd.exe /q /c FOR /F "usebackq" %%i IN ('%V') DO ECHO Preparation %%~di to safe eject...wait... & TITLE Safe Eject Disk %%~di & RemoveDrive.exe %%~di && (TITLE Drive eject completed successfully) & PAUSE

This is the entire entry that adds these values, icons and commands to the registry:

enter image description here

As you can see, the cmd.exe firing command and the appropriate commands for Eject drive (forced) to be executed are saved in the .reg file, but it's not a problem for me to change it.

In the registry itself it looks like this:

enter image description here

After launching Eject drive (forced), a CMD console window is shown which shows the progress of the RemoveDrive.exe operation and which at the end waits for the button to be pressed to close the CMD console window.

Coming to the heart of the matter, I would like the implementation of the Eject drive (forced) process to be automatic and invisible.

I managed at the moment in such a way that I removed the text o & PAUSE at the very end from the command register value.

Thanks to this, the CMD console now appears and disappears by itself when the Eject drive (forced) is finished.

However, I'm still looking for a way to make it invisible, i.e. to make the console / CMD script run as invisible without a visible window.

I've already tried to do it in several ways, but I couldn't finally cope with it and I'm still struggling with it.

I hope that someone who reads my query will know what to add and what to change in the command register value to make this text:

cmd.exe /q /c FOR /F "usebackq" %%i IN ('%V') DO ECHO Preparation %%~di to safe eject...wait... & TITLE Safe Eject Disk %%~di & RemoveDrive.exe %%~di && (TITLE Drive eject completed successfully)

Change and edit in such a way that the commands are executed without the CMD console being visible, but so that the script itself is executed in the background as hidden.

Here below you can see how after using Eject drive (forced) the CMD console is visible.

I would like it to be invisible in action:

Will anyone have an idea?

Unfortunately, it must be saved in the registry to work immediately after using the right mouse button and clicking the appropriate option, which I showed in the pictures above.

Or in other words, I have something like HidRun.exe

link here:

https://www.uwe-sieber.de/files/hidrun.zip

Please, tell me how the entire path in the registry should look like for RemoveDrive.exe to be launched by HidRun.exe as hidden?

Suppose HidRun.exe and RemoveDrive.exe - both located in "C:\Windows\System32"

What should the entire path look like for using eject drive (force) together with [-l] loop until success ?

Code without HidRun.exe:

"C:\Windows\System32\RemoveDrive.exe" %1 -e

enter image description here


Solution

  • I found the cause of the error and managed to make it work.

    Instead of using:

    cmd.exe /q /c FOR /F "usebackq" %%i IN ('%V') DO ECHO Preparation %%~di to forced eject...wait... & TITLE Force Eject Disk %%~di & RemoveDrive.exe %%~di -e && (TITLE Drive eject completed successfully) & PAUSE
    

    I use now:

    "C:\Windows\HidRun.exe"
    "C:\Windows\RemoveDrive.exe" %1 -F -L
    

    It is important that HidRun.exe is not in System32 because it does not work properly in System32 as it should.

    So I moved HidRun.exe and RemoveDrive.exe to C:\Windows\HERE

    Thanks to this, now HidRun.exe is run correctly first, which in turn makes the running RemoveDrive.exe run in the background as invisible.

    Perhaps this solution will be useful to someone in the future, so I'm leaving it here. If the admins or moderators think otherwise, please close/delete my entire thread on this topic if it's too much of a mess.

    Or mark my message as checked and as a ready solution by pinning it to the top if possible.

    Regards.