Jump to content

AutoIT help please?


Mekrel
 Share

Recommended Posts

Hi, im trying to make a global command file launcher using AutoIT, I want it to just search for files and then pass them into the run command which hides the command files from launching.

I've got it working on a test setup, kinda. It the command files have not got a space in their name then they will get executed and run, but if they have they won't. I'm sure it is just to do with the run command and the placing of quotes so that the run command ends up having speech marks enclosing the command.

$search = FileFindFirstFile("*.cmd")  

While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop

Run("cmd.exe /c '" & $file & "'", "", @SW_HIDE)
WEnd

; Close the search handle
FileClose($search)

Any help will be appreciated!

Link to comment
Share on other sites


You may have better luck with this

$search = FileFindFirstFile('*.cmd')  
If $search <> -1 Then
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
RunWait(@ComSpec & ' /c "' & $file & '"', '', @SW_HIDE)
WEnd
FileClose($search); Close the search handle
EndIf

ComSpec likes double quotes, not singles, so using single quotes by default and use double quotes as needed within the string works well.

:)

Also while I'm here, some other variations.

For au3 files (use AutoIt v3.2.0.1 or later)

$search = FileFindFirstFile('*.au3')  
If $search <> -1 Then
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
If $file = @ScriptName Then ContinueLoop
RunWait(@AutoItExe & ' /AutoIt3ExecuteScript "' & $file & '"')
WEnd
FileClose($search); Close the search handle
EndIf

or a Multi-FileType

$search = FileFindFirstFile('*.*')  
If $search <> -1 Then
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
If $file = @ScriptName Then ContinueLoop
Switch StringRight($file, 4)
Case '.cmd'
RunWait(@ComSpec & ' /c "' & $file & '"', '', @SW_HIDE)
Case '.au3'
RunWait(@AutoItExe & ' /AutoIt3ExecuteScript "' & $file & '"')
Case '.vbs'
RunWait(@SystemDir & '\WScript.exe "' & $file & '"')
EndSwitch
WEnd
FileClose($search); Close the search handle
EndIf

Link to comment
Share on other sites

Thanks very much, they work great :)

Knew either you or Nologic would come to my rescue sooner or later.

I'm doing this so that I just add the compiled script to cmdlines.txt and then throw any batch files into said directory and I won't have to update anything.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...