Sign in to follow this  
Followers 0
TheNorwegianUser

Shellexecute / Run error

3 posts in this topic

#1 ·  Posted (edited)

Okay, so I have a TCP connection set up over some computers, no problem. I recieve the messages without problem, and when I get a specific message over the server, it runs some program. No problem at first. But then, after the whole script has ran for a while, it won't open any program, not even a web page like ShellExecute("www.google.com"). It just returns @error=1. It's nothing wrong with the path, FileExists makes sure of that (Always returns 1). When I then try using Run instead of ShellExecute, I still get an error. Any idea why it just works at first, but then starts to fail every time?

Relevant for opening a specific file:

ShellExecute(@DesktopDir & "\Fireplace.mp4")
If @error Then
    FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  ShellExecute Error: " & @error & " & Extended: " & @extended & @CRLF)
    $Exists=FileExists(@DesktopDir & "\Fireplace.mp4")
    FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Exists: " & $Exists & " & exists error: " & @error & " & Extended: " & @extended & @CRLF);;;;;;;;;;;
    Run(@DesktopDir & "\Fireplace.mp4")
    If @error Then FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Run Bål Error: " & @error & " & Extended: " & @extended & @CRLF)
EndIf

Whole client:

#Include <_AudioEndpointVolume.au3>
#include <Process.au3>
TCPStartup()
OnAutoItExitRegister("Terminate")
$IPAdress="My personal IP..."
$Port= Some IP...
Local $Socket
Connect()

While 1
    Sleep(50)
    Recv()
    If _IsInternetConnected()=False Then Connect(2)
WEnd

Func Recv()
    $Recv=TCPRecv($Socket, 2048)
    If @error>0 Then Connect(@error & "    " & @extended)
    If $Recv="" Then Return
    FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Recieved " & $Recv & @CRLF);;;;;;;;;;;
    $Recv=StringReplace($Recv, @CR, "")
    CheckForAction($Recv)
EndFunc

Func Connect($Conn=0)
    TCPCloseSocket($Socket)
    FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Connection mode " & $Conn & @CRLF);;;;;;;;;;;
    TraySetIcon(@ScriptDir & "\icons\offline.ico")
    Do
        Sleep(1000)
        $Socket=TCPConnect($IPAdress, $Port)
    Until Not @error
    TraySetIcon(@ScriptDir & "\icons\online.ico")
    TCPSend($Socket, "ImMain")
EndFunc

Func CheckForAction($_Recv)
    If $_Recv="vg" Then
        ShellExecute("www.vg.no")
        Return True
    EndIf
    If $_Recv="bål" Or $_Recv="bÃ¥l" Then
        ShellExecute(@DesktopDir & "\Fireplace.mp4")
        If @error Then
            FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  ShellExecute Error: " & @error & " & Extended: " & @extended & @CRLF)
            $Exists=FileExists(@DesktopDir & "\Fireplace.mp4")
            FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Exists: " & $Exists & " & exists error: " & @error & " & Extended: " & @extended & @CRLF);;;;;;;;;;;
            Run(@DesktopDir & "\Fireplace.mp4")
            If @error Then FileWrite(@DesktopDir & "\MultiClientMainLog.txt", @MDAY & "." & @MON & "." & @YEAR & "   " & @HOUR & ":" & @MIN & "  -  Run Bål Error: " & @error & " & Extended: " & @extended & @CRLF)
        EndIf
        Sleep(1000)
        Send("f")
        Return True
    EndIf
    If $_Recv="exit" Then
        Send("{ALTDOWN}{F4}{ALTUP}")
        Return True
    EndIf
    If $_Recv="opp" Then
        Send("{PGUP}")
        Return True
    EndIf
    If $_Recv="ned" Then
        Send("{PGDN}")
        Return True
    EndIf
    If $_Recv="endc" Then
        FileWrite(@TempDir & "\endc.txt", "ok")
        Return True
    EndIf
    If $_Recv="startc" Then
        FileWrite(@TempDir & "\startc.txt", "ok")
        Return True
    EndIf
    If $_Recv="cbål" Or $_Recv="cbÃ¥l" Then
        FileWrite(@TempDir & "\endc.txt", "ok")
        Sleep(3000)
        ShellExecute(@DesktopDir & "\Fireplace.mp4")
        Sleep(1000)
        Send("f")
        Return True
    EndIf
    If StringLeft($_Recv, 3)="cmd" Then
        _RunDOS(StringTrimLeft($_Recv, 4))
        Return True
    EndIf
    If StringLeft($_Recv, 3)="au3" Then
        If FileExists(@TempDir & "\Run.au3") Then FileDelete(@TempDir & "\Run.au3")
        FileWrite(@TempDir & "\Run.au3", StringTrimLeft($_Recv, 4))
        ShellExecute(@TempDir & "\Run.au3")
        Return True
    EndIf
    If Stringleft($_Recv, 10)="set volume" Then
        _SetMasterVolumeLevelScalar(StringTrimLeft($_Recv, 11))
        Return True
    EndIf
    If StringLeft($_Recv, 4)="send" Then
        Send(StringTrimLeft($_Recv, 5))
        Return True
    EndIf
    If StringLeft($_Recv, 4)="www." Then
        ShellExecute($_Recv)
        Return True
    EndIf
    Return False
