AutoHotkey Community

It is currently May 25th, 2012, 2:52 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: converting reg into ahk
PostPosted: June 23rd, 2007, 2:00 pm 
Offline

Joined: May 24th, 2006, 7:08 pm
Posts: 66
Location: New Mumbai, India
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2007, 7:19 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8657
Location: Salem, MA
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.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 23rd, 2007, 7:46 pm 
Offline

Joined: May 24th, 2006, 7:08 pm
Posts: 66
Location: New Mumbai, India
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 9:15 am 
Offline

Joined: May 24th, 2006, 7:08 pm
Posts: 66
Location: New Mumbai, India
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 9:52 am 
Offline

Joined: May 24th, 2007, 3:45 am
Posts: 1121
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 3:33 pm 
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?


Report this post
Top
  
Reply with quote  
PostPosted: August 15th, 2007, 9:01 am 
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! :-)


Report this post
Top
  
Reply with quote  
 Post subject: Forgot to mention...
PostPosted: August 15th, 2007, 9:05 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2007, 10:11 am 
Offline

Joined: May 24th, 2006, 7:08 pm
Posts: 66
Location: New Mumbai, India
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 15th, 2007, 2:54 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8657
Location: Salem, MA
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.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 16th, 2007, 5:06 pm 
Offline

Joined: July 23rd, 2004, 7:38 am
Posts: 15
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! :-) 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;}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 20th, 2007, 1:18 pm 
Offline

Joined: July 23rd, 2004, 7:38 am
Posts: 15
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

_________________
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;}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 16th, 2008, 11:40 am 
Offline

Joined: October 16th, 2008, 11:36 am
Posts: 7
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject: new link to the file
PostPosted: October 16th, 2008, 7:33 pm 
Offline

Joined: July 23rd, 2004, 7:38 am
Posts: 15
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;}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: new link to the file
PostPosted: October 17th, 2008, 12:37 pm 
Offline

Joined: October 16th, 2008, 11:36 am
Posts: 7
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 :) 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 ;) )


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, sarevok9, Wicked, Yahoo [Bot] and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group