I wrote this using the only compiler I had handy - Borland Pascal 7! I was also rather ill so its just a quick hack really... just to get the basics down, pretty much all I need atm.
Things that *don't* work:
- almost no error checking, there are some special characters in value names and values which will probably crash or bug the AHK file
- [edit:thanx dave!] default values (ie @=xyz) not done yet, empty keys should be possible too - will add these another time
- i found out too late that strings in this old compiler can only be 255 chars, so longer strings will truncated -
- you have to use a REGEDIT4 style reg file
usage: reg2ahk.exe [regfilename] [ahkfilename]
http://home.exetel.com.au/kea/e/reg2ahk.zip
and here's the source in case the link dies:
Code:
Program Reg2AHK;
Var
CurrentRootKey : String;
CurrentSubKey : String;
Var
OneLine : String;
RegFile : Text;
AHKFile : Text;
ValueName : String;
ValueREST : String;
EndQuote : Integer;
FirstChar : String;
{-----------------------------------------------------------------}
Procedure SplitHeader(Data:String);
Var FirstSlash : Integer;
Begin
Delete(Data,1,1);
Delete(Data,Length(Data),1);
FirstSlash:=Pos('\',Data);
CurrentRootKey:=Copy(Data,1,FirstSlash-1);
CurrentSubKey:=Copy(Data,FirstSlash+1,Length(Data)-FirstSlash);
End;
{-----------------------------------------------------------------}
function hex_to_dec(h :string) :longint;
var
d,place,digit,i :longint;
begin
d := 0;
place := 1;
for i := length(h) downto 1 do
begin
digit := ord(upcase(h[i]))-48;
if digit>9 then digit := digit - (ord('A')-58);
if not digit in [0..15] then
begin
writeln('Hex conversion error, ',h,' not a hex digit');
exit;
end;
d := d + place*digit;
place := place shl 4;
end;
hex_to_dec := d;
end;
{-----------------------------------------------------------------}
Function AddEscapes(S:String):String;
Var
X,L : Integer;
Begin
L:=Length(S);
For X:=L downto 1 do
Begin
If S[X]='%' then
Insert('`',S,X)
End;
AddEscapes:=S;
End;
{-----------------------------------------------------------------}
Function RemoveDoubleSlash(S:String):String;
Begin
While Pos('\\',S)>0 do
Begin
Delete(S,Pos('\\',S),1);
End;
RemoveDoubleSlash:=S;
End;
{-----------------------------------------------------------------}
Function ConvertToStr(S:String):String;
Var
AByte : Word;
S2 : String;
Begin
S2:='';
Repeat
AByte:=Hex_to_Dec(Copy(S,1,2));
Delete(S,1,3);
S2:=S2+Chr(AByte);
Until AByte=0;
Delete(S2,Length(S2),1);
ConvertToStr:=S2;
End;
{-----------------------------------------------------------------}
Function ConvertMultiLineToStr(S:String):String;
Var
AByte : Word;
S2 : String;
Begin
S2:='';
Repeat
AByte:=Hex_to_Dec(Copy(S,1,2));
Delete(S,1,3);
If AByte=0 then
S2:=S2+'`n'
else
S2:=S2+Chr(AByte);
Until Length(S)=0;
Delete(S2,Length(S2),1);
ConvertMultiLineToStr:=S2;
End;
{-----------------------------------------------------------------}
Procedure ProcessDWORD(InValue:String);
Var
HexData : Longint;
Begin
Delete(InValue,1,6);
HexData:=Hex_to_dec(InValue);
WriteLn(AHKFile,'RegWrite, REG_DWORD, ',CurrentRootKey,', ',CurrentSubKey,', ',ValueName,', ',HexData);
End;
{-----------------------------------------------------------------}
Procedure ProcessSZ(InValue:String);
Begin
Delete(InValue,1,1);
Delete(InValue,Length(InValue),1);
InValue:=AddEscapes(InValue);
InValue:=RemoveDoubleSlash(InValue);
WriteLn(AHKFile,'RegWrite, REG_SZ, ',CurrentRootKey,', ',CurrentSubKey,', ',ValueName,', ',InValue);
End;
{-----------------------------------------------------------------}
Procedure ProcessBIN(InValue:String);
Begin
Delete(InValue,1,4);
While Pos(',', InValue) > 0 do
Delete(InValue,Pos(',',InValue),1);
WriteLn(AHKFile,'RegWrite, REG_BINARY, ',CurrentRootKey,', ',CurrentSubKey,', ',ValueName,', ',InValue);
End;
{-----------------------------------------------------------------}
Procedure ProcessEXPAND(InValue:String);
Var
AddedLine : String;
Begin
Delete(InValue,1,7);
While Copy(InValue,Length(InValue),1)='\' do
Begin
Delete(InValue,Length(InValue),1);
ReadLn(RegFile, AddedLine);
Delete(AddedLine,1,2);
InValue:=InValue+AddedLine;
End;
InValue:=ConvertToStr(InValue);
InValue:=AddEscapes(InValue);
WriteLn(AHKFile,'RegWrite, REG_EXPAND_SZ, ',CurrentRootKey,', ',CurrentSubKey,', ',ValueName,', ',InValue);
End;
{-----------------------------------------------------------------}
Procedure ProcessMULTI(InValue:String);
Var
AddedLine : String;
Begin
Delete(InValue,1,7);
While Copy(InValue,Length(InValue),1)='\' do
Begin
Delete(InValue,Length(InValue),1);
ReadLn(RegFile, AddedLine);
Delete(AddedLine,1,2);
InValue:=InValue+AddedLine;
End;
InValue:=ConvertMultiLineToStr(InValue);
InValue:=AddEscapes(InValue);
WriteLn(AHKFile,'RegWrite, REG_MULTI_SZ, ',CurrentRootKey,', ',CurrentSubKey,', ',ValueName,', ',InValue);
End;
{-----------------------------------------------------------------}
Begin
Assign(RegFile, ParamStr(1));
Reset(RegFile);
Assign(AHKFile, ParamStr(2));
Rewrite(AHKFile);
ReadLn(RegFile, OneLine);
ReadLn(RegFile, OneLine);
While Not Eof(RegFile) do
Begin
{start on a subkey}
ReadLn(RegFile, OneLine);
SplitHeader(OneLine);
{read a value}
ReadLn(RegFile, OneLine);
While OneLine<>'' do
Begin
If Copy(OneLine,1,1)='@' then
Begin
{Default value}
End;
Delete(OneLine,1,1);
EndQuote:=Pos('"',OneLine);
ValueName:=Copy(OneLine,1,EndQuote-1);
ValueREST:=Copy(OneLine,EndQuote+2,Length(OneLine)-(EndQuote+1));
FirstChar:=Copy(ValueREST,1,1);
If FirstChar='d' then
Begin
ProcessDWORD(ValueREST);
End;
If FirstChar='"' then
Begin
ProcessSZ(ValueREST);
End;
If FirstChar='h' then
Begin
If Copy(ValueRest,4,1)=':' Then
ProcessBIN(ValueREST);
If Copy(ValueRest,5,1)='2' Then
ProcessEXPAND(ValueREST);
If Copy(ValueRest,5,1)='7' Then
ProcessMULTI(ValueREST);
End;
ReadLn(RegFile, OneLine);
End;
End;
Close(RegFile);
Close(AHKFile);
End.
so for example this:
Code:
REGEDIT4
[HKEY_LOCAL_MACHINE\SOFTWARE\AAAMACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/AllocateDASD]
"ValueType"=dword:00000001
"DisplayType"=dword:00000003
"DisplayName"="Devices: Allowed to format and eject removable media"
"DisplayChoices"=hex(7):30,7c,41,64,6d,69,6e,69,73,74,72,61,74,6f,72,73,00,31,\
7c,41,64,6d,69,6e,69,73,74,72,61,74,6f,72,73,20,61,6e,64,20,50,6f,77,65,72,\
20,55,73,65,72,73,00,32,7c,41,64,6d,69,6e,69,73,74,72,61,74,6f,72,73,20,61,\
6e,64,20,49,6e,74,65,72,61,63,74,69,76,65,20,55,73,65,72,73,00,00
becomes:
Code:
RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE, SOFTWARE\AAAMACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/AllocateDASD, ValueType, 1
RegWrite, REG_DWORD, HKEY_LOCAL_MACHINE, SOFTWARE\AAAMACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/AllocateDASD, DisplayType, 3
RegWrite, REG_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\AAAMACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/AllocateDASD, DisplayName, Devices: Allowed to format and eject removable media
RegWrite, REG_MULTI_SZ, HKEY_LOCAL_MACHINE, SOFTWARE\AAAMACHINE/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/AllocateDASD, DisplayChoices, 0|Administrators`n1|Administrators and Power Users`n2|Administrators and Interactive U