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