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

    • nikink
      By nikink
      Hi all,
      I have a bit of code that works on my old Win10 PC, that fails on my new Win10 PC, and I think the only significant difference is the version of Autoit - old PC has 3.3.12, new has 3.3.14.
      I couldn't find anything mentioned in the change logs though, so perhaps I'm wrong.
      Anyway, the code to replicate my issue is:
      Test('username', 'DOMAIN') ; THIS ERRORS: ;Test('localun', 'DOMAIN') ; THIS ERRORS: ;Test(' ', ' ') ; THIS ERRORS: ;Test('', '') ; THIS ERRORS: ;Test('localun', '') ; THIS ERRORS: ;Test('', 'DOMAIN') Func Test($un, $dom) $compName = 'PCNAME' $FullName = '.' $Description = '.' ; get the WIM object $objWMIService = ObjGet("winmgmts:\\" & $compName & "\root\cimv2") ; get default user full name and description $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") If IsObj($objAccount) Then $FullName = $objAccount.FullName $Description = $objAccount.Description EndIf ConsoleWrite($FullName & @CRLF) ConsoleWrite($Description & @CRLF) Return EndFunc  
      On my old PC this code will output just . and . for each of those line currently commented out. Which is fine.
      On my new PC any of those commented out lines of code cause an error, and the script won't even compile.
      $objAccount = $objWMIService.Get("Win32_UserAccount.Name='" & $un & "',Domain='" & $dom & "'") $objAccount = $objWMIService^ ERROR I'm very much a newb with the WMI stuff and objects, but it looks like the .Get property is failing when either $un or $dom aren't valid in v3.3.14, whereas in 3.3.12 the .Get would fail to return an object, which is then caught by the If statement.
      Am I on track with this? Is there some new/better way to code the example so that 3.3.14 will compile it?
    • BlazerV60
      By BlazerV60
      Hello all,
      I've written the code below which launches chrome in incognito mode and then proceeds to go to the autoit website.
      From my understanding, the Run() command is also supposed to output the PID number related to the application that got launched from the Run command.
      However when I run the below lines, it outputs a PID number that is different from the newly launched chrome browser's PID number, does anyone know why and possibly explain how I could retrieve the accurate PID number associated with the newly launched browser?
      Global $iPid = Run(@ComSpec & ' /c start chrome.exe https://www.autoitscript.com/forum/ -incognito' ,"", "") msgbox(0,"",$iPid) Thank you,
      Brian
    • BlazerV60
      By BlazerV60
      Hello all,
      I've been trying to figure out how to launch Google Chrome in the background (hidden) but it doesn't seem possible. I've tried the following methods:
      ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "", "", "", @SW_HIDE) Also I've tried:
      ShellExecute(@ComSpec, "/c start chrome.exe","","",@SW_HIDE) Lastly I tried:
      RunWait('"'&@ProgramFilesDir&'\Google\Chrome\Application\chrome.exe" --silent-launch',@ScriptDir)  
      But all of them launch my chrome browser without hiding it. Does anyone know a workaround for this or if AutoIT just can't Chrome? 
      Bonus points if you know how to make it launch chrome hidden and make it go to https://www.autoitscript.com
       
      Thank you,
      Brian
    • 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