Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/26/2012 in all areas

  1. Update 2/2/12: v2.0.7 Fix _RegRead returns string data for _RegExport. Update 1/30/12: v2.0.6 - SCRIPT BREAKING Change _RegRead treatment of REG_MULTI_SZ data. Data is returned in a comparable format to AutoIt's native RegRead function: CRLF delimited substrings. (AutoIt's RegRead actually returns LF delimited substrings.) Update 1/29/12: v2.0.5 Added more supported formats to the Export function and fixed infinite loop errors. REG_LINK remains unsupported. v2.0.4 Fixed some REG_MULTI_SZ issues in Write/Copy/Move functions. Re-read the _RegWrite header notes for the pertinent information. Thanks again step887 for reporting. Update 1/28/12: v2.0.3 Do not use RegDeleteKeyEx on 32-bit OS's, it is not needed (and does not exist on XP 32-bit and lower, or lower than Server 2003 SP1). Thanks step887 for reporting the error! Update 12/2/10: v2.0.2 Fixed wrong @error return from _RegRead which would cause _RegValueExists to incorrectly return Success. Update 5/25/10: Ok, huge overhaul. Added: - Function documentation! - Improved _RegRead and _RegWrite to better handle data. Specifically, REG_MULTI_SZ data types are correctly read / exported if the data was incorrectly written to the registry by another application. And the data is correctly written even if it was supplied to the function with incorrect termination. Because of the unusual format of this data type, it is returned from _RegRead as binary data. - _RegRead / _RegWrite support all known registry value data types (in at a least a limited way). For uncommon types, the values are read / written as binary data. - Better error checking and reporting, especially before any delete operations. - x64 Platform: Support for directly reading the 32-bit and 64-bit registry views from both 32-bit and 64-bit scripts. - All operations are now done via custom registry functions. I didn't want to go all the way, but AutoIt doesn't support a root key like HKLM32 to force reading the 32-bit registry on the x64 platform from a native 64-bit script. Once I decided to introduce that capability in some of the higher level functions, I had to rewrite all the low level functions as well. - _RegExport function to recursively export a key or a single value to a MS compatible REG file. - Other undocumented helper functions that could be pilfered for nefarious usage. There might be some more minor things that I've forgotten. I've tested this pretty well, but please report any bugs or problems. Update 4/16/2010: Added the latest version of this UDF. It includes some custom _RegWrite / _RegRead functions as well. The _RegWrite function allows you to set the REG_OPTION_VOLATILE flag on a registry key. Example at the bottom. I needed this for a script, and didn't necessarily like big_daddy's solution. Here's a recursive registry copy/move function. I tested it and it seems to work perfectly (knock on wood). It could probably use some more error catching, so suggestions are welcome. _RegFunc.au3
    1 point
  2. For MBR it seems to works so #include <WinAPI.au3> $_PARTITION_INFORMATION_MBR = 'byte PartitionType;' & _ 'byte BootIndicator;' & _ 'byte RecognizedPartition;' & _ 'dword HiddenSectors;' $_PARTITION_INFORMATION_GPT = 'byte TypeGuid[16];' & _ 'byte IDGuid[16];' & _ 'int64 Attributes;' & _ 'wchar Name[36];' $_PARTITION_INFORMATION_EX = 'int PartitionStyle;' & _ 'int64 StartingOffset;' & _ 'int64 PartitionLength;' & _ 'dword PartitionNumber;' & _ 'byte RewritePartition;' & _ 'byte pad[3];' & _ $_PARTITION_INFORMATION_MBR & _ $_PARTITION_INFORMATION_GPT $_PARTITION_INFORMATION_EX_2 = 'int PartitionStyle;' & _ 'int64 StartingOffset;' & _ 'int64 PartitionLength;' & _ 'dword PartitionNumber;' & _ 'byte RewritePartition;' & _ 'byte pad[3];' & _ $_PARTITION_INFORMATION_GPT $DRIVE_LAYOUT_INFORMATION_MBR = 'ULONG Signature;' $DRIVE_LAYOUT_INFORMATION_GPT = 'byte Guid[16];' & _ 'int64 StartingUsableOffset;' & _ 'int64 UsableLength;' & _ 'ulong MaxPartitionCount;' $_DRIVE_LAYOUT = DllStructCreate('dword PartitionStyle;' & _ 'dword PartitionCount;' & _ 'byte union[40];' & _ 'byte PartitionEntry[8192]') $hDrive = _WinAPI_CreateFile('.PHYSICALDRIVE0', 2, 0) local $Ret = DllCall("kernel32.dll", "int", "DeviceIoControl", _ "hwnd", $hDrive, _ "dword", 0x00070050, _ "ptr", 0, _ "dword", 0, _ "ptr", DllStructGetPtr($_DRIVE_LAYOUT), _ "dword", DllStructGetSize($_DRIVE_LAYOUT), _ "dword*", 0, _ "ptr", 0) Switch DllStructGetData($_DRIVE_LAYOUT, "PartitionStyle") Case 0 ;MBR $data = DllStructGetData($_DRIVE_LAYOUT, "union") $binaryStruct = DllStructCreate('byte[8192]') DllStructSetData($binaryStruct, 1, $data) $DriveMBRInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_MBR , DllStructGetPtr($binaryStruct)) ConsoleWrite('MBR Signature: ' & Hex(DllStructGetData($DriveMBRInfo, "Signature"), 8) & @CRLF & @CRLF) $PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount") $PartitionEntry = 'byte[144];' For $x = 2 To $PartitionCount $PartitionEntry &= 'byte[144];' Next $PartitionEntry &= 'byte[8192]' $data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry") $binaryStruct = DllStructCreate('byte[8192]') DllStructSetData($binaryStruct, 1, $data) $PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct)) For $x = 1 To $PartitionCount $Partion = DllStructCreate($_PARTITION_INFORMATION_EX, DllStructGetPtr($PartitionEntry, $x)) IF Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF) ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF) ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF) ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion,'PartitionLength') & @CRLF) ConsoleWrite('RecognizedPartition: ' & DllStructGetData($Partion, 'RecognizedPartition') & @CRLF) ConsoleWrite('PartitionType: ' & DllStructGetData($Partion, 'PartitionType') & @CRLF) ConsoleWrite('BootIndicator: ' & DllStructGetData($Partion, 'BootIndicator') & @CRLF) ConsoleWrite('HiddenSectors: ' & DllStructGetData($Partion, 'HiddenSectors') & @CRLF & @CRLF) Next Case 1 ;GPT ;GPT stuff here ... $data = DllStructGetData($_DRIVE_LAYOUT, "union") $binaryStruct = DllStructCreate('byte[8192]') DllStructSetData($binaryStruct, 1, $data) $DriveGPTInfo = DllStructCreate($DRIVE_LAYOUT_INFORMATION_GPT , DllStructGetPtr($binaryStruct)) ConsoleWrite('Guid: ' & _BeautyGUID(DllStructGetData($DriveGPTInfo, "Guid")) & @CRLF & @CRLF) ConsoleWrite('StartingUsableOffset: ' & Int(DllStructGetData($DriveGPTInfo, "StartingUsableOffset")) & @CRLF) ConsoleWrite('UsableLength: ' & Int(DllStructGetData($DriveGPTInfo, "UsableLength")) & @CRLF) ConsoleWrite('MaxPartitionCount: ' & Int(DllStructGetData($DriveGPTInfo, "MaxPartitionCount")) & @CRLF & @CRLF) $PartitionCount = DllStructGetData($_DRIVE_LAYOUT, "PartitionCount") $PartitionEntry = 'byte[144];' For $x = 2 To $PartitionCount $PartitionEntry &= 'byte[144];' Next $PartitionEntry &= 'byte[8192]' $data = DllStructGetData($_DRIVE_LAYOUT, "PartitionEntry") $binaryStruct = DllStructCreate('byte[8192]') DllStructSetData($binaryStruct, 1, $data) $PartitionEntry = DllStructCreate($PartitionEntry, DllStructGetPtr($binaryStruct)) For $x = 1 To $PartitionCount $Partion = DllStructCreate($_PARTITION_INFORMATION_EX_2, DllStructGetPtr($PartitionEntry, $x)) IF Not DllStructGetData($Partion, 'PartitionNumber') Then ContinueLoop ConsoleWrite('Name: ' & DllStructGetData($Partion, 'Name') & @CRLF) ConsoleWrite('PartitionNumber: ' & DllStructGetData($Partion, 'PartitionNumber') & @CRLF) ConsoleWrite('PartitionStyle: ' & DllStructGetData($Partion, 'PartitionStyle') & @CRLF) ConsoleWrite('StartingOffset: ' & DllStructGetData($Partion, 'StartingOffset') & @CRLF) ConsoleWrite('PartitionLength: ' & DllStructGetData($Partion,'PartitionLength') & @CRLF) ConsoleWrite('TypeGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'TypeGuid')) & @CRLF) ConsoleWrite('IDGuid: ' & _BeautyGUID(DllStructGetData($Partion, 'IDGuid')) & @CRLF) ConsoleWrite('Attributes: ' & Int(DllStructGetData($Partion, 'Attributes')) & @CRLF & @CRLF) Next Case 2 ; RAW ConsoleWrite('RAW Disk - no information available' & @CRLF) EndSwitch Func _BeautyGUID($GUID) $GUID = StringLower($GUID) IF StringLeft($GUID, 2) = '0x' Then $GUID = StringTrimLeft($GUID, 2) Return '{' & StringLeft($GUID, 8) & '-' & StringMid($GUID, 9, 4) & '-' & StringMid($GUID, 13, 4) & '-' & StringMid($GUID, 17, 4) & '-' & StringRight($GUID, 8) & '}' EndFunc Edit: added GPT now also works Edit2: runs with limited user privileges, Thanks Kafu
    1 point
  3. This is awesome. Is there any documentation on what the commands mean? Also are there any simplified examples to follow? Cheers
    1 point
×
×
  • Create New...