Hack notepad.exe to launch .bat file instead of text.


  1. Posts : 30
    Windows 10
       #1

    Hack notepad.exe to launch .bat file instead of text.


    When i run command
    Code:
    c:\windows\explorer.exe d:\run.bat
    it loads bat file as if i click it in windows explorer.

    Now i need to replace notepad.exe with explorer.exe to be able to run .bat file.

    Tried to replace in windows\system32\notepad.exe it won't let me overwrite so i tried this approach found here except that i used this command

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
    "Debugger"="C:\\Windows\\explorer.exe /C \"%1\" %*"

    Now when i go WinKey+R and type Notepad it opens explorer.exe, however i think i messed up with the last part explorer.exe /C "%1" %* because it does not belong to explorer, i copied it from cmd.exe /C "%1" %*, so going to WinKey+R and typing notepad d:\bat.bat only opens explorer (not starting .bat file).



    At this point i need to find either how to replace notepad.exe with explorer.exe in windows\system32 folder or correct the regedit command so when i do WinKey+R and type notepad d:\run.bat actual bat file load.


    In case you wonder why i need this, its workaround for this issue with Excel, because excel does not show this warning when link points to .txt file.
    Made excel think it opens text file when link is pointing to to .bat with this trick
    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Classes\.bat]
    @="txtfile"
    Last edited by captainJack; 12 Mar 2024 at 16:36.
      My Computer


  2. Posts : 6,855
    22H2 64 Bit Pro
       #2

    Batch files are not launched by explorer or notepad. They run under cmd.exe.

    So replacing notepad with explorer in IFEO will only run explorer in place of notepad. It won't launch your batch file.
      My Computer


  3. Posts : 30
    Windows 10
    Thread Starter
       #3

    Callender said:
    Batch files are not launched by explorer or notepad. They run under cmd.exe.
    That's part true however they are run inside cmd.exe, but launched by explorer.exe.

    You can try this experiment WinKey+R
    cmd.exe d:\my.bat - only command prompt opens
    explorer.exe d:\my.bat - bat file loads
      My Computer


  4. Posts : 6,855
    22H2 64 Bit Pro
       #4

    Okay thanks but your IFEO hack only launches one executable in place of another.

    RE: Hyperlinks in Excel to batch files. Is there some reason why you must use Excel?

    I can think of at least one program where you could define shortcuts and pull up a list to launch one or more files.

    You could add any number of menu's, submenu's and shortcuts.

    A quick demo:

    Desktop menu called via Winkey+Z

    Hack notepad.exe to launch .bat file instead of text.-menu.jpg

    Edit menu:

    Hack notepad.exe to launch .bat file instead of text.-quick-cliq-editor-1.jpg

    Hack notepad.exe to launch .bat file instead of text.-quick-cliq-editor-2.jpg
      My Computer


  5. Posts : 30
    Windows 10
    Thread Starter
       #5

    Callender said:
    Okay thanks but your IFEO hack only launches one executable in place of another.

    RE: Hyperlinks in Excel to batch files. Is there some reason why you must use Excel?
    Because Excel allows to work with lots of data i am generating big file excel file extracting 100+ cells with data from another file using Python script and it will have links to original location of that data in original file. Need ability to sort data apply functions, like =TRANSPOSE() etc so Excel is a must.

    Callender said:
    Okay thanks but your IFEO hack only launches one executable in place of another.
    It do work with notepad++ allowing to launch files trough WinKey + R notepad d:\document.txt guess it does not work for .bat because i did set correct arguments after explorer.exe when added it to regedit.



    Reason why IFEO slution is not working if i run notepad d:\bat.bat then executed command reads like this

    cmd.exe /k "%1" "C:\Windows\system32\notepad.exe" d:\bat.bat so it never starts the bat file because putting "C:\Windows\system32\notepad.exe" in the middle.


    - - - Updated - - -

    Managed to get this working

    Method 1. Replacing windows\system32\ notepad.exe with copy of conhost.exe from same location (renamed to notepad.exe) have to take ownership of notepad.exe to be able to replace it.

    Then added this to registry and now links to .bat files open without any warning messages.

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\ClickToRun\REGISTRY\MACHINE\Software\Classes\.bat]
    @="txtfile"

    Method 2. IFEO hack way.
    Create a .bat file with contents
    Code:
    cmd.exe /c %2
    and place it somewhere where you won't incidentally delete it for sake of this example i place it in d:\run.bat. %2 simply takes second argument (so the first argument that ICEO always gives "C:\Windows\system32\notepad.exe", is ignored and not going to interfere with anything).

    Create and import .reg file to replace notepad.exe with run.bat file you just created.

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe]
    "Debugger"="D:\\run.bat"

    Now can launch .bat files trough WinKey+R using command Notepad d:\doSomething.bat
    Last edited by captainJack; 13 Mar 2024 at 13:48.
      My Computer


  6. Posts : 6,855
    22H2 64 Bit Pro
       #6

    Well done. It makes sense.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:42.
Find Us




Windows 10 Forums