Leaderboard
Popular Content
Showing content with the highest reputation on 08/09/2015 in all areas
-
I'm writing a set of PowerShell scripts/library for Windows 10 builds. One thing I often want to do is to browse to the location of a script that is part of a larger group of scripts and run it manually to do an install or make a one off change. So I like all my scripts to work well whether run from a task sequence or double-clicked in explorer. Most of my build scripts rely on having admin rights so I like to make them able to self-elevate if required - or at least give an error message. In PowerShell 4.0 (Windows 8.1) they added the #Requires -RunAsAdministrator statement but this won't do it for you - it just causes the script to abort if not admin. Below is a PowerShell script that does the following: Checks for admin rights using the Test-IsAdmin functionIf not admin:Get the full script path and working directory using the Get-UNCFromPath functionIf the paths are mapped drives then get the UNC version (drive mappings are lost when elevating from user to admin in most configurations)Execute PowerShell.exe with the UNC path of the script and the RunAs verb to trigger elevation. ExecutionPolicy is also set to Bypass on the command line. The working directory is also set to the UNC path version.Waits for the new process to finish, and captures its return codeExits using the same return codeScript is as follows: # Test if admin function Test-IsAdmin() { # Get the current ID and its security principal $windowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent() $windowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($windowsID) # Get the Admin role security principal $adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator # Are we an admin role? if ($windowsPrincipal.IsInRole($adminRole)) { $true } else { $false } } # Get UNC path from mapped drive function Get-UNCFromPath { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [String] $Path) if ($Path.Contains([io.path]::VolumeSeparatorChar)) { $psdrive = Get-PSDrive -Name $Path.Substring(0, 1) -PSProvider 'FileSystem' # Is it a mapped drive? if ($psdrive.DisplayRoot) { $Path = $Path.Replace($psdrive.Name + [io.path]::VolumeSeparatorChar, $psdrive.DisplayRoot) } } return $Path } # Relaunch the script if not admin function Invoke-RequireAdmin { Param( [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] [System.Management.Automation.InvocationInfo] $MyInvocation) if (-not (Test-IsAdmin)) { # Get the script path $scriptPath = $MyInvocation.MyCommand.Path $scriptPath = Get-UNCFromPath -Path $scriptPath # Need to quote the paths in case of spaces $scriptPath = '"' + $scriptPath + '"' # Build base arguments for powershell.exe [string[]]$argList = @('-NoLogo -NoProfile', '-ExecutionPolicy Bypass', '-File', $scriptPath) # Add $argList += $MyInvocation.BoundParameters.GetEnumerator() | Foreach {"-$($_.Key)", "$($_.Value)"} $argList += $MyInvocation.UnboundArguments try { $process = Start-Process PowerShell.exe -PassThru -Verb Runas -Wait -WorkingDirectory $pwd -ArgumentList $argList exit $process.ExitCode } catch {} # Generic failure code exit 1 } } # Relaunch if not admin Invoke-RequireAdmin $script:MyInvocation # Running as admin if here $wshell = New-Object -ComObject Wscript.Shell $wshell.Popup("Script is running as admin", 0, "Done", 0x1) | Out-Null1 point
-
Is the offending template explicitely tagged as "malayalam"? If it's English (say), things may not work as expected, but this is just a guess. This site (by Richard Ishida, a lead member of the Unicode consortium and I8n) is full of up-to-date data and information about Unicode. For instance its uniview applet lets you see a Unicode block (e.g. malayalam) and access detailed information about each and every codepoint (e.g. 0x0D4D). EDIT: I must clarify something for future readers. When I or Ishida use the word "script", we intend "a writing system" which can be Latin, Cyrillic, Hangul, ... and this has no relationship with the term "script" as in "AutoIt is a script language".1 point
-
This is where you're confused: the text you just posted is not a letter, to wit: #include <Array.au3> Local $s = "ണ്ട" Local $a = StringToASCIIArray($s) _ArrayDisplay($a)You can as well copy the first character or the last one with the mouse on the post. This is a string of three Unicode codepoints, namely 0x00D23, 0x00D4D and 0x00D1F. That is, in this order : MALAYALAM LETTER NNA MALAYALAM SIGN VIRAMA MALAYALAM LETTER TTA The actual rendering engine (depends on the font you use) decides to group these three glyphs into a new one which doesn't have a unique Unicode codepoint. The link I gave above explains what happens, even if there is little malayalam example, you'll get the idea. Also as MS Word does a large number of things in your back, I'm uncertain you can succeed in making it do exactly what you want. Maybe simply by creating a user ligature in the menus.1 point
-
kcvinu, I understand your issue, but why did you post a bitmap and not text? Doing so doesn't allow to grab characters as you want them. Anyway, I don't know malayalam enough to guide you to a final resolution but consider that both ൺ (MALAYALAM LETTER CHILLU NN, codepoint 0x00D7A) and ട (MALAYALAM LETTER TTA, codepoint 0x00D1F) are two distinct letters. Only a malayalam-aware text processor will be able to detect that they can be represented by a ligature as in your "actual letter" example [I guess it's a ligature but not knowing enough about the script I may be wrong]. AFAIK there is no Unicode codepoint attributed to this ligature and it can only be detected and represented by a malayalam-aware font rendering code. I'm certain your code isn't intended to do anything bad and I also understand Melba concern. Can you please copy and paste the "actual letter" in text form (just like I did). Leave code away for now. I advise you read from this page (but reading the entire site would help even more).1 point
-
That brought me to this completely unnecessary UDF ... #include <WinAPI.au3> #include <WindowsConstants.au3> Local $hParent = GUICreate("Main GUI") Local $c_Button_0 = GUICtrlCreateButton("Button0", 10, 10) GUISetState(@SW_SHOW, $hParent) Local $hChild = GUICreate("Child GUI", 250, 150, 10, 10) Local $c_Button_1 = GUICtrlCreateButton("Button1", 10, 10) GUISetState(@SW_SHOW, $hChild) _WinAPI_SetParent($hChild, $hParent) Local $hChild2 = GUICreate("Child GUI", 250, 150, 10, 10) Local $c_Button_2 = GUICtrlCreateButton("Button2", 10, 10) GUISetState(@SW_SHOW, $hChild2) _WinAPI_SetParent($hChild2, $hChild) MsgBox(0, "_Window_NestingDepth", _Window_NestingDepth($hParent) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_0)) & @CRLF & @CRLF _ & _Window_NestingDepth($hChild) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_1)) & @CRLF & @CRLF _ & _Window_NestingDepth($hChild2) & @CRLF & _Window_NestingDepth(GUICtrlGetHandle($c_Button_2))) Func _Window_NestingDepth($hWnd) Local $hWnd_Desktop = _WinAPI_GetDesktopWindow(), $hWnd_Parent = _WinAPI_GetAncestor($hWnd, $GA_PARENT) If $hWnd_Parent = $hWnd_Desktop Then Return 0 ; Parent is Desktop Local $iEnum = 0 While 1 If $hWnd_Parent = $hWnd_Desktop Then Return $iEnum $iEnum += 1 If $iEnum = 999 Then Return 999 $hWnd_Parent = _WinAPI_GetAncestor($hWnd_Parent, $GA_PARENT) WEnd EndFunc ;==>_Window_NestingDepth1 point
-
How to capture the hidden program window?
guestscripter reacted to mikell for a topic
Answer for the Edit : this exists for IE using AutoItObject.au31 point -
ImageSearch Usage Explanation
guestscripter reacted to Gwaren for a topic
Alright thanks for helping me out much appreciated yeah im going to start to read the help files and get used to this program more and more just that i had worked on this then i put it all down and wanted help quick and there you where, so thanks alot for the help And ill look at the imagesearch you have posted in here1 point -
1 point
-
You need to get a reference to the frame first using _IEFrameGetObjByName. Then use this reference in place of the "normal" IE object.1 point
-
#include <WinAPIShPath.au3> #include <Array.au3> HotKeySet("{F2}","start") Func start() sleep(200) Send("EMAIL@gmail.com") sleep(1000) Send("{enter}") sleep(1000) Send("PASSWORD") sleep(1000) Send("{enter}") Exit EndFunc While 1 sleep(100) WEnd Not sure if you're still having trouble... but i tested that and it worked for me (change email and password to your email and password in case it wasn't obvious ) (if it doesn't work try running as Admin)1 point
-
I agree with @guinness, Ads are annoying in desktop apps... You might want to try including crapware in your software's installer instead of software ads, TD1 point
-
I think it's unfair to compare the two. Desktop apps have different usage compared to mobile.1 point
-
I had a look at your linked post and let Google translate it. Now I am sure much has gotten lost in translation, but must say I was somewhat surprised by the wording used and some other things like: Nowhere I see any credits of all the work I and others have put in the stuff you bluntly copied, and merely see a lot of things that we are doing wrong. This is the last I am going to say about it and leave you to maintain your own project. Jos1 point
-
I downloaded the ZIP file and did a scan at Viruscentral and got: Detection ratio: 9 / 55 There are still several files flagged and don't think we want to host this on our forum and have the risk being flagged again! Please check and either resolve or remove the ZIP file. Thanks, Jos1 point
-
Sorry my mistake... didn't closely look at the details, just saw the link re-appear without any comments. Jos1 point
-
The UDF creates a file which contains binary data of files that are added to the BinaryBin file (using the provided functions.) I decided to create this UDF because I was internally updating applications using 7-Zip (FileInstall'ed) and then extracting the ZIP file which was downloaded from the website. Despite this being effective I wanted to create a UDF in which I could import files into a file and then extract using a single function & without the need for an external application. Even though I decided to create this UDF myself, it should be pointed out that I did search the Forum to see if anything was currently available and came across >AUBinary.au3, though the function syntax's are very different and I believe my version is slightly faster. Any suggestions post below. Thanks. UDF: #include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _BinaryBin ; AutoIt Version : v3.3.10.0 or higher ; Language ......: English ; Description ...: Creates a bin file to store files that can then be extracted using native AutoIt code. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: Thanks to SmOke_N for hints about the DIR command and Malkey for the SRE's. [http://www.autoitscript.com/forum/topic/95580-a-question-regarding-pathsplit/page__view__findpost__p__687288]. ; =============================================================================================================================== ; #INCLUDES# ==================================================================================================================== #include <Crypt.au3> #include <File.au3> #include <WinAPI.au3> ; #GLOBAL VARIABLES# ============================================================================================================ Global Const $BINARYBIN_GUID = 'D74855F2-E356-11E3-8EDA-00A70707A45E' Global Enum $BINARYBIN_FILENAME, $BINARYBIN_FILEPATH, $BINARYBIN_HWND, $BINARYBIN_ID, $BINARYBIN_MAX Global Enum $BINARYBIN_ERROR_NONE, $BINARYBIN_ERROR_FATAL, $BINARYBIN_ERROR_INVALIDBIN, $BINARYBIN_ERROR_INVALIDFILENAME, $BINARYBIN_ERROR_INVALIDFOLDER ; #CURRENT# ===================================================================================================================== ; _BinaryBin: Create a new binary bin object by opening a new or previous binary file. ; _BinaryBin_Add: Add a file to a binary bin. ; _BinaryBin_AddFolder: Add a folder to a binary bin file. This is recursive i.e. it will search sub-folders too. ; _BinaryBin_Close: Close a binary bin file. ; _BinaryBin_Decrypt: Decrypt a binary bin file. ; _BinaryBin_Encrypt: Encrypt a binary bin file. ; _BinaryBin_Extract: Extract a binary bin file to a specified folder/path. ; _BinaryBin_GetFileCount: Retrieve the file count in a binary bin file. ; _BinaryBin_GetFiles: Retrieve the list of files in a binary bin file. ; _BinaryBin_GetFolders: Retrieve the list of folders in a binary bin file. ; _BinaryBin_GetSize: Retrieve the filesize of a BinaryBin file. ; _BinaryBin_GetFilePath: Rerieve the filepath of a handle returned by _BinaryBin. ; _BinaryBin_IsEncrypted: Check if a binary bin file is encrypted. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; See below ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin ; Description ...: Create a new binary bin object by opening a new or previous binary file. ; Syntax ........: _BinaryBin($sFilePath[, $bOverwrite = False]) ; Parameters ....: $sFilePath - Filepath of a new or previous binary bin file. ; $bOverwrite - [optional] Overwrite the binary bin. Default is False. ; Return values .: Handle to be passed to relevant functions. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin($sFilePath, $bOverwrite = False) Local $aBinaryBin[$BINARYBIN_MAX] $aBinaryBin[$BINARYBIN_FILENAME] = __BinaryBin_GetFileName($sFilePath) $aBinaryBin[$BINARYBIN_FILEPATH] = $sFilePath ; $CREATE_ALWAYS = 2 $aBinaryBin[$BINARYBIN_HWND] = _WinAPI_CreateFile($sFilePath, ($bOverwrite ? $CREATE_NEW : $CREATE_ALWAYS), BitOR($FILE_SHARE_WRITE, $FILE_SHARE_DELETE), 0, 0, 0) If $aBinaryBin[$BINARYBIN_HWND] > 0 Then $aBinaryBin[$BINARYBIN_ID] = $BINARYBIN_GUID Return $aBinaryBin EndFunc ;==>_BinaryBin ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_Add ; Description ...: Add a file to a binary bin. ; Syntax ........: _BinaryBin_Add(ByRef $aBinaryBin, $sFilePath[, $bOverwrite = False]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sFilePath - Valid filepath to add to the binary bin. ; $bOverwrite - [optional] Clear the contents of the binary bin. Default is False. ; Return values .: Success - Returns data string added to the binary bin ; Failure - Returns blank string & sets @error to none-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_Add(ByRef $aBinaryBin, $sFilePath, $bOverwrite = False) Return __BinaryBin_AddData($aBinaryBin, $sFilePath, True, $bOverwrite, '') EndFunc ;==>_BinaryBin_Add ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_AddFolder ; Description ...: Add a folder to a binary bin file. This is recursive i.e. it will search sub-folders too. ; Syntax ........: _BinaryBin_AddFolder(ByRef $aBinaryBin, $sFolder[, $bOverwrite = False]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sFolder - Valid folder to add to the binary bin file. ; $bOverwrite - [optional] Clear the contents of the binary bin. Default is False. ; Return values .: Success - Array of files and folder added. ; Failure - Empty array & sets @error to none-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_AddFolder(ByRef $aBinaryBin, $sFolder, $bOverwrite = False) Local $aArray = 0, $aError[0], _ $iError = $BINARYBIN_ERROR_NONE If __BinaryBin_IsBinaryBin($aBinaryBin) Then $sFolder = __BinaryBin_GetDirectoryFormat($sFolder, False) If StringInStr(FileGetAttrib($sFolder), 'D', $STR_NOCASESENSEBASIC) Then Local $iPID = Run(@ComSpec & ' /C DIR /B /A-D /S', $sFolder & '\', @SW_HIDE, $STDOUT_CHILD) ; Thanks to SmOke_N. ProcessWaitClose($iPID) $aArray = StringRegExp(@ScriptFullPath & @CRLF & StdoutRead($iPID), '([^\r\n]*)(?:\R)', $STR_REGEXPARRAYGLOBALMATCH) $aArray[0] = UBound($aArray, 1) - 1 If $aArray[0] Then If $bOverwrite Then Local $sData = '' __BinaryBin_FileWrite($aBinaryBin[$BINARYBIN_HWND], $sData, True) EndIf For $i = 1 To $aArray[0] If $aArray[$i] = $aBinaryBin[$BINARYBIN_FILENAME] Then ContinueLoop EndIf __BinaryBin_AddData($aBinaryBin, $aArray[$i], True, 0, StringReplace(StringRegExpReplace($aArray[$i], '(^.*\\)(.*)', '\1'), $sFolder & '\', '')) ; Thanks to Malkey for the SRE. Next Else $aArray = $aError $iError = $BINARYBIN_ERROR_FATAL EndIf Else $aArray = $aError $iError = $BINARYBIN_ERROR_INVALIDFOLDER EndIf Else $aArray = $aError $iError = $BINARYBIN_ERROR_INVALIDBIN EndIf Return SetError($iError, 0, $aArray) EndFunc ;==>_BinaryBin_AddFolder ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_Close ; Description ...: Close a binary bin file. ; Syntax ........: _BinaryBin_Close(Byref $aBinaryBin) ; Parameters ....: $aBinaryBin - [in/out] Handle created by _BinaryBin. ; Return values .: Success - True ; Failure - None ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_Close(ByRef $aBinaryBin) Local $bReturn = False If __BinaryBin_IsBinaryBin($aBinaryBin) Then _WinAPI_CloseHandle($aBinaryBin[$BINARYBIN_HWND]) For $i = 0 To $BINARYBIN_MAX - 1 $aBinaryBin[$i] = Null Next EndIf Return $bReturn EndFunc ;==>_BinaryBin_Close ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_Decrypt ; Description ...: Decrypt a binary bin file. ; Syntax ........: _BinaryBin_Decrypt(ByRef $aBinaryBin, $sPassword) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sPassword - Password to decrypt the binary bin file. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_Decrypt(ByRef $aBinaryBin, $sPassword) Local $bReturn = False If __BinaryBin_IsBinaryBin($aBinaryBin) And __BinaryBin_IsEncrypted($aBinaryBin) Then Local $bClose = _WinAPI_CloseHandle($aBinaryBin[$BINARYBIN_HWND]), _ $hFileOpen = 0, _ $sData = '' If $bClose Then $hFileOpen = FileOpen($aBinaryBin[$BINARYBIN_FILEPATH], $FO_READ) $bReturn = ($hFileOpen > -1) If $bReturn Then $sData = FileRead($hFileOpen) FileClose($hFileOpen) _Crypt_Startup() Local Const $hDeriveKey = _Crypt_DeriveKey($sPassword, $CALG_RC4) $sData = _Crypt_DecryptData($sData, $hDeriveKey, $CALG_USERKEY) $bReturn = (@error = $BINARYBIN_ERROR_NONE) _Crypt_DestroyKey($hDeriveKey) _Crypt_Shutdown() EndIf EndIf If $bReturn Then $hFileOpen = FileOpen($aBinaryBin[$BINARYBIN_FILEPATH], $FO_OVERWRITE) $bReturn = ($hFileOpen > -1) If $bReturn Then FileWrite($hFileOpen, $sData) FileClose($hFileOpen) EndIf EndIf If $bClose Then $aBinaryBin = _BinaryBin($aBinaryBin[$BINARYBIN_FILEPATH], False) EndIf EndIf Return $bReturn EndFunc ;==>_BinaryBin_Decrypt ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_Encrypt ; Description ...: Encrypt a binary bin file. ; Syntax ........: _BinaryBin_Encrypt(ByRef $aBinaryBin, $sPassword) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sPassword - Password to encrypt the binary bin file. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_Encrypt(ByRef $aBinaryBin, $sPassword) Local $bReturn = False If __BinaryBin_IsBinaryBin($aBinaryBin) And Not __BinaryBin_IsEncrypted($aBinaryBin) Then Local $bClose = _WinAPI_CloseHandle($aBinaryBin[$BINARYBIN_HWND]), _ $hFileOpen = 0, _ $sData = '' If $bClose Then $hFileOpen = FileOpen($aBinaryBin[$BINARYBIN_FILEPATH], $FO_READ) $bReturn = ($hFileOpen > -1) If $bReturn Then $sData = FileRead($hFileOpen) FileClose($hFileOpen) _Crypt_Startup() Local Const $hDeriveKey = _Crypt_DeriveKey($sPassword, $CALG_RC4) $sData = _Crypt_EncryptData($sData, $hDeriveKey, $CALG_USERKEY) $bReturn = (@error = $BINARYBIN_ERROR_NONE) _Crypt_DestroyKey($hDeriveKey) _Crypt_Shutdown() EndIf EndIf If $bReturn Then $hFileOpen = FileOpen($aBinaryBin[$BINARYBIN_FILEPATH], $FO_OVERWRITE) $bReturn = ($hFileOpen > -1) If $bReturn Then FileWrite($hFileOpen, $sData) FileClose($hFileOpen) EndIf EndIf If $bClose Then $aBinaryBin = _BinaryBin($aBinaryBin[$BINARYBIN_FILEPATH], False) EndIf EndIf Return $bReturn EndFunc ;==>_BinaryBin_Encrypt ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_Extract ; Description ...: Extract a binary bin file to a specified folder/path. ; Syntax ........: _BinaryBin_Extract(ByRef $aBinaryBin[, $sDestination = @ScriptDir[, $iIndex = -1]]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sDestination - [optional] Destination filepath to extract the files to. Default is @ScriptDir. ; $iIndex - [optional] Index number of the file to extract. Default is -1 all contents. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_Extract(ByRef $aBinaryBin, $sDestination = @ScriptDir, $iIndex = -1) Local $bReturn = False If __BinaryBin_IsBinaryBin($aBinaryBin) Then If $iIndex = Default Then $iIndex = -1 EndIf Local $aArray = __BinaryBin_Process($aBinaryBin[$BINARYBIN_HWND]) Local $iCount = $iIndex $sDestination = __BinaryBin_GetDirectoryFormat($sDestination, True) If $iIndex <= 0 Or $iIndex > $aArray[0][0] Then $iCount = 1 $iIndex = $aArray[0][0] EndIf Local $hFileOpen = 0 $bReturn = $aArray[0][0] > 0 If $bReturn Then For $i = $iCount To $iIndex DirCreate($sDestination & '\' & $aArray[$i][2]) $hFileOpen = FileOpen($sDestination & '\' & $aArray[$i][2] & $aArray[$i][1], BitOR($FO_APPEND, $FO_BINARY)) If $hFileOpen = -1 Then ContinueLoop EndIf FileWrite($hFileOpen, Binary($aArray[$i][0])) FileClose($hFileOpen) Next EndIf EndIf Return $bReturn EndFunc ;==>_BinaryBin_Extract ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetFileCount ; Description ...: Retrieve the file count in a binary bin file. ; Syntax ........: _BinaryBin_GetFileCount(ByRef $aBinaryBin) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; Return values .: Success - File count. ; Failure - 0 sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetFileCount(ByRef $aBinaryBin) Local $iError = $BINARYBIN_ERROR_NONE, $iReturn = 0 If __BinaryBin_IsBinaryBin($aBinaryBin) Then Local Const $sData = __BinaryBin_FileRead($aBinaryBin[$BINARYBIN_HWND]) Local Const $aSRE = StringRegExp($sData, '<filename>([^<]*)</filename>', $STR_REGEXPARRAYGLOBALMATCH) If @error Then $iError = $BINARYBIN_ERROR_INVALIDFILENAME Else $iReturn = UBound($aSRE) EndIf Else $iError = $BINARYBIN_ERROR_INVALIDBIN EndIf Return SetError($iError, 0, $iReturn) EndFunc ;==>_BinaryBin_GetFileCount ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetFolders ; Description ...: Retrieve the list of files in a binary bin file. ; Syntax ........: _BinaryBin_GetFolders(ByRef $aBinaryBin[, $sDestination = @ScriptDir]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; Return values .: Success - An array containing a list of files. ; Failure - Empty array & sets @error to non-zero. ; Author ........: guinness ; Remarks........: The array returned is one-dimensional and is made up as follows: ; $aArray[0] = Number of files ; $aArray[1] = 1st file ; $aArray[2] = 2nd file ; $aArray[3] = 3rd File ; $aArray[n] = nth file ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetFiles(ByRef $aBinaryBin) Local $aError[0], $aReturn = 0, _ $iError = $BINARYBIN_ERROR_NONE If __BinaryBin_IsBinaryBin($aBinaryBin) Then Local $sData = __BinaryBin_FileRead($aBinaryBin[$BINARYBIN_HWND]) $aReturn = StringRegExp('<filename>GetBinFilesCount</filename>' & @CRLF & $sData, '<filename>([^<]*)</filename>', $STR_REGEXPARRAYGLOBALMATCH) If @error Then $aReturn = $aError $iError = $BINARYBIN_ERROR_INVALIDFILENAME Else $aReturn[0] = UBound($aReturn, 1) - 1 EndIf Else $aReturn = $aError $iError = $BINARYBIN_ERROR_INVALIDBIN EndIf Return SetError($iError, 0, $aReturn) EndFunc ;==>_BinaryBin_GetFiles ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetFolders ; Description ...: Retrieve the list of folders in a binary bin file. ; Syntax ........: _BinaryBin_GetFolders(ByRef $aBinaryBin[, $sDestination = @ScriptDir]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $sDestination - [optional] Destination filepath to extract the folders to. Default is @ScriptDir. ; Return values .: Success - An array containing a list of folders. ; Failure - Empty array & sets @error to non-zero. ; Author ........: guinness ; Remarks........: The array returned is one-dimensional and is made up as follows: ; $aArray[0] = Number of folders ; $aArray[1] = 1st folder ; $aArray[2] = 2nd folder ; $aArray[3] = 3rd folder ; $aArray[n] = nth folder ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetFolders(ByRef $aBinaryBin, $sDestination = @ScriptDir) Local $aError[0], $aReturn = 0, _ $iError = $BINARYBIN_ERROR_NONE If __BinaryBin_IsBinaryBin($aBinaryBin) Then If $sDestination = Default Then $sDestination = @ScriptDir EndIf Local $sData = __BinaryBin_FileRead($aBinaryBin[$BINARYBIN_HWND]) $sDestination = __BinaryBin_GetDirectoryFormat($sDestination, False) $aReturn = StringRegExp('<folder>GetBinFoldersCount</folder>' & @CRLF & $sData, '<folder>([^<]*)</folder>', $STR_REGEXPARRAYGLOBALMATCH) If @error Then $aReturn = $aError $iError = $BINARYBIN_ERROR_INVALIDFOLDER Else $aReturn[0] = UBound($aReturn, 1) - 1 Local Const $sSOH = Chr(01) Local $sReturn = '' For $i = 1 To $aReturn[0] If Not StringInStr($sSOH & $sReturn, $sSOH & $sDestination & '\' & $aReturn[$i] & $sSOH, $STR_NOCASESENSEBASIC) Then $sReturn &= $sDestination & '\' & $aReturn[$i] & $sSOH EndIf Next $aReturn = StringSplit(StringTrimRight($sReturn, StringLen($sSOH)), $sSOH) If @error Then $aReturn = $aError $iError = $BINARYBIN_ERROR_INVALIDFOLDER EndIf EndIf Else $aReturn = $aError $iError = $BINARYBIN_ERROR_INVALIDBIN EndIf Return SetError($iError, 0, $aReturn) EndFunc ;==>_BinaryBin_GetFolders ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetSize ; Description ...: Retrieve the filesize of a BinaryBin file. ; Syntax ........: _BinaryBin_GetSize(ByRef $aBinaryBin[, $bFormatted = False]) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; $bFormatted - [optional] Return as a user friendly output e.g. 1000 bytes >> 1 KB. Default is False. ; Return values .: Success - Filesize ; Failure - 0 ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetSize(ByRef $aBinaryBin, $bFormatted = False) Local $iSize = 0 If __BinaryBin_IsBinaryBin($aBinaryBin) Then $iSize = _WinAPI_GetFileSizeEx($aBinaryBin[$BINARYBIN_HWND]) EndIf Return ($bFormatted ? __BinaryBin_ByteSuffix($iSize, 2) : $iSize) EndFunc ;==>_BinaryBin_GetSize ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetFileName ; Description ...: Rerieve the filename of a handle returned by _BinaryBin. ; Syntax ........: _BinaryBin_GetFileName(ByRef $aBinaryBin) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; Return values .: Success - Filename ; Failure - Null ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetFileName(ByRef $aBinaryBin) Return __BinaryBin_IsBinaryBin($aBinaryBin) ? $aBinaryBin[$BINARYBIN_FILENAME] : Null EndFunc ;==>_BinaryBin_GetFileName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_GetFilePath ; Description ...: Rerieve the filepath of a handle returned by _BinaryBin. ; Syntax ........: _BinaryBin_GetFilePath(ByRef $aBinaryBin) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; Return values .: Success - Filepath ; Failure - Null ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_GetFilePath(ByRef $aBinaryBin) Return __BinaryBin_IsBinaryBin($aBinaryBin) ? $aBinaryBin[$BINARYBIN_FILEPATH] : Null EndFunc ;==>_BinaryBin_GetFilePath ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryBin_IsEncrypted ; Description ...: Check if a binary bin file is encrypted. ; Syntax ........: _BinaryBin_IsEncrypted(ByRef $aBinaryBin) ; Parameters ....: $aBinaryBin - [in/out and const] Handle created by _BinaryBin. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _BinaryBin_IsEncrypted(ByRef $aBinaryBin) Return __BinaryBin_IsBinaryBin($aBinaryBin) ? __BinaryBin_IsEncrypted($aBinaryBin) : Null EndFunc ;==>_BinaryBin_IsEncrypted ; #INTERNAL_USE_ONLY#============================================================================================================ Func __BinaryBin_AddData(ByRef $aBinaryBin, $sFilePath, $bWrite, $bOverwrite, $sFolder) Local $sData = '' If __BinaryBin_IsBinaryBin($aBinaryBin) Then Local $hFileOpen = FileOpen($sFilePath, $FO_BINARY) If $hFileOpen = -1 Then Return SetError($BINARYBIN_ERROR_FATAL, 0, $sData) EndIf $sData = '<data>' & Binary(FileRead($hFileOpen)) & '</data>' & _ '<filename>' & __BinaryBin_GetFileName($sFilePath) & '</filename>' & _ '<folder>' & $sFolder & '</folder>' & @CRLF FileClose($hFileOpen) If $bWrite Then __BinaryBin_FileWrite($aBinaryBin[$BINARYBIN_HWND], $sData, $bOverwrite) If @error Then $sData = '' Return SetError($BINARYBIN_ERROR_FATAL, 0, $sData) EndIf EndIf EndIf Return $sData EndFunc ;==>__BinaryBin_AddData Func __BinaryBin_ByteSuffix($iBytes, $iRound) Local $aArray = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], _ $iIndex = 0 While $iBytes > 1023 $iIndex += 1 $iBytes /= 1024 WEnd Return Round($iBytes, $iRound) & ' ' & $aArray[$iIndex] EndFunc ;==>__BinaryBin_ByteSuffix Func __BinaryBin_FileRead($hFilePath) Local $iFileSize = (_WinAPI_GetFileSizeEx($hFilePath) + 1), _ $sText = '' Local $tBuffer = DllStructCreate('byte array[' & $iFileSize & ']') _WinAPI_SetFilePointer($hFilePath, 0) _WinAPI_ReadFile($hFilePath, DllStructGetPtr($tBuffer), $iFileSize, $sText) Return SetError(@error, 0, BinaryToString(DllStructGetData($tBuffer, 'array'))) EndFunc ;==>__BinaryBin_FileRead Func __BinaryBin_FileWrite($hFilePath, ByRef $sText, $bOverwrite) If $bOverwrite Then _WinAPI_SetFilePointer($hFilePath, $FILE_BEGIN) _WinAPI_SetEndOfFile($hFilePath) EndIf Local $iFileSize = _WinAPI_GetFileSizeEx($hFilePath), $iLength = StringLen($sText), $iWritten = 0 Local $tBuffer = DllStructCreate('byte array[' & $iLength & ']') DllStructSetData($tBuffer, 'array', $sText) _WinAPI_SetFilePointer($hFilePath, $iFileSize) _WinAPI_WriteFile($hFilePath, DllStructGetPtr($tBuffer), $iLength, $iWritten) Return SetError(@error, @extended, $iWritten) EndFunc ;==>__BinaryBin_FileWrite Func __BinaryBin_GetDirectoryFormat($sFolder, $bCreate) $sFolder = StringRegExpReplace($sFolder, '[\\/]+$', '') ; Strip the last backslash. If $bCreate And Not FileExists($sFolder) Then DirCreate($sFolder) EndIf Return $sFolder EndFunc ;==>__BinaryBin_GetDirectoryFormat Func __BinaryBin_GetFileName($sFilePath) Return StringRegExpReplace($sFilePath, '^.+[\\/]', '') ; Thanks to Malkey. EndFunc ;==>__BinaryBin_GetFileName Func __BinaryBin_IsBinaryBin(ByRef $aBinaryBin) Return UBound($aBinaryBin) = $BINARYBIN_MAX And $aBinaryBin[$BINARYBIN_ID] = $BINARYBIN_GUID EndFunc ;==>__BinaryBin_IsBinaryBin Func __BinaryBin_IsEncrypted(ByRef $aBinaryBin) Return Not StringInStr(__BinaryBin_FileRead($aBinaryBin[$BINARYBIN_HWND]), 'data') EndFunc ;==>__BinaryBin_IsEncrypted Func __BinaryBin_Process($hFilePath) Local Const $iColumns = 3 Local $sData = __BinaryBin_FileRead($hFilePath) Local $aArray = StringRegExp($sData, '<data>(0x[[:xdigit:]]+)</data><filename>([^<]*)</filename><folder>([^<]*)</folder>', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Local $aError[1][$iColumns] = [[0, $iColumns]] Return SetError($BINARYBIN_ERROR_INVALIDBIN, 0, $aError) EndIf Local $iColumn = 0, $iIndex = 0, $iUbound = UBound($aArray, 1) Local $aReturn[($iUbound / $iColumns) + 1][$iColumns] = [[0, $iColumns]] For $i = 0 To $iUbound - 1 Step $iColumns $iColumn = 0 $iIndex += $iColumns $aReturn[0][0] += 1 For $j = $i To $iIndex - 1 $aReturn[$aReturn[0][0]][$iColumn] = $aArray[$j] $iColumn += 1 Next Next Return $aReturn EndFunc ;==>__BinaryBin_Process Example 1: #include '_BinaryBin.au3' Example() Func Example() ; Open the BinaryBin.bin file and erase previous contents. Local $hBinFile = _BinaryBin(@ScriptDir & '\BinaryBin.bin', True) Local $sFolder = FileSelectFolder('_BinaryBin Folder to add to the BinaryBin.bin file.', '') If @error Then Return False ; Return if no folder was selected. ; Add a Folder to the BinaryBin.bin file. _BinaryBin_AddFolder($hBinFile, $sFolder, False) ; Check the files added to the BinaryBin.bin file and display in _ArrayDisplay(). Local $aArray = _BinaryBin_GetFiles($hBinFile) _ArrayDisplay($aArray, '_BinaryBin File Names') ; Check the folders added to the BinaryBin.bin file and display in _ArrayDisplay(). $aArray = _BinaryBin_GetFolders($hBinFile, @ScriptDir & '\Export') _ArrayDisplay($aArray, '_BinaryBin Folders') ; Retrieve the number of files before encrypting. Local $iFileCount = _BinaryBin_GetFileCount($hBinFile) ; Encrypt the BinaryBin.bin file with the password - Password. _BinaryBin_Encrypt($hBinFile, 'Password') Local $sData = '_BinaryBin FileSize: ' & _BinaryBin_GetSize($hBinFile, 1) & @CRLF ; Display additional details about the BinaryBin.bin file. $sData &= '_BinaryBin File Count: ' & $iFileCount & @CRLF $sData &= '_BinaryBin is Encrypted: ' & _BinaryBin_IsEncrypted($hBinFile) & @CRLF $sData &= '_BinaryBin FilePath: ' & _BinaryBin_GetFilePath($hBinFile) & @CRLF MsgBox($MB_SYSTEMMODAL, '_BinaryBin Data', $sData) ; Decrypt the BinaryBin.bin file with the password - Password. _BinaryBin_Decrypt($hBinFile, 'Password') ; Close the BinaryBin.bin handle. _BinaryBin_Close($hBinFile) EndFunc ;==>Example Example 2: #include '_BinaryBin.au3' Example() Func Example() ; Open the BinaryBin.bin file and don't erase previous contents. Local $hBinFile = _BinaryBin(@ScriptDir & '\BinaryBin.bin', False) ; Decrypt the BinaryBin.bin file with the password - Password. _BinaryBin_Decrypt($hBinFile, 'Password') MsgBox($MB_SYSTEMMODAL, '_BinaryBin Extraction', 'Extracting the BinaryBin.bin to ' & @ScriptDir & '\Export results in the return value of: ' & @CRLF & _ 'Return: ' & _BinaryBin_Extract($hBinFile, @ScriptDir & '\Export')) ; Close the BinaryBin.bin handle. _BinaryBin_Close($hBinFile) EndFunc ;==>Example All of the above has been included in a ZIP file. BinaryBin.zipPrevious download 330+ Warning: This is ideal for moderately small files, anything in the excess of 100 MB's is probably best to look elsewhere e.g. 7-Zip1 point
-
AutoITJavaAccess.dll
guestscripter reacted to CiVQ for a topic
Hello. If you are still interested: http://www.mediafire.com/download/j7blzrjj6gn5ebh/AutoITJavaAccess.zip Best regards. civ.1 point -
ConsoleWrite(ATan(1)*4) This ways pretty simple... and it will give you pi as good as the implementation is in the language.1 point
-
Calculate Pi
mLipok reacted to jvanegmond for a topic
This was fun to write, although it doesn't show how to calculate Pi in more places.. MsgBox(0, "This is a demonstration of calculating Pi", "Actual Pi: 3.1415926535897932384626433832795" & @CRLF & @CRLF & "Arjan: "& Pi() & @CRLF & "Gregory: " & Gregory() & @CRLF & "Newton: " & Newton() & @CRLF & "Manadar: " & Manadar() & @CRLF & "Wallis: " & Wallis()) Func Pi($calc = 100000) Local $b = 0 For $a = 1 To $calc $b += 1/($a*$a) Next Return Sqrt($b*6) EndFunc Func Wallis() ;methos is faulty from 20 and up ;requires integral calculation... I'm clueless?!? Starting on integral calculation in a month at school ^o) ;http://www.escape.com/~paulg53/math/pi/wallis/index.html Local $numerator = 1 Local $dividor = 1 For $x = 1 to 61 If $x/2 = Int($x/2) Then $numerator *= $x * $x Else $dividor *= $x * $x EndIf ;MsgBox(0, "Faulty from 20", $numerator & @CRLF & "---------------------------------" & @CRLF & $dividor) Next Return ($numerator/$dividor)*2 EndFunc Func Gregory() ;Leibniz and Machin ;http://www.escape.com/~paulg53/math/pi/greg/index.html Local $pi = 4*ATan(1/5)-ATan(1/239) Return $pi*4 EndFunc Func Newton() ;http://www.escape.com/~paulg53/math/pi/newton/index.html $a = Sqrt(3)/23 $b = Sqrt(3)/32 $c = $a + $b $d = 24 * $c Return $d EndFunc Func Manadar() ; lol, this is totally random! I want Apple3.14159265358 Return Sin(0.5)*6.5 EndFunc A lot more stuff on Pi that i have to try! http://www.escape.com/~paulg53/math/pi/links.html1 point