EndFunc

Func _IsInternetConnected()
    Local $aReturn = DllCall('connect.dll', 'long', 'IsInternetConnected')
    If @error Then Return SetError(1, 0, False)
    Return $aReturn[0] = 0
EndFunc ;==>_IsInternetConnected

Func Terminate()
    TCPShutdown()
    Exit
EndFunc

 

Edited by TheNorwegianUser

Share this post


Link to post
Share on other sites



Nobody has experienced anything like it? I think it's very odd, at least...

Share this post


Link to post
Share on other sites

No?

It also recieves error 10054 from TcpRecv every 15 minutes of inactivity. No idea why.

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

  • Similar Content

    • Miloud
      By Miloud
      How to get the result of the command?
      My code :
      Local $iRc = ShellExecute ( "G:\ffmpeg\bin\ffmpeg.exe" , "-version" , "G:\ffmpeg\bin\") ProcessWaitClose($iRc) $Message = StdoutRead($iRc)
    • breakbadsp
      By breakbadsp
      I want to run a python script from autoit. 
      I know we can do this with shellexecute or run , but this python script takes 3 cmd line arguments.
      How to pass them from autoit script?
      I tried many ways.
      Following solution also not working 
      e.g. 
      RunWait( 'fullpath\Python.exe Scriptpath\ReadLog.py  -f "file.log" -k "key" -e "errMsg" ') Found solution:
      RunWait( 'fullpath\Python.exe ReadLog.py -f "file.log" -k "key" -e "errMsg" ', 'Working_directory_path')  
      PFB description:
      https://stackoverflow.com/questions/45757834/how-to-pass-command-line-arguments-to-a-python-script-anyscript-while-executin
       
    • rootx
      By rootx
      I need help to understand why the run function does not work, but if i use it directly inside cmd shell the command works. $where is the name of the jpg file
      ShellExecute(@ComSpec ," /k C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&'"'&$where&'"'&" > "&'"'&@ScriptDir&"\out.txt"&'"',@ScriptDir);<----- work Run("C:\Users\root\Desktop\test\exiftool.exe -p $FileName "&$where&" > "&@ScriptDir&"\out.txt",@ScriptDir);<--- doesn't work I would use the run command!
      Thx
    • argumentum
      By argumentum
      UDF to intercept the error window of AutoIt, showing more details about the error, including ability to save and send by email!
    • nacerbaaziz
      By nacerbaaziz
      Hello
      How are you
      I have a question, please.
      I've created a window and i need
      when i run the script if it detect an other copy from the same script was runing
       the script close the first copy Automatically and run a new copy
      I want an example to understand it