Leaderboard
Popular Content
Showing content with the highest reputation on 02/02/2015 in all areas
-
LAST VERSION - 1.0 02-Feb-15 This UDF allows to use API Virtual Hard Disk (VHD) in AutoIt scripts. VHD format is a publicly-available image format specification that specifies a virtual hard disk encapsulated in a single file, capable of hosting native file systems while supporting standard disk and file operations. VHD is supported on Windows 7 and Windows Server 2008 R2. WinAPIVhd UDF written for AutoIt 3.3.6.x or later, however, if you are using AutiIt 3.3.12.x, you can integrate this library into AutoIt package (see below). The library contains a detailed help file (WinAPIVhd.chm) in AutoIt style, syntax highlighting and calltips files for SciTE (required full version), and full examples. I hope that many users will find this library useful. Moreover, I created two icons for the file types .vhd (Virtual Hard Disk) and .vhdx (Hyper-V Virtual Hard Disk) which you can use for yourself. You can also download more document icons in the same style for AutoIt, Restorator, etc. To associate icons with the required file types, you can use my simple utility >File Types Manager. Installation (optionaly) If you are using AutiIt 3.3.12.0 or later, you can integrate WinAPIVhd UDF library into AutoIt package. This will add the calltips and syntax highlighting for new functions, and provide a simpler way to include the library in your scripts. To integrate WinAPIVhd UDF library into AutoIt, you should do the following steps. Before to do anything, you should make sure that the WinAPIVhd UDF library is not included in the AutoIt package. For more information, see the help file (WinAPIVhd.chm) within the archive. Сopy APIVhdConstants.au3 and WinAPIVhd.au3 to AutoIt3Include.Сopy Examples*.au3 to AutoIt3ExamplesHelpFile.Сopy SciTE*.* to AutoIt3SciTE (only if the full version of SciTE is installed).Сopy HelpWinAPIVhd.chm to AutoIt3.Open AutoIt3IncludeAPIConstants.au3 in SciTE and add the line #include "APIVhdConstants.au3" to the end of list.Open AutoIt3IncludeWinAPIEx.au3 in SciTE and add the line #include "WinAPIVhd.au3" to the end of list. Available functions WinAPIVhd UDF Library v1.0 Previous downloads: 17 WinAPIVhd.zip Example #Include <APIConstants.au3> #Include <GUIConstantsEx.au3> #Include <EditConstants.au3> #Include <WinAPIEx.au3> #Include <APIVhdConstants.au3> #Include <WinAPIVhd.au3> Opt('MustDeclareVars', 1) Opt('TrayAutoPause', 0) Global $hForm, $hVHD = 0, $Edit, $Button[3], $Path, $Size = 128 * 1024 * 1024 If _WinAPI_GetVersion() < '6.1' Then MsgBox(16, 'Error', 'Require Windows 7 or later.') Exit EndIf $hForm = GUICreate('VHD API Example', 460, 302) $Edit = GUICtrlCreateEdit('', 13, 13, 434, 238, $ES_READONLY) GUICtrlSetFont(-1, 9, 400, 0, 'Courier New') GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetColor(-1, 0x404040) $Button[0] = GUICtrlCreateButton('Create VHD', 12, 263, 140, 27) $Button[1] = GUICtrlCreateButton('Open VHD', 160, 263, 140, 27) $Button[2] = GUICtrlCreateButton('Close VHD', 308, 263, 140, 27) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE If $hVHD Then _VHD_Close() EndIf Exit Case $Button[0] $Path = FileSaveDialog('Create VHD', @ScriptDir, 'Virtual Hard Disk (*.vhd)|All Files (*.*)', 2 + 16, 'Test.vhd', $hForm) If $Path Then If FileExists($Path) Then FileDelete($Path) EndIf Else ContinueLoop EndIf GUICtrlSetData($Edit, '') If Not _VHD_Create($Path, $Size) Then If FileExists($Path) Then FileDelete($Path) EndIf ContinueLoop EndIf For $i = 0 To 1 GUiCtrlSetState($Button[$i], $GUI_DISABLE) Next GUiCtrlSetState($Button[2], $GUI_ENABLE) Case $Button[1] $Path = FileOpenDialog('Open VHD', @ScriptDir, 'Virtual Hard Disk (*.vhd)|All Files (*.*)', 1 + 2, '', $hForm) If $Path Then Else ContinueLoop EndIf GUICtrlSetData($Edit, '') If Not _VHD_Open($Path) Then ContinueLoop EndIf For $i = 0 To 1 GUiCtrlSetState($Button[$i], $GUI_DISABLE) Next GUiCtrlSetState($Button[2], $GUI_ENABLE) Case $Button[2] _VHD_Close() GUiCtrlSetState($Button[2], $GUI_DISABLE) For $i = 0 To 1 GUiCtrlSetState($Button[$i], $GUI_ENABLE) Next EndSwitch WEnd Func _P2L($sDisk) Local $aData, $aList, $iDisk, $iTime, $sMask = '' $iDisk = StringReplace($sDisk, '\\.\PHYSICALDRIVE', '') If Not StringIsDigit($iDisk) Then Return $sDisk EndIf $iDisk = Number($iDisk) $iTime = TimerInit() While TimerDiff($iTime) < 5000 $aList = DriveGetDrive('FIXED') If IsArray($aList) Then For $i = 1 To $aList[0] If Not StringInStr($sMask, $aList[$i]) Then $aData =_WinAPI_GetDriveNumber($aList[$i]) If (IsArray($aData)) And ($aData[1] = $iDisk) Then Return StringUpper($aList[$i]) EndIf EndIf $sMask&= $aList[$i] Next EndIf Sleep(10) WEnd Return $sDisk EndFunc ;==>_P2L Func _Log($sEvent, $iError = -1) Switch $iError Case -1 $sEvent &= @CRLF Case 0 $sEvent &= ': OK' & @CRLF Case Else $sEvent &= ': FAIL (' & $iError & ')' & @CRLF EndSwitch GUICtrlSendMsg($Edit, $EM_SETSEL, 32767, 32767) GUICtrlSetData($Edit, $sEvent, 1) EndFunc ;==>_Log Func _VHD_Close() Local $sDisk = _P2L(_WinAPI_GetVirtualDiskPhysicalPath($hVHD)) _WinAPI_DetachVirtualDisk($hVHD) If @Error Then _Log('Detach', @Extended) Else _Log('Detach', 0) EndIf _WinAPI_CloseHandle($hVHD) $hVHD = 0 If $sDisk Then _Log('VHD (' & $sDisk & ') has been closed!') EndIf EndFunc ;==>_VHD_Close Func _VHD_Create($sPath, $iSize) Local $tVST, $tCVDPV1, $tGVDI, $sDisk, $Error = True _Log('Path: ' & _WinAPI_PathCompactPathEx($sPath, 60)) Do $tVST = _WinAPI_CreateVirtualStorageType($VIRTUAL_STORAGE_TYPE_DEVICE_VHD, $VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT) $tCVDPV1 = _WinAPI_CreateCreateVirtualDiskParametersV1($iSize) $hVHD = _WinAPI_CreateVirtualDisk($sPath, $tVST, $tCVDPV1, $VIRTUAL_DISK_ACCESS_ALL, $CREATE_VIRTUAL_DISK_FLAG_FULL_PHYSICAL_ALLOCATION) If @Error Then _Log('Create', @Extended) ExitLoop Else _Log('Create', 0) EndIf _WinAPI_AttachVirtualDisk($hVHD) If @Error Then _Log('Attach', @Extended) ExitLoop Else _Log('Attach', 0) EndIf $sDisk = _WinAPI_GetVirtualDiskPhysicalPath($hVHD) If @Error Then ; Nothing EndIf _VHD_Initialize($sDisk) If @Error Then _Log('Initialize', @Extended) ExitLoop Else _Log('Initialize', 0) EndIf $Error = False Until 1 If $Error Then If $hVHD Then _WinAPI_DetachVirtualDisk($hVHD) _WinAPI_CloseHandle($hVHD) EndIf $hVHD = 0 Return 0 EndIf $tGVDI = _WinAPI_GetVirtualDiskInformation($hVHD, $GET_VIRTUAL_DISK_INFO_IDENTIFIER) If Not @Error Then _Log('GUID: ' & _WinAPI_StringFromGUID(DllStructGetPtr($tGVDI, 'Identifier'))) EndIf $tGVDI = _WinAPI_GetVirtualDiskInformation($hVHD, $GET_VIRTUAL_DISK_INFO_SIZE) If Not @Error Then _Log('Size: ' & _WinAPI_StrFormatByteSize(DllStructGetData($tGVDI, 'VirtualSize'))) EndIf _Log('VHD (' & _P2L($sDisk) & ') has been successfully created and ready for use!') Return 1 EndFunc ;==>_VHD_Create Func _VHD_Initialize($sDisk) ;~ Local Const $PARTITION_ENTRY_UNUSED = 0x00 ;~ Local Const $PARTITION_EXTENDED = 0x05 ;~ Local Const $PARTITION_FAT_12 = 0x01 ;~ Local Const $PARTITION_FAT_16 = 0x04 ;~ Local Const $PARTITION_FAT_32 = 0x0B Local Const $PARTITION_IFS = 0x07 ;~ Local Const $PARTITION_LDM = 0x42 ;~ Local Const $PARTITION_NTFT = 0x80 ;~ Local Const $PARTITION_VALID_NTFT = 0xC0 Local Const $PARTITION_STYLE_MBR = 0 ;~ Local Const $PARTITION_STYLE_GPT = 1 ;~ Local Const $PARTITION_STYLE_RAW = 2 Local Const $tagDISK_GEOMETRY = 'int64 Cylinders;dword MediaType;dword TracksPerCylinder;dword SectorsPerTrack;dword BytesPerSector;' Local Const $tagCREATE_DISK_MBR = 'dword Signature;byte GPT[16];' ;~ Local Const $tagCREATE_DISK_GPT = 'byte DiskId[16];dword MaxPartitionCount' Local Const $tagCREATE_DISK = 'dword PartitionStyle;' & $tagCREATE_DISK_MBR Local Const $tagPARTITION_INFORMATION_MBR = 'byte PartitionType;boolean BootIndicator;boolean RecognizedPartition;dword HiddenSectors;byte GPT[104];' ;~ Local Const $tagPARTITION_INFORMATION_GPT = 'byte PartitionType[16];byte PartitionId[16];uint64 Attributes;wchar Name[36];' Local Const $tagPARTITION_INFORMATION_EX = 'dword PartitionStyle;int64 StartingOffset;int64 PartitionLength;dword PartitionNumber;boolean RewritePartition;byte Alignment[3];' & $tagPARTITION_INFORMATION_MBR Local Const $tagDRIVE_LAYOUT_INFORMATION_MBR = 'ulong Signature;byte GPT[36];' ;~ Local Const $tagDRIVE_LAYOUT_INFORMATION_GPT = 'byte DiskId[16];int64 StartingUsableOffset;int64 UsableLength;ulong MaxPartitionCount;' Local Const $tagDRIVE_LAYOUT_INFORMATION_EX = 'dword PartitionStyle;dword PartitionCount;' & $tagDRIVE_LAYOUT_INFORMATION_MBR & 'byte PartitionEntry[144];' Local Const $tagVERIFY_INFORMATION = 'int64 StartingOffset;dword Length' Local $hFile, $tDG, $tCD, $tDLIEX, $tPIEX, $tVI, $Error, $Extended = 0 Do $Error = 1 $hFile = _WinAPI_CreateFileEx($sDisk, $OPEN_EXISTING, BitOR($GENERIC_READ, $GENERIC_WRITE), BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_ATTRIBUTE_NORMAL) If @Error Then ExitLoop EndIf ; IOCTL_DISK_GET_DRIVE_GEOMETRY $Error = 2 $tDG = DllStructCreate($tagDISK_GEOMETRY) If Not _WinAPI_DeviceIoControl($hFile, $IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0, DllStructGetPtr($tDG), DllStructGetSize($tDG)) Then ExitLoop EndIf ; IOCTL_DISK_CREATE_DISK $Error = 3 $tCD = DllStructCreate($tagCREATE_DISK) DllStructSetData($tCD, 'PartitionStyle', $PARTITION_STYLE_MBR) DllStructSetData($tCD, 'Signature', 0xA4B57300) If Not _WinAPI_DeviceIoControl($hFile, $IOCTL_DISK_CREATE_DISK, DllStructGetPtr($tCD), DllStructGetSize($tCD)) Then ExitLoop EndIf ; IOCTL_DISK_SET_DRIVE_LAYOUT_EX $Error = 4 $tDLIEX = DllStructCreate($tagDRIVE_LAYOUT_INFORMATION_EX) DllStructSetData($tDLIEX, 'PartitionStyle', $PARTITION_STYLE_MBR) DllStructSetData($tDLIEX, 'PartitionCount', 1) DllStructSetData($tDLIEX, 'Signature', 0xA4B57300) $tPIEX = DllStructCreate($tagPARTITION_INFORMATION_EX, DllStructGetPtr($tDLIEX, 'PartitionEntry')) DllStructSetData($tPIEX, 'PartitionStyle', $PARTITION_STYLE_MBR) DllStructSetData($tPIEX, 'StartingOffset', 0) DllStructSetData($tPIEX, 'PartitionLength', DllStructGetData($tDG, 'Cylinders') * DllStructGetData($tDG, 'TracksPerCylinder') * DllStructGetData($tDG, 'SectorsPerTrack') * DllStructGetData($tDG, 'BytesPerSector')) DllStructSetData($tPIEX, 'PartitionNumber', 1) DllStructSetData($tPIEX, 'RewritePartition', 1) DllStructSetData($tPIEX, 'PartitionType', $PARTITION_IFS) DllStructSetData($tPIEX, 'BootIndicator', 0) DllStructSetData($tPIEX, 'RecognizedPartition', 1) DllStructSetData($tPIEX, 'HiddenSectors', 1) If Not _WinAPI_DeviceIoControl($hFile, $IOCTL_DISK_SET_DRIVE_LAYOUT_EX, DllStructGetPtr($tDLIEX), DllStructGetSize($tDLIEX)) Then ExitLoop EndIf ; IOCTL_DISK_VERIFY $Error = 5 $tVI = DllStructCreate($tagVERIFY_INFORMATION) DllStructSetData($tVI, 'StartingOffset', 0) DllStructSetData($tVI, 'Length', DllStructGetData($tPIEX, 'PartitionLength')) If Not _WinAPI_DeviceIoControl($hFile, $IOCTL_DISK_VERIFY, DllStructGetPtr($tVI), DllStructGetSize($tVI)) Then ExitLoop EndIf ; IOCTL_DISK_UPDATE_PROPERTIES $Error = 6 If Not _WinAPI_DeviceIoControl($hFile, $IOCTL_DISK_UPDATE_PROPERTIES) Then ExitLoop EndIf $Error = 0 Until 1 If $Error Then $Extended = _WinAPI_GetLastError() EndIf If $hFile Then _WinAPI_CloseHandle($hFile) EndIf Return SetError($Error, $Extended, Not $Error) EndFunc ;==>_VHD_Initialize Func _VHD_Open($sPath) Local $tVST, $tGVDI, $sDisk, $Error = True _Log('Path: ' & _WinAPI_PathCompactPathEx($sPath, 50)) Do $tVST = _WinAPI_CreateVirtualStorageType($VIRTUAL_STORAGE_TYPE_DEVICE_VHD, $VIRTUAL_STORAGE_TYPE_VENDOR_MICROSOFT) $hVHD = _WinAPI_OpenVirtualDisk($sPath, $tVST, 0, $VIRTUAL_DISK_ACCESS_ALL) If @Error Then _Log('Open', @Extended) ExitLoop Else _Log('Open', 0) EndIf _WinAPI_AttachVirtualDisk($hVHD) If @Error Then _Log('Attach', @Extended) ExitLoop Else _Log('Attach', 0) EndIf $Error = False Until 1 If $Error Then If $hVHD Then _WinAPI_DetachVirtualDisk($hVHD) _WinAPI_CloseHandle($hVHD) EndIf $hVHD = 0 Return 0 EndIf $tGVDI = _WinAPI_GetVirtualDiskInformation($hVHD, $GET_VIRTUAL_DISK_INFO_IDENTIFIER) If Not @Error Then _Log('GUID: ' & _WinAPI_StringFromGUID(DllStructGetPtr($tGVDI, 'Identifier'))) EndIf $tGVDI = _WinAPI_GetVirtualDiskInformation($hVHD, $GET_VIRTUAL_DISK_INFO_SIZE) If Not @Error Then _Log('Size: ' & _WinAPI_StrFormatByteSize(DllStructGetData($tGVDI, 'VirtualSize'))) EndIf $sDisk = _WinAPI_GetVirtualDiskPhysicalPath($hVHD) If Not @Error Then _Log('VHD (' & _P2L($sDisk) & ') has been successfully opened and ready for use!') EndIf Return 1 EndFunc ;==>_VHD_Open2 points
-
Question About Functions
jaberwacky and one other reacted to jvanegmond for a topic
You have to learn to think about where the responsibilities should be. Do you think a function called "Move File A to B" should also be responsible for "Prepare directory"? Or could that cause confusion to someone who is not familiar with your code? Or is that not relevant to the process of "Move File A to B"? A simple example will help. For example, we have a humanoid robot which we want to program to wave his left arm and then say "Hello!". We define the functions Main, WaveArm and SayHello. In terms of functionality, it doesn't really matter if we let Main call WaveArm and let WaveArm call SayHello. But should a function called WaveArm also be the trigger for saying "Hello!" afterwards? Or should we let Main call both WaveArm and SayHello in the order we want it to happen? If we choose to keep the responsibility of waving the arm in the method WaveArm and the responsibility of saying "Hello!" in SayHello, we can easily ask a different programmer later to change the code to make the robot say "Hello" first and then wave his arm (the reverse of what we wanted) by changing the Main. He will be done in a few seconds, rather than having to drill into the long and complicated WaveArm function which mainly deals with motor control. It therefore helps with clarity too: If we want to understand the order of the robot's actions, we don't have to drill down into the specifics of how the robot waves his arm by reading the whole WaveArm function, we just have to know that WaveArm will wave the robots arm and let other code deal with the order of the robots operations. In this way, we can create functions which are essentially abstractions of the code we write. We can stop thinking of WaveArm as a series of operations of motor control, but instead think of it as a robot waving its arm (and only that). This helps us write and maintain bigger programs without having to understand every line of code in the system. Placing correct responsibilities is a main principle in software development and is often referred to by the larger term Separation of Concerns, though I find it easier to explain and understand as thinking of placing responsibilities.2 points -
I don't know how to use zip.au3 but you can try 7za http://www.dotnetperls.com/7-zip-examples2 points
-
Chimp, This seems to do the trick: #include <Array.au3> $sText = '<TD ROWSPAN=3 BGCOLOR="#99CCFF">Sales</TD>' & @CRLF & _ '<td rowspan= " 2 ">' & @CRLF & _ '<td style="width:400px;" colspan = "5 " ...</td>' $aExtract = StringRegExp($sText, '(?i)span\s*=\s*"?\s?(\d+)', 3) _ArrayDisplay($aExtract, "", Default, 8) M23 Edit: SRE decode (sorry I did not provide one last night): (?i) - Case insensitive (because we have ~SPAN and ~span) span - Look for the word "span", \s* - possibly followed by any number of spaces, = - but certainly by "=". \s* - Then there might be some more spaces, "? - and even a '"', \s? - with another possible space. (\d+) - Finally, capture the digits that come along! 3 - Produce an array of every match found For me a Regex is indispensable here as it allows you to get around the fact that the number of spaces (and even their very existence) is completely variable.2 points
-
For an alternative similar to Autoit for Android... Try RFO Basic. http://rfobasic.com/ http://laughton.com/basic/ http://rfobasic.com/ http://laughton.com/basic/ Uses Basic syntax, Scite wit code highlight etc Code and build in windows or Android, test on Android platform. Doesn't have a lot of advanced feataures up fron, but easy to use =)2 points
-
waiting for window for to long (time out 500+?)
SorryButImaNewbie reacted to water for a topic
You could create a GUI with a "Cancel" button so the user can end your script any time. To check for the window use AdLibRegister to call a function every x seconds and use WinExists to check for the window. If the window was found, unregister the function and set a flag. In the main script you then can act on this flag and take the screenshot. Sounds a bit cryptic? If yes, I can provide an example.1 point -
What about negated types ? $word = "rowspan" $res = StringRegExp($s, '(?i)\Q' & $word & '\E\s*=\D*(\d+)', 3)1 point
-
Lots of ways to create a working expression: "(?is)(?:row|col)span\h*=\h*(?:'|"")?\h*(\d+)" (?is) = case insensitive, work through any type of new line sequence (html is famous for not working as expected without using this) (?:row|col) = non-capturing group to select rowspan or colspan h* = work through any horizontal space if it exists (?:'|")? = non-capturing group to look for a single or double quote, the "?" after is basically saying... May or may not exist (d+) = capture group (give me my digits please) .... Btw, didn't I provide a pattern in the the udf funcs I did for you with _htmlraw_* that did something like this?1 point
-
GuiBuilderNxt - Reboot [08/18/2016]
TheSaint reacted to jaberwacky for a topic
I like this. Will be in the next update! Thanks!1 point -
I found this the other day: http://regex.inginf.units.it/# It automatically creates regular expression pattern. It's not going to work every time but it might help1 point
-
Dll injection udf for 32 bits
Blue_Drache reacted to JohnOne for a topic
It will work on everything, even your watch.1 point