AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

converting reg into ahk
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
geeneeyes



Joined: 24 May 2006
Posts: 66
Location: New Mumbai, India

PostPosted: Sat Jun 23, 2007 1:00 pm    Post subject: converting reg into ahk Reply with quote

I cant seem to reproduce the below code into ahk
especially the last line: which has no value is not possible to write in ahk
Is there any way to parse .reg files and convert them to ahk code?
Code:
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}]
"InfoTip"="Commands"
"NeverShowExt"=""
@="command prompt date-time"

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\DefaultIcon]
@="E:\\Windows\\System32\\2180\\pag\\0.nfo"

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell]

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\Open]
@="Command Prompt"

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\Open\Command]
@="cmd"

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\01]
@="Change date"
"SuppressionPolicy"=dword:4000003c

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\01\Command]
@="cmd /k date"

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\ShellFolder]
"Attributes"=hex:00,00,00,00

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\02]
@="Change time"
"SuppressionPolicy"=dword:4000003c

[HKEY_CLASSES_ROOT\CLSID\{00000000-5003-0000-0000-000000000002}\Shell\02\Command]
@="cmd /k time"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{00000000-5003-0000-0000-000000000002}]

_________________
irc://irc.freenode.net/ahk
Opera: SpeedDial, Email, Extensions, Widgets, Unite, UserJS, Notes, Contacts, IRC, BitTorrent, Download Manager, Tab Stacking, Thumbnails, Sessions, VoiceControl, Mouse Gestures, Content/Flash Blocker, Opera Link, Turbo mode
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Sat Jun 23, 2007 6:19 pm    Post subject: Reply with quote

you want to make a script that inserts these keys into the registry? There are two ways - convert it to RegWrite, or put the file exactly like you posted into a variable, write it to a temp .reg file, the have ahk run it, and allow the merge.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
geeneeyes



Joined: 24 May 2006
Posts: 66
Location: New Mumbai, India

PostPosted: Sat Jun 23, 2007 6:46 pm    Post subject: Reply with quote

I tried regwrite but I think it has some shortcomings like it cant create a subkey without any default value or any value

the reg file creates a shortcut icon on the desktop with some right-click options but the same thing when performed with ahk produces a null value error.

Code:
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002},, EzeeTray
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}, InfoTip, EzeeTray
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}, NeverShowExt

RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\DefaultIcon,, E:\WINDOWS\system32\2180\pag\0.nfo ;%AppPath%\0.nfo
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\01,, Show
RegWrite, REG_DWORD, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\01, SuppressionPolicy, 4000003c ; possible mismatch here with D_WORD value data
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\01\Command,, %A_ScriptFullPath% 1

RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\02,, Hide
RegWrite, REG_DWORD, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\02, SuppressionPolicy, 4000003c ; again
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\02\Command,, "%A_ScriptFullPath%" 2 ; error here? maybe quotes need to be included.

RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\Open,, Run
RegWrite, REG_SZ, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\Shell\Open\Command,, %A_ScriptFullPath%

RegWrite, REG_BINARY, HKCR, CLSID\{00000000-5003-0000-0000-000000000002}\ShellFolder, Attributes, 00000000
RegWrite, REG_SZ, HKLM, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{00000000-5003-0000-0000-000000000002} ; this subkey has no values
Return

_________________
irc://irc.freenode.net/ahk
Opera: SpeedDial, Email, Extensions, Widgets, Unite, UserJS, Notes, Contacts, IRC, BitTorrent, Download Manager, Tab Stacking, Thumbnails, Sessions, VoiceControl, Mouse Gestures, Content/Flash Blocker, Opera Link, Turbo mode
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
geeneeyes



Joined: 24 May 2006
Posts: 66
Location: New Mumbai, India

PostPosted: Wed Jul 04, 2007 8:15 am    Post subject: Reply with quote

bump

issue still pending... really needs to be resolved

please advice
_________________
irc://irc.freenode.net/ahk
Opera: SpeedDial, Email, Extensions, Widgets, Unite, UserJS, Notes, Contacts, IRC, BitTorrent, Download Manager, Tab Stacking, Thumbnails, Sessions, VoiceControl, Mouse Gestures, Content/Flash Blocker, Opera Link, Turbo mode
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
ManaUser



Joined: 24 May 2007
Posts: 1121

PostPosted: Wed Jul 04, 2007 8:52 am    Post subject: Reply with quote

Why isn't the option of creating .reg file temporarily and running it exceptable? It realize it's not super slick, but it gets the job done.
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Wed Jul 04, 2007 2:33 pm    Post subject: Reply with quote

GeeNeeYes wrote:
especially the last line: which has no value is not possible to write in ahk
Are you sure? If you omit ValueName & Value, you should be close, no?
Back to top
REGTester
Guest





PostPosted: Wed Aug 15, 2007 8:01 am    Post subject: REG file --> AHK file converter Reply with quote

