start and stop icon

maxstretch

Reputable
Mar 19, 2014
6
0
4,510
Is it possible to make 1 batch file to open a program like magnify if it's close or close it if it's open? thank you
 
Solution
Now i solved this stuff and it works fine:

Nukemasters Code (AND mine btw) works great. I made an sheduled task out of it (with 'elevated shortcut') and had an icon on my desktop that works perfectly. But: u cannot start an sheduled task without parameters and with your mouse u can only start pure exe files and not sheduled tasks with parameters. The solution is easy as hell: start it with a second batch file.
so the tree steps should be :

1. Main body
XML:
@echo off
tasklist /FI "IMAGENAME eq magnify.exe" 2>NUL | find /I /N "magnify.exe">NUL
     
    if "%ERRORLEVEL%"=="0" (goto running) else (goto not)
     
    :running
    taskkill /im magnify.exe
    goto end
    :not
    start magnify.exe
    :end

2. use 'elevated...
Well you can use

Taskkill /im magnifier.exe

But you have to use tasklist to see if it is running

A quick bit of Google should have this solved fairly well.

A bit of Google later we have this.
Code:
tasklist /FI "IMAGENAME eq magnify.exe" 2>NUL | find /I /N "magnify.exe">NUL

if "%ERRORLEVEL%"=="0" (goto running) else (goto not)

:running
taskkill /im magnify.exe
goto end
:not
start magnify.exe
:end

Now we have a problem with it. You NEED admin to close magnify.exe so the batch file would have to be run as admin, this having to say yes to UAC.

They must have a better way.
 

maxstretch

Reputable
Mar 19, 2014
6
0
4,510
What i want to do is use my logitech mx mouse with the magnifier as you do with a microsoft mouse. I'm sure there is a simple way somewhere. Knowing the lines that microsoft use on there mouse would be so easier. But, whats life without challenges!!!
 
I had edited the above to use

Start program.exe and not just program.exe so the batch would move on and not wait for the program to close, but it still gets you stuck with needing admin.

I am almost betting it has something to do with the mouse drivers already running as an admin and the fact that MS made both.
 

elzock

Reputable
May 17, 2014
3
0
4,520


The same here. And sadly 'nukemaster's Code isn't working here. I had an nearly same Code:

XML:
@echo OFF 
set Lupe=Magnify.exe
TaskList /FI "IMAGENAME eq %Lupe%" 2>NUL | Find /I /N "%Lupe%">NUL
if "%errorlevel%" == "0" (
taskkill /IM %Lupe%
goto ende 
) else ( 
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) 
 :ende

But this stuff isn't working too. I'll put my previous versions here. Perhaps it helps someone.
test1:
XML:
tasklist | find /i "magnify.exe">nul && Taskkill /F magniy.exe

test2:
XML:
@echo OFF 
tasklist |find "magnify.exe" >nul 
if %errorlevel% == 0 (
taskkill /IM "magnify.exe"
goto ende 
) else ( 
start "%windir%\system32\magnify.exe"
goto ende 
) 
 :ende

test3:
XML:
@echo OFF 
set Lupe=magnify.exe
tasklist |find "%Lupe%" >nul 
if %errorlevel% == 0 (
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) else ( 
taskkill /IM "%Lupe%"
goto ende 
) 
 :ende

test4:
XML:
@echo OFF 
set Lupe=magnify.exe
TaskList /FI "%Lupe% eq RUNNING" 1>NUL | Find "%Lupe%" 2>NUL
if %errorlevel% == 2 (
taskkill /IM "%Lupe%"
goto ende 
) else ( 
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) 
 :ende

test5:
XML:
@echo OFF 
set Lupe=magnify.exe
TaskList /FI "IMAGENAME eq %Lupe%" 2>NUL | Find "%Lupe%" >NUL
if %errorlevel% == 2 (
taskkill /IM "%Lupe%"
goto ende 
) else ( 
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) 
 :ende

test6:
XML:
@echo OFF 
set Lupe=Magnify.exe
TaskList /FI "IMAGENAME eq %Lupe%" 2>NUL | Find "%Lupe%" >NUL
if %errorlevel% == 1 (
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) else ( 
taskkill /IM "%Lupe%"
goto ende 
) 
 :ende

test7:
Code:
[code="xml"]@echo OFF 
set Lupe=Magnify.exe
TaskList /FI "IMAGENAME eq %Lupe%" 2>NUL | Find /I /N "%Lupe%">NUL
if "%errorlevel%" == "0" (
taskkill /IM %Lupe%
goto ende 
) else ( 
start "%Lupe%" "%windir%\system32\%Lupe%"
goto ende 
) 
 :ende
[/code]

To get the batch file lateron working without UAC, you have to make a Task out of it. You can do this by yourself(manually) but theres already a small freeware tool that is automaticly doing that, and provides in a second an UAC-free Desktoplink. (name: 'elevated shortcut')




 
The problem is that killing a task needs admin rights. When I run as an admin, the batch I had was working perfect, every time I ran it, the system would either open magnifier or close it if it was open.

The opening part was always working, but it was the killing it that was an issue.
 

elzock

Reputable
May 17, 2014
3
0
4,520
Again:

To get the batch file lateron working without UAC, you have to make a sheduled Task out of it. You can do this by yourself(manually) but theres already a small freeware tool that is automaticly doing that, and provides in a second an UAC-free Desktoplink. (name: 'elevated shortcut')
 

elzock

Reputable
May 17, 2014
3
0
4,520
Now i solved this stuff and it works fine:

Nukemasters Code (AND mine btw) works great. I made an sheduled task out of it (with 'elevated shortcut') and had an icon on my desktop that works perfectly. But: u cannot start an sheduled task without parameters and with your mouse u can only start pure exe files and not sheduled tasks with parameters. The solution is easy as hell: start it with a second batch file.
so the tree steps should be :

1. Main body
XML:
@echo off
tasklist /FI "IMAGENAME eq magnify.exe" 2>NUL | find /I /N "magnify.exe">NUL
     
    if "%ERRORLEVEL%"=="0" (goto running) else (goto not)
     
    :running
    taskkill /im magnify.exe
    goto end
    :not
    start magnify.exe
    :end

2. use 'elevated shortcut' to create an UAC-free desktop icon (or do it manually)

3. write an opening batch file with the parameters u find in your new desktoplink.
Mine looks like :
XML:
@echo off
start C:\WINDOWS\system32\schtasks.exe /run /tn elevated_ADAD_potkseDmihcAsresUC

now you're able to use the start batch file with your mousebuttons or anything else without UAC. I hope that helped...:wahoo:




 
Solution