Jump to content
Huntknife

Bat file to Autoit exe

Recommended Posts

Could someone help me to change Bat Code to Autoit code? Becouse i know that you cant change bat file to Autoit exe until you change the code language right?

 

@echo off

:menu

ECHO.
ECHO ....................
ECHO  Spausti 1 - Change ip 
ECHO  Spausti 2 - Start ping  
ECHO  Spausti 3 - Open google chrome
ECHO ....................
ECHO.

echo= IP Change: %IP%
echo.
CHOICE /C:123
IF ERRORLEVEL 1 SET M=1
IF ERRORLEVEL 2 SET M=2
IF ERRORLEVEL 3 SET M=3
IF %M%==1 GOTO start
IF %M%==2 GOTO ping
IF %M%==3 GOTO chrome

:start
echo.
set /p IP= Change IP= 
netsh interface ipv4 set address name="Eternetas" static %IP% 255.255.255.0
echo.
cls
goto menu

:ping

echo.
set /p Ping= Ping ip= 
echo.
Ping %Ping% -t
pause
cls
goto menu

:chrome

start "" www.google.com

cls
goto menu

The main question can Autoit do these things?

Share this post


Link to post
Share on other sites

AutoIt can do this, you can call the commands via Run i.e.

Example (untested)

Local $sIP = "192.168.1.1"
RunWait(@Comspec & ' /c netsh interface ipv4 set address name="Eternetas" static ' & $sIP & ' 255.255.255.0')

 

Share this post


Link to post
Share on other sites

 

14 minutes ago, Huntknife said:

The main question can Autoit do these things?

You can also run the Batchfile from AutoIt (name.bat or name.cmd) :

RunWait(@ComSpec & " /C " & "name.bat", "", @SW_SHOW)

Change /C to /K to see, if an error is displayed in the CMD window.

 

Edited by Musashi

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

Strange thing, i can load cmd file without error. But only thing that works is IP change, but not all three functions If i press 2 its still runs first function. Maybe have some ideas?

Share this post


Link to post
Share on other sites
45 minutes ago, Huntknife said:

If i press 2 its still runs first function. Maybe have some ideas?

This CMD jumps at least to the correct goto positions. You have to test if the respective commands are correct there.

@echo off

:menu
echo.
echo ..........................
echo  Spausti 1 - Change ip 
echo  Spausti 2 - Start ping  
echo  Spausti 3 - Open google chrome
echo  Spausti [ESC] - Quit
echo ..........................
echo.
echo= IP Change: %IP%
echo.

set Modus=0
set /p modus="Enter Selection : " 
if %modus%==1 goto start
if %modus%==2 goto ping
if %modus%==3 goto chrome
goto end


:start
echo.
set /p IP= Change IP= 
netsh interface ipv4 set address name="Eternetas" static %IP% 255.255.255.0
echo.
cls
goto menu


:ping
echo.
set /p Ping= Ping ip= 
echo.
Ping %Ping% -t
pause
cls
goto menu


:chrome
start "" www.google.com
cls
goto menu

end:
echo  Script terminated
pause

 


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

Instead of using this prehistoric DOS approach, I would recommend that you create a simple AutoIt GUI that can provide a more robust, secure interface.  It only takes a few minutes, you could add some input verification and automate pretty much all you want within your script without relying to external program.

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

Instead of using this prehistoric DOS approach, I would recommend that you create a simple AutoIt GUI that can provide a more robust, secure interface.  It only takes a few minutes, you could add some input verification and automate pretty much all you want within your script without relying to external program.

Note: I only corrected the CMD, because it was part of the user question ;).

In general, I agree with you 100% that an AutoIt-GUI is definitely the better and more reliable solution.


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites
39 minutes ago, Nine said:

It was not aimed at you @Musashi nor at OP either.  Was just a general comment.  Sorry if it seems a bit harsh.

I didn't consider your remark to be harsh, otherwise I would not have given it a 'Like' :lol:.

Sometimes answers will be provided, that are within the scope of the user question, although more appropriate solutions would be preferable. That is exactly what you did - you have suggested a better approach.


Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...