Before I reinvent the wheel, I thought I'd check here.

Has anyone written a REG file to AHK file converter? I have a repeating need to update the registry directly using scripts (ie not spawning regedit to import a REG file). I can manually convert the REG files into RegWrite lines of code, but was thinking of writing a script to automate the process.

Anyone know about this? If not, time for a night or two of scripting for me! Smile
Back to top
REGTester
Guest





PostPosted: Wed Aug 15, 2007 8:05 am    Post subject: Forgot to mention... Reply with quote

ManaUser: the reason "running" the REG file is not acceptable is that regedit / regedt32 is blocked for security from "basic" users, but updating most areas of the registry works via scripts. Besides, it makes for a neater, all-in-one-exe portable solution.
Back to top
geeneeyes



Joined: 24 May 2006
Posts: 66
Location: New Mumbai, India

PostPosted: Wed Aug 15, 2007 9:11 am    Post subject: Reply with quote

hi
I would like more inputs on this too.
_________________
irc://irc.freenode.net/ahk
Opera: SpeedDial, Email, Extensions, Widgets, Unite, UserJS, Notes, Contacts, IRC, BitTorrent, Download Manager, Tab Stacking, Thumbnails, Sessions, VoiceControl, Mouse Gestures, Content/Flash Blocker, Opera Link, Turbo mode
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Wed Aug 15, 2007 1:54 pm    Post subject: Reply with quote

registry files are just ini files. there is a script somewhere on the forum that reads ini files with unknown section titles with iniread, or you can just manually parse the file. If you can hang on a few hours (while I get ready for, and drive to work), I can write a quick parsing script later. It will basically just be a loop, read with a few lines inside to make the ahk file.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
Yek-Toho-Tua



Joined: 23 Jul 2004
Posts: 15

PostPosted: Thu Aug 16, 2007 4:06 pm    Post subject: Reply with quote

engunneer wrote:
registry files are just ini files. there is a script somewhere on the forum that reads ini files with unknown section titles with iniread, or you can just manually parse the file. If you can hang on a few hours (while I get ready for, and drive to work), I can write a quick parsing script later. It will basically just be a loop, read with a few lines inside to make the ahk file.


hi again (it's REGTester here - i didn't have my login before!)
Thats pretty much exactly what i was thinking, a script that parses the file and for each type of regkey (eg REG_SZ, REG_BINARY etc) does the relevent change to make it turn into a RegWrite line.

I think you're underestimating the "few lines" of code needed to handle all the variations of registry keys, what with the double // in paths, removing commas in BINARY, hex to dec conversions for hex values etc! Smile but then again, it's been a loooong time since I did any parsing scripts so maybe its easier than i think....?

even if you post the basics here, it'd be cool to have the frame work and then I'd add code to handle any "rarer" style REG files (like keys that delete values or subkeys etc).
_________________
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
Back to top
View user's profile Send private message Visit poster's website
Yek-Toho-Tua



Joined: 23 Jul 2004
Posts: 15

PostPosted: Mon Aug 20, 2007 12:18 pm    Post subject: Reply with quote

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 - Sad
- 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

_________________
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
Back to top
View user's profile Send private message Visit poster's website
nicosc



Joined: 16 Oct 2008
Posts: 7

PostPosted: Thu Oct 16, 2008 10:40 am    Post subject: Reply with quote

Hi, I have exact the same problem, i need to convert standard .reg file (NT4 or win2k+ format) to .AHK

is the above file still available somewhere to download? or does anybody still have it? i cannot compile the pascal source here..

thanx in advance
Back to top
View user's profile Send private message
Yek-Toho-Tua



Joined: 23 Jul 2004
Posts: 15

PostPosted: Thu Oct 16, 2008 6:33 pm    Post subject: new link to the file Reply with quote

here ya go nicosc.

http://www.yourfilelink.com/get.php?fid=472341

exactly same code etc - i never did get round to making this work better!
_________________
float o=0.075,h=1.5,T,r,O,l,I;int _,L=80,s=3200;main(){for(;s%L||
(h-=o,T= -2),s;4 -(r=O*O)<(l=I*I)|++ _==L&&write(1,(--s%L?_<L?--_
%6:6:7)+"World! \n",1)&&(O=I=l=_=r=0,T+=o /2))O=I*2*O+h,I=l+T-r;}
Back to top
View user's profile Send private message Visit poster's website
nicosc



Joined: 16 Oct 2008
Posts: 7

PostPosted: Fri Oct 17, 2008 11:37 am    Post subject: Re: new link to the file Reply with quote

Yek-Toho-Tua wrote:
here ya go nicosc.

http://www.yourfilelink.com/get.php?fid=472341

exactly same code etc - i never did get round to making this work better!



Thank you very much Yek-Toho-Tua Smile I tried a couple of Pascal Compilers myself but couldn't compile it ( i don't have any experience with Pascal, that could be the problem Wink )
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group