Select "Open with" with . bat command

Asked

Viewed 1,086 times

-2

I need to open any image through Windows image viewer (what is standard of Windows 7), but I’m using the Windows 10 and I can’t change the system’s default application to no longer use that App which is native to the Windows 10, I searched and found that by changing some registry keys the option to select the old viewer would appear. I’m not a local computer administrator, so I thought I’d use some commands on .bat to try to do this:

%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo 
Viewer\PhotoViewer.dll", ImageView_Fullscreen "caminho da imagem"

With this command worked, but I wanted to click on the image and it was opened with the old viewer, and not stick the path in the .bat, I thought of somehow when I selected the image "open with" and selected the .bat he executed and in the "image path", already changed to the image path I clicked, through some variable or something. Does anyone have any idea?

  • There is no way because you have to change the registration and as you said yourself, you do not have administrator privileges for this

3 answers

3

First, if you call a file . bat with a parameter in the command line, you can access it through the variable %1, for example:

set caminhoDaImagem=%1

To know how to pass more parameters you can check this reply.

And then you can do something like:

%SystemRoot%\System32\rundll32.exe "%ProgramFiles%\Windows Photo 
Viewer\PhotoViewer.dll", ImageView_Fullscreen "%caminhoDaImagem%" 

Now, even if you manage to put this. bat as one of the context menu options "Open with:", there is no guarantee that the name of the file to be opened will be passed to the execution command, as this other one says reply. It may be that for files . bat it handles like this, or not. I could not find documentation on the internet that would prove such behavior. It’s something worth testing. Also, have you checked if adding to the "Open with:" menu requires administrator privileges as well? Or just setting the app as default requires them?

Finally, the solution I propose if nothing above works, is that you can drag an image up of this file ". bat", and this yes will open the . bat with the file as argument. Of course, if this is the chosen solution, and if you have an executable that does exactly what your bat proposes to do, you can do it directly with the chosen program (or a shortcut to it), without having to do one. bat so simple it would serve only at the end of intermediate.

1

I use Windows 10 and remember that one of the first things I did was to change the program to view image to look like Windows 7. In my case, I had no difficulty following these two steps:

1) Click with the right key on top of any image / open with / choose another application

tela_1

2) Select the Windows photo viewer and mark the option to always use this application to open file .jpg.

tela_2

I know it seems an obvious answer, but here it works and I believe it is easier to work this way than via script since you have no admin user.

0


inserir a descrição da imagem aqui


You can try using a bat that generates an HTA to open the image in full screen using vbs.


This eliminates the need to have administrator/password/etc privileges...

Note: 1) Works on Windows 7 asking for password/user

Note: 2) Works on Windows 8, 8.1, and 10 versions without asking for a password


@echo off && pushd "%~dp0"

if exist "%temp%\hta_img_viewer.hta" del /q /f "%temp%\hta_img_viewer.hta" 2>&1 

rem :: cria o arquivo hta para executar o trabalho :: 
>"%temp%\hta_img_viewer.hta"^
    (
     echo/^<head^>^<hta:application id="ohta"
     echo/  applicationname="preview"
     echo/  windowstate="maximize"
     echo/  border="none"
     echo/  innerborder="no"
     echo/  caption="no"
     echo/  sysmenu="no"
     echo/  maximizebutton="no"
     echo/  minimizebutton="no"
     echo/  scroll="no"
     echo/  scrollflat="yes"
     echo/  singleinstance="yes"
     echo/  showintaskbar="no"
     echo/  contextmenu="no"
     echo/  selection="no"
     echo/^>^</head^>
     echo/ body ^{
     echo/ box-sizing: border-box;
     echo/ min-height: 0vh;
     echo/ margin: 0;
     echo/ border-bottom: solid 5px #ad3127;
     echo/ padding-top: 0px;
     echo/ ^}
     echo/ ^<script language="vbscript"^>
     echo/  sub window_onload
     echo/    document.all.splash.width = document.body.offsetwidth
     echo/    document.all.splash.height = document.body.offsetheight
     echo/  end sub
     echo/^</script^>^<body^>^<p^>^<img id='splash' src='%~f1'^>^</p^>^</body^>
    ) && start "" /b mshta.exe "%temp%\hta_img_viewer.hta"
    >nul timeout /t 4 & taskkill /f /im mshta.exe 2>&1 
    del /q /f "%temp%\hta_img_viewer.hta" 2>&1 

If you would like to elaborate on hta:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.