Jump to content

ParoXsitiC

Active Members
  • Posts

    165
  • Joined

  • Last visited

About ParoXsitiC

  • Birthday 06/04/1985

Profile Information

  • Location
    Michigan

Recent Profile Visitors

281 profile views

ParoXsitiC's Achievements

Prodigy

Prodigy (4/7)

1

Reputation

  1. Bump. Windows 8 is released and I still have this issue.
  2. For those interested, I have the problem in C# as well at stackoverflow.com - it suffers from the same issues. http://stackoverflow.com/questions/6808831/delete-a-mutex-from-another-process However, if a googler happen to come across this, info may be useful.
  3. Off the bat my function isn't working right. It wont detect any Object names at all. That is.. _getHandles(ProcessExists("SciTE.exe"), "Mutant", "\Sessions\1\BaseNamedObjects\SciTE-UniqueInstanceMutex-Default") For all purposes and logic (assuming no errors on my half) should find a match, but it continues at this point: if $sObjectName <> Default and $avArray[$i][9] <> $sObjectName Then $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf And it shouldn't. This reasoning eludes me at the moment, I forgot since yesterday.. lol. However another issue I found, which could be related... Well for one, half of the calls to NtQueryObject normally have a GetLastError of 50 (which google that error yields not much info). And in some/alot cases the return value is 0 for the typename (instead of Directory, File, Mutex). I know different type object numbers vary on versions of windows, which is why you need the NtQueryObject call to determine its true type. On my system when getting the objects of SciTE the objects with objecttypenumber 39 kept giving me an objecttypename of 0. Which then messed up my if statement of If ObjectTypeName == "Mutex"...it would return true, despite ObjectTypeName supposively being a zero.. I dont know why that would return true... So I just set the a check where it If $Ret == 0 Then Return "Unknown?" and for the Objectname .. If $Ret == 0 Then Return "No Name?"... This works fine for SciTE but other processes such as osk.exe (Windows Onscreen Keyboard) it will not even detect any ObjectTypeNames...everything is returned Unknown or No name. I assumed maybe it was privledges because I took RequireAdmin out...as i didnt need it, but adding that seems to make things even more difficult as it seems osk.exe closes when you goto admin mode and then reopens... strangely.
  4. Weird how I never found anything about the diff. from remote vs local handles in my search for solutions. Thanks though, I got it working with the following code: #include <WinAPI.au3> #include <array.au3> Global Const $MUTEX_ALL_ACCESS = 0x1F0001 Global $hMutexRemote Global $hMutexLocal Global $MutexName = "SciTE-UniqueInstanceMutex-Default" Global $PIDofMutex = ProcessExists("SciTE.exe") $hMutexLocal = _getMutexLocalHandle($MutexName) If ($hMutexLocal <> 0) Then $hMutexRemote = _getMutexRemoteHandle($MutexName, $PIDofMutex) ConsoleWrite("Mutex Handle: " & $hMutexRemote & " of type: " & _getHandleType($hMutexLocal) & @CRLF) If _ReleaseMutex($hMutexRemote, $PIDofMutex) = 1 Then ConsoleWrite("Mutex Released!" & @CRLF & "Mutex Exists: " & (_getMutexRemoteHandle($MutexName, $PIDofMutex) <> -1) & @CRLF & @CRLF) Else ConsoleWrite("Mutex Released: Failed with error code: " & @error & @CRLF) ConsoleWrite("Mutex Exists: " & (_getMutexLocalHandle($MutexName) <> 0) & @CRLF & @CRLF) EndIf Else ConsoleWrite("The mutex " & $MutexName & " does not exist." & @CRLF) EndIf Func _getMutexRemoteHandle($sMutexName, $iPID=@AutoItPID) $a = _getHandles($iPID, "Mutant") $iIndex = _ArraySearch($a, "\Sessions\1\BaseNamedObjects\" & $MutexName, 0, 0, 0, 0, 1, 9) If @error == 6 Then Return SetError(1, 0, $iIndex) return $a[$iIndex][4] EndFunc Func _NtQueryObject($h, $i) $tag_OBJECT_TYPE= _ ; TYPE / NAME Doesnt matter... I just want the unicodestring. "ushort Length;" & _ "ushort MaximumLength;" & _ "ptr Name;" & _ "byte[512]" Local $ObjType=DllStructCreate($tag_OBJECT_TYPE) dllcall("ntdll.dll", "int", "NtQueryObject", "hwnd", $h, "int", $i, "ptr", dllstructgetptr($ObjType, 1), "int" ,DllStructGetSize($ObjType), "int*", 0) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") if $aGLE[0] > 0 then SetError($aGLE[0]) $buffer=DllStructCreate("wchar[256]", DllStructGetData($ObjType, "Name")) return DllStructGetData($buffer, 1) EndFunc Func _getHandleType($hMutex) $Ret = _NtQueryObject($hMutex, 2) if @error then SetError(@error) If $Ret == 0 Then Return "Unknown?" Return $Ret EndFunc Func _getHandleName($hMutex) $Ret = _NtQueryObject($hMutex, 1) if @error then SetError(@error) If $Ret == 0 Then Return "No Name?" Return $Ret EndFunc Func _getHandles($iPID=Default, $sObjectType=Default, $sObjectName=Default) $tag_SYSTEM_HANDLE_INFO= _ "USHORT UniqueProcessId;" & _; "USHORT CreatorBackTraceIndex;" & _; "ubyte ObjectTypeIndex;" & _; "ubyte HandleAttributes;" & _; "USHORT HandleValue;" & _; "ptr Object;" & _; "ptr GrantedAccess"; Local $Mem=DllStructCreate("byte[" & 40000000 & "]") Local $ret=dllcall("ntdll.dll", "int", "ZwQuerySystemInformation","int", 16, "ptr", DllStructGetPtr($MEM), "int", DllStructGetSize($MEM), "int*",0) Local $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $ret[2]+4) Local $dw=DllStructCreate("dword",$ret[2]) Local $Count=DllStructGetData($dw,1) Local $SysHnd_ptr=$ret[2]+4 Local $SysHnd_Size=DllStructGetSize($SysHnd) Local $buffer, $i=0, $lastthread, $m=0, $NextEntryDelta, $k, $temp, $space, $l Local $avArray[1000000][10] const $DUPLICATE_SAME_ACCESS = 0x2 Local $types[100] If ($iPID == Default) Then ProgressOn("Processing through PIDs", "Processing...", "0 / " & $Count & " PIDs") Local $ProgressSpacing = Int($Count / 100) EndIf While 1 if $m=$count Then ExitLoop If ($iPID == Default and mod($m, $ProgressSpacing) == 0) Then ProgressSet(($m/$count) * 100, "Processing...", $m & " / " & $Count & " PIDs") $avArray[$i][0]=DllStructGetData($SysHnd, "UniqueProcessId") ; If its not a process in the process list, skip it --- Doesnt speed it up, infact slows it down because so many searches. ;~ Local $aProcessList = ProcessList() ;~ If _ArraySearch($aProcessList, $avArray[$i][0], 0,0,0,0,1,2) == -1 Then ;~ $m+=1 ;~ $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) ;~ Continueloop ;~ EndIf If $iPID <> Default Then If $avArray[$i][0] <> $iPID Then $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf EndIf $avArray[$i][1]=DllStructGetData($SysHnd, "CreatorBackTraceIndex") if not $avArray[$i][1] Then $avArray[$i][1]="" $avArray[$i][2]=DllStructGetData($SysHnd, "ObjectTypeIndex") $avArray[$i][3]=DllStructGetData($SysHnd, "HandleAttributes") if not $avArray[$i][3] Then $avArray[$i][3]="" $avArray[$i][4]=ptr(DllStructGetData($SysHnd, "HandleValue")) $avArray[$i][5]=DllStructGetData($SysHnd, "Object") $avArray[$i][6]=DllStructGetData($SysHnd, "GrantedAccess") $hProcSource=_WinAPI_OpenProcess(0x1f0fff, 0, $avarray[$i][0]) $hProcDest=_WinAPI_OpenProcess(0x1f0fff, 0, @AutoItPID) $ret=dllcall("kernel32.dll","int","DuplicateHandle","hwnd", $hProcSource, "hwnd", $avarray[$i][4], "hwnd", $hProcDest, "hwnd*", 0, "int",0, "int", 0, "int", $DUPLICATE_SAME_ACCESS) $avArray[$i][7]=$ret[4] $avArray[$i][7]=$ret[4] if $types[$avArray[$i][2]] == "" Then $avArray[$i][8]=_getHandleType($ret[4]) $types[$avArray[$i][2]]=$avArray[$i][8] Else $avArray[$i][8]=$types[$avArray[$i][2]] EndIf ;Filter by ObjectType if $sObjectType <> Default and $avArray[$i][8] <> $sObjectType Then $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf ; Try to filter out NAMED PIPES to not deadlock. Writing a driver to get names would be best. I'm researching... if $avArray[$i][2]=28 Then if $avArray[$i][6]=0x00120189 Then $avArray[$i][9]=" NAMED PIPES ??? - DANGER OF DEADLOCK - SKIPPED ..." $m+=1 ;$i+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf if $avArray[$i][6]=0x00100000 Then $avArray[$i][9]=" NAMED PIPES ??? - DANGER OF DEADLOCK - SKIPPED ..." $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf if $avArray[$i][6]=0x0012019F Then if $avArray[$i][3]<2 Then $avArray[$i][9]=" NAMED PIPES ??? - DANGER OF DEADLOCK - SKIPPED ..." $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf EndIf EndIf Switch $avArray[$i][2] Case 5 $ret1=dllcall("kernel32.dll", "int", "GetProcessId", "hwnd", $ret[4]) $avArray[$i][9]=$ret1[0] Case Else if not $avArray[$i][9] Then $avArray[$i][9]=_getHandleName($ret[4]) if not $avArray[$i][9] Then $avArray[$i][9]="" EndIf EndSwitch if $sObjectName <> Default and $avArray[$i][9] <> $sObjectName Then $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) Continueloop EndIf _WinAPI_CloseHandle($hProcSource) _WinAPI_CloseHandle($hProcDest) $i+=1 $m+=1 $SysHnd=DllStructCreate($tag_SYSTEM_HANDLE_INFO, $SysHnd_ptr+$SysHnd_Size*$m) ContinueLoop WEnd If ($iPID == Default) Then ProgressSet(($m/$count) * 100) ProgressOff() EndIf If $i > 0 Then Redim $avArray[$i][10] Return $avArray EndFunc Func _getMutexLocalHandle($szMutexName) Dim $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", False, "str", $szMutexName) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") If IsArray($aGLE) And $aGLE[0] = 127 Then Return $hMutex[0] Return 0 EndFunc ;==>_MutexExists Func _ReleaseMutex($hMutex, $iPID=@AutoItPID) $test = _DuplicateHandle($iPID,$hMutex,@AutoItPID, true) if @error then Return SetError(@error, 0, 0) return 1 EndFunc ;==>_ReleaseMutex ;=============================================================================== ; ; Description: Duplicates a Handle from or for another process ; Parameter(s): $dwSourcePid - Pid from Source Process ; $hSourceHandle - The Handle to duplicate ; $dwTargetPid - Optional, Pid from Target Procces - Defaults to current process ; $fCloseSource - Optional, Close the source handle - Defaults to False ; Requirement(s): 3.2.4.9 ; Return Value(s): On Success - Duplicated Handle ; On Failure - 0 and sets error to ; @error to: 1 - Api OpenProcess Failed ; 2 - Api DuplicateHandle Falied ; Author(s): Florian 'Piccaso' Fida ; Note(s): ; ;=============================================================================== Func _DuplicateHandle($dwSourcePid, $hSourceHandle, $dwTargetPid = @AutoItPID, $fCloseSource = False) Local $hTargetHandle, $hPrSource, $hPrTarget, $dwOptions $hPrSource = __dh_OpenProcess($dwSourcePid) $hPrTarget = __dh_OpenProcess($dwTargetPid) If $hPrSource = 0 Or $hPrTarget = 0 Then _CloseHandle($hPrSource) _CloseHandle($hPrTarget) Return SetError(1, 0, 0) EndIf ; DUPLICATE_CLOSE_SOURCE = 0x00000001 ; DUPLICATE_SAME_ACCESS = 0x00000002 If $fCloseSource <> False Then $dwOptions = 0x01 + 0x02 Else $dwOptions = 0x02 EndIf $hTargetHandle = DllCall("kernel32.dll", "int", "DuplicateHandle", "ptr", $hPrSource, "ptr", $hSourceHandle, "ptr", $hPrTarget, "long_ptr", 0, "dword", 0, "int", 1, "dword", $dwOptions) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") if $aGLE[0] > 0 then Return SetError($aGLE[0], 0, 0) Return $hTargetHandle[4] EndFunc ;==>_DuplicateHandle Func __dh_OpenProcess($dwProcessId) ; PROCESS_DUP_HANDLE = 0x40 Local $hPr = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", 0x40, "int", 0, "dword", $dwProcessId) If @error Then Return SetError(1, 0, 0) Return $hPr[0] EndFunc ;==>__dh_OpenProcess Func _CloseHandle($hAny) If $hAny = 0 Then Return SetError(1, 0, 0) Local $fch = DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hAny) If @error Then Return SetError(1, 0, 0) Return $fch[0] EndFunc ;==>_CloseHandle Func _Escape() Exit EndFunc ;==>_Escape I use the local mutant address to check if it exists, because it's way faster than the remote way. The remote way goes through every PID, I am not sure if there is a way to filter a certain PID natively. Strangely the local mutant still exists when you duplicate the mutant with a CLOSE...but the remote mutant does not..however when you close your autoit.exe the local mutant address dies...probably not closing handles right maybe? On a related note I tried to modify your function to Handles to "_getHandles" which was a function I was tyring to do the following with: _getHandles(Default) -- get all objects of every PID _getHandles(Default, "File") -- Get every file object from every PID _getHandles(Default, "Mutant") -- Get every mutant from every PID _getHandles(ProcessExists("Calc.exe"), "Mutant") -- Get mutant for process calc.exe _getHandles(ProcessExists("SciTE.exe"), "Mutant", "\Sessions\1\BaseNamedObjects\SciTE-UniqueInstanceMutex-Default") -- Get info on the specific mutex from Scite.exe Only the _getHandles(ProcessExists("Calc.exe"), "Mutant") works, something about NtQuery messes up for all the other, i assume not closing handles or something. I am not sure.
  5. I did originally use your code _DuplicateHandle routine I found seemed to be a bit more polished with error checking. It does use DUPLICATE_CLOSE_SOURCE when you give it a true last parameter. My only guess is that you mean to use "duplicate" to perhaps clone the handles to a new process and then close the source on that? I am pretty confused... I have also struggled with this same problem in c# with the same error messages.. http://stackoverflow.com/questions/6808831/delete-a-mutex-from-another-process
  6. Just to confirm that I did try to figure out whats going on: Please note this will try to find the "SciTE-UniqueInstanceMutex-Default" mutex within SciTE.exe. If the mutex has been deleted successfully, when you go to edit another AU3 it will open a 2nd copy of SciTE, rather than reusing the same instance. I think the error relies in how each call of _getMutexHandle($name) seems to output a different Handle address. I would think the use of OpenMutex was JUST to get the handle and not re-open a mutex... I am not sure what's going on but I do know that DuplicateHandle failed with GetLastError of 6...which a google seems to indicate a "INVALID HANDLE" error, however the handles of the PIDs are correct and getHandleType confrism the Mutex Handle is indeed a real mutant handle. So I am not sure which "handle" is "invalid". #RequireAdmin HotKeySet("{ESC}", "_Escape"); ESC to exit #include <WinAPI.au3> #include <array.au3> Global Const $MUTEX_ALL_ACCESS = 0x1F0001 Global $hMutexGlobal Global $name = "SciTE-UniqueInstanceMutex-Default" Global $hGUI = GUICreate("Mutex Test", 400, 600) Global $ctrlEdit = GUICtrlCreateEdit("Start...", 10, 10, 380, 580) GUISetState() $hMutexGlobal = _getMutexHandle($name) _EditWrite("Mutex Exists: " & ($hMutexGlobal <> 0) & @CRLF) _EditWrite("Mutex Handle: " & $hMutexGlobal & " of type: " & getHandleType($hMutexGlobal) & @CRLF) _EditWrite("Mutex Handle: " & _getMutexHandle($name) & " of type: " & getHandleType($hMutexGlobal) & @CRLF) If _ReleaseMutex($hMutexGlobal) = 1 Then _EditWrite("Mutex Released!" & @CRLF & "Mutex Exists: " & (_MutexExists($hMutexGlobal) <> 0) & @CRLF & @CRLF) Else _EditWrite("Mutex Released: Failed with error code: " & @error & @CRLF) _EditWrite("Mutex Exists: " & (_MutexExists($hMutexGlobal) <> 0) & @CRLF & @CRLF) EndIf _EditWrite("Mutex Handle: " & _getMutexHandle($name) & " of type: " & getHandleType($hMutexGlobal) & @CRLF) While 1 Sleep(1000) WEnd Func _MutexExists($hMutex) return (getHandleType($hMutex) == "Mutant") EndFunc Func getHandleType($hMutex) $tag_OBJECT_TYPE= _ ; TYPE / NAME Doesnt matter... I just want the unicodestring. "ushort Length;" & _ "ushort MaximumLength;" & _ "ptr Name;" & _ "byte[512]" Local $ObjType=DllStructCreate($tag_OBJECT_TYPE) dllcall("ntdll.dll", "int", "NtQueryObject", "hwnd", $hMutexGlobal, "int", 2, "ptr", dllstructgetptr($ObjType, 1), "int" ,DllStructGetSize($ObjType), "int*", 0) $buffer=DllStructCreate("wchar[256]", DllStructGetData($ObjType, "Name")) return DllStructGetData($buffer, 1) EndFunc Func _getMutexHandle($szMutexName) Dim $hMutex = DllCall("kernel32.dll", "hwnd", "OpenMutex", "int", 0x1F0001, "int", False, "str", $szMutexName) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") If IsArray($aGLE) And $aGLE[0] = 127 Then Return $hMutex[0] Return 0 EndFunc ;==>_MutexExists Func _ReleaseMutex($hMutex) $test = _DuplicateHandle(ProcessExists("SciTE.exe"),$hMutex,@AutoItPID, true) if @error then Return SetError(@error, 0, 0) return 1 EndFunc ;==>_ReleaseMutex ;=============================================================================== ; ; Description: Duplicates a Handle from or for another process ; Parameter(s): $dwSourcePid - Pid from Source Process ; $hSourceHandle - The Handle to duplicate ; $dwTargetPid - Optional, Pid from Target Procces - Defaults to current process ; $fCloseSource - Optional, Close the source handle - Defaults to False ; Requirement(s): 3.2.4.9 ; Return Value(s): On Success - Duplicated Handle ; On Failure - 0 and sets error to ; @error to: 1 - Api OpenProcess Failed ; 2 - Api DuplicateHandle Falied ; Author(s): Florian 'Piccaso' Fida ; Note(s): ; ;=============================================================================== Func _DuplicateHandle($dwSourcePid, $hSourceHandle, $dwTargetPid = @AutoItPID, $fCloseSource = False) Local $hTargetHandle, $hPrSource, $hPrTarget, $dwOptions $hPrSource = __dh_OpenProcess($dwSourcePid) $hPrTarget = __dh_OpenProcess($dwTargetPid) If $hPrSource = 0 Or $hPrTarget = 0 Then _CloseHandle($hPrSource) _CloseHandle($hPrTarget) Return SetError(1, 0, 0) EndIf ; DUPLICATE_CLOSE_SOURCE = 0x00000001 ; DUPLICATE_SAME_ACCESS = 0x00000002 If $fCloseSource <> False Then $dwOptions = 0x01 + 0x02 Else $dwOptions = 0x02 EndIf $hTargetHandle = DllCall("kernel32.dll", "int", "DuplicateHandle", "ptr", $hPrSource, "ptr", $hSourceHandle, "ptr", $hPrTarget, "long_ptr", 0, "dword", 0, "int", 1, "dword", $dwOptions) Local $aGLE = DllCall("Kernel32.dll", "int", "GetLastError") if $aGLE[0] > 0 then Return SetError($aGLE[0], 0, 0) If $hTargetHandle[0] = 0 Or $hTargetHandle[4] = 0 Then _CloseHandle($hPrSource) _CloseHandle($hPrTarget) Return SetError(2, 0, 0) EndIf Return $hTargetHandle[4] EndFunc ;==>_DuplicateHandle Func __dh_OpenProcess($dwProcessId) ; PROCESS_DUP_HANDLE = 0x40 Local $hPr = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", 0x40, "int", 0, "dword", $dwProcessId) If @error Then Return SetError(1, 0, 0) Return $hPr[0] EndFunc ;==>__dh_OpenProcess Func _CloseHandle($hAny) If $hAny = 0 Then Return SetError(1, 0, 0) Local $fch = DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hAny) If @error Then Return SetError(1, 0, 0) Return $fch[0] EndFunc ;==>_CloseHandle Func _EditWrite($sString) ControlSetText($hGUI, "", $ctrlEdit, ControlGetText($hGUI, "", $ctrlEdit) & $sString) EndFunc ;==>_EditWrite Func _Escape() Sleep(5000) Exit EndFunc ;==>_Escape Output: Start...Mutex Exists: True Mutex Handle: 0x000001A8 of type: Mutant Mutex Handle: 0x000001A4 of type: Mutant Mutex Released: Failed with error code: 6 Mutex Exists: True Mutex Handle: 0x000001B4 of type: Mutant Please note how the Handle seemingly changed from 0x000001A8 to 0x000001A4 and then 0x000001B4. Also these handles seem to be the same no matter which mutex/process I target...
  7. Was there ever an update to this? I very much would like/need this ability.
  8. Ohh, Yeah I figured any type of multithreading would be complex and over complicated for AutoIT purposes unless recompiled for support for it. I never knew you made a UDF for it and a search brings me to "_RemoteThreadX" but I see you removed it as explained on your autoit site. I thought maybe you had a crack at multiprocessing UDF's. The one I use currently is ChildProc (). He has examples using WM_COPYDATA but the fastest way is he uses Environment variables. A very simple demo of what he does (more or less) is here: #include <Debug.au3> Global Const $STDIO_INHERIT_PARENT = 0x10 _DebugSetup ("Debug Window", false, 2) CheckIfChild() _DebugOut("Hello, I am the parent"); EnvSet("ChildProc", "0x" & Hex(StringToBinary("Child"))) $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, default, $STDIO_INHERIT_PARENT ) Func Child() _DebugOut("Hello, I am the child"); EndFunc Func CheckIfChild() $sCmd = EnvGet("ChildProc") If StringLeft($sCmd, 2) = "0x" Then $sCmd = BinaryToString($sCmd) Call($sCmd) If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd) Exit EndIf EndFunc However he uses functions like ProcessExists and such in his UDF, and because of it I think performance takes a hit. To counterbalance that I am going to take a crack at it mixing his idea for EnvVars, and having persistnant child processes (to avoid the slowdown of creating/destroying processes) that get fed variables/data thanks to CoCreates ideas for sending variables via STDIN/STDOUT: for the internal process functions I hope to use some parts of your UDF. Thought maybe if you had any logic/advise for me on the way you would personally approach multiprocessing.
  9. I am sure the devs had a reason for it. BTW, with PHP if you don't want to expand it you use \$var instead of $var. Infact thats how you would print dollar signs..just escaping them. Back to the topic at hand, I doubt SciTE could really format for it, since its a optional opt() that you set within AutoIT. SciTE would need to follow the logic of the program just to get an idea when to expand and when not to expand. Example: $Name = "Brian" Expand() ConsoleWrite("Hello world, my name is $Name$") UnExpand() ConsoleWrite("Hello world, my name is $Name$") Expand() ConsoleWrite("Hello world, my name is $Name$") Func Expand Opt("ExpandVarStrings", 1) EndFunc Func UnExpand Opt("ExpandVarStrings", 0) EndFunc I assume SciTE uses a type of regular expressions to figured out how to format things. That would be impossible to format correctly...
  10. I only know of PHP,PERL,Ruby who do variable interpolation. PHP & Perl have it so just declaring the variable as you would out of a string. For things like objects or arrays you would put them in brackets {}. Ruby doesn't have a variable identifier (test = "Hello world" as compared to $test = "Hello world") and therefore uses #{}. More discussion of it here, and the "language envy": http://devlicio.us/blogs/sergio_pereira/archive/2009/01/17/language-envy-string-interpolation.aspx Interestingly, VB, javascript, Java, C++, C# all don't have variable interpolation. I assume maybe because those that implemented it are most web languages that print/output a lot of information (PHP & PERL & Ruby). It's noted that C# has an implementation (http://bugsquash.blogspot.com/2009/01/poor-man-string-interpolation-in-c.html) VB has one too (http://haacked.com/archive/2009/01/04/fun-with-named-formats-string-parsing-and-edge-cases.aspx) and Javascript: http://ajaxian.com/archives/secure-string-interpolation-in-javascript & http://stackoverflow.com/questions/1408289/best-way-to-do-variable-interpolation-in-javascript etc... It's noted that if a variable doesn't have an identifying symbol like AutoIT's, PERL's or PHP's dollar sign ... Such as Ruby, VB, C#, and Javascript, Java, then they would normally opt to use {} to encase the variable or some variation of brackets. However based on the implementation of the C# and one of the Javascript's they opted for the PHP style of using dollar signs, despite not even using dollar signs for variables normally. So therefore, yes. I would say since AutoIT variables use $, that the "conventional" method would be to use $ instead of $..$ for variable interpolation.
  11. Upon looking at the help topics on the Run function to make the demo, I ran into the solution. The following code will fix the problem: Global Const $STDIO_INHERIT_PARENT = 0x10 $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, default, $STDIO_INHERIT_PARENT ) Here it is fully: #include <Debug.au3> Global Const $STDIO_INHERIT_PARENT = 0x10 _DebugSetup ("Debug Window", false, 2) CheckIfChild() _DebugOut("Hello, I am the parent"); EnvSet("ChildProc", "0x" & Hex(StringToBinary("Child"))) $iPid = Run(FileGetShortName(@AutoItExe) & ' "' & @ScriptFullPath & '"', @WorkingDir, default, $STDIO_INHERIT_PARENT ) Func Child() _DebugOut("Hello, I am the child"); EndFunc Func CheckIfChild() $sCmd = EnvGet("ChildProc") If StringLeft($sCmd, 2) = "0x" Then $sCmd = BinaryToString($sCmd) Call($sCmd) If @error And Not @Compiled Then MsgBox(16, "ChildProc Error", "Unable to Call: " & $sCmd) Exit EndIf EndFunc
  12. This is a lot of UDFs for 1 topic-- Although I guess they are all pretty similar in way. Anyways, given your experience with threads/processes and memory-- Have you ever considered giving a crack at multithreading/multiprocessing within autoit? Figured you might be the best guy for the job.
  13. It uses variable interpolation, I would suspect the formatting to be similar to how most syntaxes recognize variables in PHP variable interpolation strings. See this screenshot of notepad2 and PHP for example: http://cl.ly/1f2K0v0D3P1z3L2v3K3h Notice how the interpolated variables are still marked as normal variables, despite being in a string. ---------- Also, that consolewrite works fine? I was posting that is the -working- way.
  14. Image: http://cl.ly/0Z0k0t1N0O1c3l1n1Q3X I would expect the variables to be red.
×
×
  • Create New...