Sign in to follow this  
Followers 0
MyDream

How to run dos batch commands script inside a autoitscript itself. Please help. Thanks

14 posts in this topic

I just need to run the whole batch file command script inside the autoit script itself, not embedded the .bat file into the exe.

Anyone have any ideas how to do it?

Thanks in advance.

Share this post


Link to post
Share on other sites



Search Run and RunWait in the AutoIt help.

Depending on how complex the batch file is, it may be a simple case of rewriting the batch file in AutoIt format.

eg. RunWait(@comspec & " \C IPCONFIG /ALL > C:\Temp\IP.txt","",@SW_HIDE)

Share this post


Link to post
Share on other sites

It depends on what commands your trying to run you may be able to do them with just autoit.

If not you can fileinstall() the batchfile which you don't seem keen on or you could write the batchfile out with autoit using filewrite() or filewriteLine() then run it using Run()

Share this post


Link to post
Share on other sites

Sample bat file

@ECHO OFF

Color F7

IF NOT EXIST "C:\Program Files\Test1\Testrun.exe" GOTO THEEND

IF NOT EXIST "C:\My Files\Test2.exe" GOTO THEEND

"C:\Program Files\Test1\Testrun"

reg import "C:\My Files\Test1Run.reg"

IF %COMPUTERNAME%==Jacky GOTO END

IF %COMPUTERNAME%==Lilian GOTO END

IF %COMPUTERNAME%==Personal GOTO END

:THEEND

EXIT

:END

CLS

Call "C:\Program Files\Test2\Start.exe" -i

"C:\Program Files\Yahoo!\Messenger\Run.exe" -s

EXIT

Something like the above.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Autoit Code

IF NOT FileEXISTs ("C:\Program Files\Test1\Testrun.exe") then  TheEnd()
IF NOT FileEXISTs ("C:\My Files\Test2.exe") Then  TheEnd()

RunWait("C:\Program Files\Test1\Testrun.exe","C:\Program Files\Test1")
Run ("Regedit /s C:\My Files\Test1Run.reg")

IF @computername = "Jacky" Then END()

IF  @computername = "Lilian" Then  END()

IF  @computername = "Personal" Then END()

EXIT

Func END()

    Run (FilegetShortName("C:\Program Files\Test2\Start.exe") & " -i","C:\Program Files\Test2")
    Run (FileGetShortName("C:\Program Files\Yahoo!\Messenger\Run.exe") & " -s","C:\Program Files\Yahoo!\Messenger")
    
    EXIT

EndFunc

Func TheEnd()
    Exit
EndFunc

Simplified version

IF NOT FileEXISTs ("C:\Program Files\Test1\Testrun.exe") then  Exit
IF NOT FileEXISTs ("C:\My Files\Test2.exe") Then  Exit

RunWait("C:\Program Files\Test1\Testrun.exe","C:\Program Files\Test1")
Run ("Regedit /s C:\My Files\Test1Run.reg")

IF @computername = "Jacky" or @computername = "Lilian" or @computername = "Personal"  Then 

    Run (FilegetShortName("C:\Program Files\Test2\Start.exe") & " -i","C:\Program Files\Test2")
    Run (FileGetShortName("C:\Program Files\Yahoo!\Messenger\Run.exe") & " -s","C:\Program Files\Yahoo!\Messenger")
    
EndIf
Edited by ChrisL

Share this post


Link to post
Share on other sites

Autoit Code

IF NOT FileEXISTs ("C:\Program Files\Test1\Testrun.exe") then  TheEnd()
IF NOT FileEXISTs ("C:\My Files\Test2.exe") Then  TheEnd()

RunWait("C:\Program Files\Test1\Testrun.exe","C:\Program Files\Test1")
Run ("Regedit /s C:\My Files\Test1Run.reg")

IF @computername = "Jacky" Then END()

IF  @computername = "Lilian" Then  END()

IF  @computername = "Personal" Then END()

EXIT

Func END()

    Run (FilegetShortName("C:\Program Files\Test2\Start.exe") & " -i","C:\Program Files\Test2")
    Run (FileGetShortName("C:\Program Files\Yahoo!\Messenger\Run.exe") & " -s","C:\Program Files\Yahoo!\Messenger")
    
    EXIT

EndFunc

Func TheEnd()
    Exit
EndFunc

Simplified version

IF NOT FileEXISTs ("C:\Program Files\Test1\Testrun.exe") then  Exit
IF NOT FileEXISTs ("C:\My Files\Test2.exe") Then  Exit

RunWait("C:\Program Files\Test1\Testrun.exe","C:\Program Files\Test1")
Run ("Regedit /s C:\My Files\Test1Run.reg")

IF @computername = "Jacky" or @computername = "Lilian" or @computername = "Personal"  Then 

    Run (FilegetShortName("C:\Program Files\Test2\Start.exe") & " -i","C:\Program Files\Test2")
    Run (FileGetShortName("C:\Program Files\Yahoo!\Messenger\Run.exe") & " -s","C:\Program Files\Yahoo!\Messenger")
    
