SoftVoile Posted January 12, 2009 Share Posted January 12, 2009 hi,my english is not so good so i will ask my question with simple example.i have a autoit exe with name 'my.exe' which can run multiple but with different names.like 'my.exe' your.exe' both are same scripts running at the same time.QA - now my Question is that i want to set hotkey which should only work with 'my.exe' and 'your.exe' should not respond to it. is it possible to do?QB - please check the following script. after pressing the Login Button i want to exit the loop but it's giving me error.expandcollapse popup#include <GUIConstants.au3> $Form1 = GUICreate("LOGIN", 450, 120) $DSP = DriveGetSerial("C:\") $e_cn = StringRegExpReplace(@ComputerName,"(?-i)[amkb0OoDAEXKJWlLiI]","") $e_ds = StringRegExpReplace($DSP,"(?-i)[360]","") $e_ov = StringRegExpReplace(@OSBuild,"(?-i)[0]","") $e_sp = StringRegExpReplace(@OSVersion,"(?-i)[WIN_]","") $s_string = "DA" & $e_cn & "EXX" & $e_ds & "KJW" & $e_ov & $e_sp $InputName = GUICtrlCreateInput($s_string, 40, 32, 313, 21) GUICtrlSetStyle($inputname, $GUI_DROPACCEPTED) $InputPass = GUICtrlCreateInput("", 40, 80, 313, 21) $Label1 = GUICtrlCreateLabel("Username", 136, 8, 50, 17) $Label2 = GUICtrlCreateLabel("Password", 136, 56, 50, 17) ;$Label3 = GUICtrlCreateLabel("Generated Pass 4 new users", 100, 125, 200, 17) $Button1 = GUICtrlCreateButton("Login", 368, 32, 65, 73, 0) ;$GenPass = GUICtrlCreateInput("", 40, 144, 313, 21) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Authenticate(GUICtrlRead($InputName), GUICtrlRead($InputPass)) EndSwitch ;If GUICtrlRead( $GenPass ) <> GenPassword(GUICtrlRead($InputName)) Then GUICtrlSetData($GenPass, GenPassword(GUICtrlRead($InputName))) WEnd Func Authenticate($Name, $Pass) $Name = _Crypt_HashData(_Crypt_HashData($Name), 0x8004) $Name = StringLeft( $Name, 4) & StringRight( $Name, 4 ) If $Pass = $Name Then MsgBox(0, "Access", "ALLOWED") ExitLoop Else MsgBox(0, "Access", "DENIED") EndIf EndFunc ;==>Authenticate Func GenPassword($UName) $hash = _Crypt_HashData(_Crypt_HashData($UName), 0x8004) $hash = StringLeft( $hash, 4 ) & StringRight( $hash, 4 ) Return $hash EndFunc ;==>GenPassword ;=============================================================================== ; Function Name: _Crypt_HashData() ; Description: Calculate hash from data ; Syntax: ; Parameter(s): $vData - data to hash, can be binary or a string ; $iAlgID - hash algorithm identifier, can be one of the following: ; 0x8001 = MD2 ; 0x8002 = MD4 ; 0x8003 = MD5 (default) ; 0x8004 = SHA1 ; also see http://msdn.microsoft.com/en-us/library/aa375549(VS.85).aspx ; Requirement(s): ; Return Value(s): Success = Returns hash string ; Failure = Returns empty string and sets error: ; @error -1 = error opening advapi32.dll ; @error 1 = failed CryptAcquireContext ; @error 2 = failed CryptCreateHash ; @error 3 = failed CryptHashData ; Author(s): Siao ; Modification(s): ;=============================================================================== Func _Crypt_HashData($vData, $iAlgID = 0x8004) Local $hDll = DllOpen('advapi32.dll'), $iLen = BinaryLen($vData), $hContext, $hHash, $aRet, $sRet = "", $iErr = 0, $tDat = DllStructCreate("byte[" & $iLen+1 & "]"), $tBuf DllStructSetData($tDat, 1, $vData) If $hDll = -1 Then Return SetError($hDll,0,$sRet) $aRet = DllCall($hDll,'int','CryptAcquireContext', 'ptr*',0, 'ptr',0, 'ptr',0, 'dword',1, 'dword',0xF0000000) ;PROV_RSA_FULL = 1; CRYPT_VERIFYCONTEXT = 0xF0000000 If Not @error And $aRet[0] Then $hContext = $aRet[1] $aRet = DllCall($hDll,'int','CryptCreateHash', 'ptr',$hContext, 'dword',$iAlgID, 'ptr',0, 'dword',0, 'ptr*',0) If $aRet[0] Then $hHash = $aRet[5] $aRet = DllCall($hDll,'int','CryptHashData', 'ptr',$hHash, 'ptr',DllStructGetPtr($tDat), 'dword',$iLen, 'dword',0) If $aRet[0] Then $aRet = DllCall($hDll,'int','CryptGetHashParam', 'ptr',$hHash, 'dword',2, 'ptr',0, 'int*',0, 'dword',0) ;HP_HASHVAL = 2 $tBuf = DllStructCreate("byte[" & $aRet[4] & "]") DllCall($hDll,'int','CryptGetHashParam', 'ptr',$hHash, 'dword',2, 'ptr',DllStructGetPtr($tBuf), 'int*',$aRet[4], 'dword',0) $sRet = Hex(DllStructGetData($tBuf, 1)) Else $iErr = 3 EndIf DllCall($hDll,'int','CryptDestroyHash', 'ptr',$hHash) Else $iErr = 2 EndIf DllCall($hDll,'int','CryptReleaseContext', 'ptr',$hContext, 'dword',0) Else $iErr = 1 EndIf DllClose($hDll) Return SetError($iErr,0,$sRet) EndFuncThanks to Andriek who already helped me in StringRegExpReplace() function Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them. Link to comment Share on other sites More sharing options...
iHonda Posted January 12, 2009 Share Posted January 12, 2009 for QA if you only define the hotkey in my.exe it will only function in my.exe for QB if you give me a bit ill take a look at it A great place to start Autoit 1-2-3 Link to comment Share on other sites More sharing options...
FireFox Posted January 12, 2009 Share Posted January 12, 2009 @SoftVoile QA - now my Question is that i want to set hotkey which should only work with 'my.exe' and 'your.exe' should not respond to it. is it possible to do?Not possible, you can only for example check time for key pressed : if you press <1sec script one will work and if you press >2sec script two will work expandcollapse popup#include <GUIConstants.au3> $Loop = True $Form1 = GUICreate("LOGIN", 450, 120) $DSP = DriveGetSerial("C:\") $e_cn = StringRegExpReplace(@ComputerName,"(?-i)[amkb0OoDAEXKJWlLiI]","") $e_ds = StringRegExpReplace($DSP,"(?-i)[360]","") $e_ov = StringRegExpReplace(@OSBuild,"(?-i)[0]","") $e_sp = StringRegExpReplace(@OSVersion,"(?-i)[WIN_]","") $s_string = "DA" & $e_cn & "EXX" & $e_ds & "KJW" & $e_ov & $e_sp $InputName = GUICtrlCreateInput($s_string, 40, 32, 313, 21) GUICtrlSetStyle($inputname, $GUI_DROPACCEPTED) $InputPass = GUICtrlCreateInput("", 40, 80, 313, 21) $Label1 = GUICtrlCreateLabel("Username", 136, 8, 50, 17) $Label2 = GUICtrlCreateLabel("Password", 136, 56, 50, 17) ;$Label3 = GUICtrlCreateLabel("Generated Pass 4 new users", 100, 125, 200, 17) $Button1 = GUICtrlCreateButton("Login", 368, 32, 65, 73, 0) ;$GenPass = GUICtrlCreateInput("", 40, 144, 313, 21) GUISetState(@SW_SHOW) While $Loop = True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Authenticate(GUICtrlRead($InputName), GUICtrlRead($InputPass)) EndSwitch ;If GUICtrlRead( $GenPass ) <> GenPassword(GUICtrlRead($InputName)) Then GUICtrlSetData($GenPass, GenPassword(GUICtrlRead($InputName))) WEnd Func Authenticate($Name, $Pass) $Name = _Crypt_HashData(_Crypt_HashData($Name), 0x8004) $Name = StringLeft( $Name, 4) & StringRight( $Name, 4 ) If $Pass = $Name Then MsgBox(0, "Access", "ALLOWED") Else MsgBox(0, "Access", "DENIED") $Loop = False EndIf EndFunc ;==>Authenticate Func GenPassword($UName) $hash = _Crypt_HashData(_Crypt_HashData($UName), 0x8004) $hash = StringLeft( $hash, 4 ) & StringRight( $hash, 4 ) Return $hash EndFunc ;==>GenPassword ;=============================================================================== ; Function Name: _Crypt_HashData() ; Description: Calculate hash from data ; Syntax: ; Parameter(s): $vData - data to hash, can be binary or a string ; $iAlgID - hash algorithm identifier, can be one of the following: ; 0x8001 = MD2 ; 0x8002 = MD4 ; 0x8003 = MD5 (default) ; 0x8004 = SHA1 ; also see http://msdn.microsoft.com/en-us/library/aa375549(VS.85).aspx ; Requirement(s): ; Return Value(s): Success = Returns hash string ; Failure = Returns empty string and sets error: ; @error -1 = error opening advapi32.dll ; @error 1 = failed CryptAcquireContext ; @error 2 = failed CryptCreateHash ; @error 3 = failed CryptHashData ; Author(s): Siao ; Modification(s): ;=============================================================================== Func _Crypt_HashData($vData, $iAlgID = 0x8004) Local $hDll = DllOpen('advapi32.dll'), $iLen = BinaryLen($vData), $hContext, $hHash, $aRet, $sRet = "", $iErr = 0, $tDat = DllStructCreate("byte[" & $iLen+1 & "]"), $tBuf DllStructSetData($tDat, 1, $vData) If $hDll = -1 Then Return SetError($hDll,0,$sRet) $aRet = DllCall($hDll,'int','CryptAcquireContext', 'ptr*',0, 'ptr',0, 'ptr',0, 'dword',1, 'dword',0xF0000000) ;PROV_RSA_FULL = 1; CRYPT_VERIFYCONTEXT = 0xF0000000 If Not @error And $aRet[0] Then $hContext = $aRet[1] $aRet = DllCall($hDll,'int','CryptCreateHash', 'ptr',$hContext, 'dword',$iAlgID, 'ptr',0, 'dword',0, 'ptr*',0) If $aRet[0] Then $hHash = $aRet[5] $aRet = DllCall($hDll,'int','CryptHashData', 'ptr',$hHash, 'ptr',DllStructGetPtr($tDat), 'dword',$iLen, 'dword',0) If $aRet[0] Then $aRet = DllCall($hDll,'int','CryptGetHashParam', 'ptr',$hHash, 'dword',2, 'ptr',0, 'int*',0, 'dword',0) ;HP_HASHVAL = 2 $tBuf = DllStructCreate("byte[" & $aRet[4] & "]") DllCall($hDll,'int','CryptGetHashParam', 'ptr',$hHash, 'dword',2, 'ptr',DllStructGetPtr($tBuf), 'int*',$aRet[4], 'dword',0) $sRet = Hex(DllStructGetData($tBuf, 1)) Else $iErr = 3 EndIf DllCall($hDll,'int','CryptDestroyHash', 'ptr',$hHash) Else $iErr = 2 EndIf DllCall($hDll,'int','CryptReleaseContext', 'ptr',$hContext, 'dword',0) Else $iErr = 1 EndIf DllClose($hDll) Return SetError($iErr,0,$sRet) EndFunc Cheers, FireFox. Link to comment Share on other sites More sharing options...
SoftVoile Posted January 12, 2009 Author Share Posted January 12, 2009 for QA if you only define the hotkey in my.exe it will only function in my.exe for QB if you give me a bit ill take a look at itboth 'my.exe' and 'your.exe' are same files, like copied one to another location with different name. but from inside they are same. how can i define hotkey only to the script which have name @ScriptName 'my.exe' ? Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them. Link to comment Share on other sites More sharing options...
FireFox Posted January 12, 2009 Share Posted January 12, 2009 @SoftVoile Youve forgotten the best function ? _IsPressed... #Include <misc.au3> While 1 If _IsPressed("01") and @ScriptName = "my.exe" then ;do stuff EndIf WEnd Cheers, FireFox. Link to comment Share on other sites More sharing options...
SoftVoile Posted January 12, 2009 Author Share Posted January 12, 2009 @SoftVoileNot possible, you can only for example check time for key pressed : if you press <1sec script one will work and if you press >2sec script two will work Cheers, FireFox.are you sure there is no way to do it using it? maybe some genius can handle this situation, like we know there are many functions which are not possible in autoit but some autoit experts can do it using tricks (indirectly) like multi threading. Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them. Link to comment Share on other sites More sharing options...
SoftVoile Posted January 12, 2009 Author Share Posted January 12, 2009 @SoftVoile Youve forgotten the best function ? _IsPressed... #Include <misc.au3> While 1 If _IsPressed("01") and @Scriptname=%26quot%3Bmy%2Eexe%26quot%3B then ;do stuff EndIf WEnd Cheers, FireFox. Thanks d3mon, but how to set hotkey Shift+Alt+z to this? can you provide me a example? Unresolved topics:1- Please help me in Editing or replacing a page in FireFox and IE.Please have a look at them. Link to comment Share on other sites More sharing options...
FireFox Posted January 12, 2009 Share Posted January 12, 2009 @SoftVoile Check in helpfile for hexadecimal keys and then use : #Include <misc.au3> While 1 If _IsPressed("01") and _IsPressed("02") Then ;do stuff EndIf WEndoÝ÷ ØêÚºÚ"µÍÒ[ÛYH ÒÔÜÙYÕQ]LÉÝÂÚ[HBYÒÐ[Ù^TÜÙY ][ÝÌ_][ÝÊH[ÙÈÝY[YÑ[ Cheers, FireFox. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now