EndIf
Thanks for the help, you give me roughly hows its done in autoitscript, although it'll take me sometime to do it since my batch script very long. But thank very much. I'll know what to do with it.

Share this post


Link to post
Share on other sites

Thanks for the help, you give me roughly hows its done in autoitscript, although it'll take me sometime to do it since my batch script very long. But thank very much. I'll know what to do with it.

Maybe a suggestion:

Estimate the time it will take you to manually rewrite all batch instructions to AutoIt format.

Then check that against the estimated time of writing a function to convert (some part of?) the batch instructions into autoit format automatically, added to the "experience points" gained by it.

See, if you have 200 batch instructions of which many (if not all) are very similar, you will probably be way better off investing in writing a conversion function :whistle:


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Maybe a suggestion:

Estimate the time it will take you to manually rewrite all batch instructions to AutoIt format.

Then check that against the estimated time of writing a function to convert (some part of?) the batch instructions into autoit format automatically, added to the "experience points" gained by it.

See, if you have 200 batch instructions of which many (if not all) are very similar, you will probably be way better off investing in writing a conversion function :whistle:

Actually, my batch file is way more complex than the one I posted here, but too bad, when it comes to Autoit script, Im still a beginner, writing an Autoit script to convert all my batch files into autoit scripts are too difficult for me. I'll take my time unless I can find certain programs to do it. The reason I wanted to use Autoit script instead of normal bat program is because most bat to exe programs have problems with antivirus programs now. So far, no perfect solution yet, its either use these programs without antivirus or find an alternate program to perform these functions and use together with an antivirus.

I'll take my time to convert these batch files, hopefully.

Share this post


Link to post
Share on other sites

Actually, my batch file is way more complex than the one I posted here, but too bad, when it comes to Autoit script, Im still a beginner, writing an Autoit script to convert all my batch files into autoit scripts are too difficult for me. I'll take my time unless I can find certain programs to do it. The reason I wanted to use Autoit script instead of normal bat program is because most bat to exe programs have problems with antivirus programs now. So far, no perfect solution yet, its either use these programs without antivirus or find an alternate program to perform these functions and use together with an antivirus.

I'll take my time to convert these batch files, hopefully.

Hmm... Just out of curiosity... I am pretty puzzled by why you can't just FileInstall() the batch files, or put everything in strings and write the batchfiles when needed? Maybe there's still some time to save by reviewing your approach?


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites

Hmm... Just out of curiosity... I am pretty puzzled by why you can't just FileInstall() the batch files, or put everything in strings and write the batchfiles when needed? Maybe there's still some time to save by reviewing your approach?

For securit reason of course. :)

Anyway, lets said

if computer name = joan then perform this function 1 and function z then exit.

if computer name = john then perform this function 2 and function z then exit.

.

.

.

.

.

if computer name = ellen then perform this function 20 and function z then exit.

Lets say I got 10 or more computers, each computer perform one fucntion specifically for that computer and another funciton that is same for all computers. Beside doing it like one statement by statement like the above, is there any other way to do it or program it. For batch, its normally statement by statement, what about autoitscript?

Thanks.

Share this post


Link to post
Share on other sites

Do you mean like this?

Switch @ComputerName    
    Case "Joan"
        Function1()
    Case "John"
        Function2()
    Case "Ellen"
        Function20()
    Case Else
        Exit
EndSwitch
Functionz()





Func Function1()
;Do stuff
EndFunc

Func Function2()
;Do stuff
EndFunc

Func Function20()
;Do stuff
EndFunc

Func Functionz()
;Do stuff for everybody
EndFunc

Share this post


Link to post
Share on other sites

Do you mean like this?

Switch @ComputerName    
    Case "Joan"
        Function1()
    Case "John"
        Function2()
    Case "Ellen"
        Function20()
    Case Else
        Exit
EndSwitch
Functionz()
Func Function1()
;Do stuff
EndFunc

Func Function2()
;Do stuff
EndFunc

Func Function20()
;Do stuff
EndFunc

Func Functionz()
;Do stuff for everybody
EndFunc
Thanks for your help. :)

Its cool since I havent figure out all the functions and commands that I can use in autoitscript. Hehe.

One thing though, anyway we can just compare the joan1 and joan2 computernames for just the 4 characters in front like for computer in joanXXX will perform this function for it?

Share this post


Link to post
Share on other sites

Thanks for your help. :)

Its cool since I havent figure out all the functions and commands that I can use in autoitscript. Hehe.

One thing though, anyway we can just compare the joan1 and joan2 computernames for just the 4 characters in front like for computer in joanXXX will perform this function for it?

Switch StringLeft(@computername,4)
    Case "Joan"
        Function1()
    Case "John"
        Function2()
    Case "Elle";have to shorten this one to the first 4 characters!
        Function20()
    Case Else
        Exit
EndSwitch
Functionz()

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
Sign in to follow this  
Followers 0