News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

create delet a file association

Started by ToutEnMasm, October 12, 2011, 12:45:48 PM

Previous topic - Next topic

ToutEnMasm


Is there somewhere a proc , a function who do this ?

jj2007

Change the registry. Example: HKEY_CLASSES_ROOT\hlpfile and HKEY_CLASSES_ROOT\.hlp

ToutEnMasm


There is a little more key to create and a function will be greatly apreciated.
sample:
Quote
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.PRJ]
@="prjfile"

[HKEY_CLASSES_ROOT\.PRJ\OpenWithList]

[HKEY_CLASSES_ROOT\.PRJ\OpenWithList\editmasm.exe]
@=""

[HKEY_CLASSES_ROOT\prjfile]
@="Projet Editmasm"
"EditFlags"=dword:00000000
"BrowserFlags"=dword:00000008

[HKEY_CLASSES_ROOT\prjfile\DefaultIcon]
@="E:\\Program Files\\editmasm\\editmasm.exe,5"

[HKEY_CLASSES_ROOT\prjfile\shell]
@=""

[HKEY_CLASSES_ROOT\prjfile\shell\open]

[HKEY_CLASSES_ROOT\prjfile\shell\open\command]
@="\"E:\\Program Files\\Editmasm\\editmasm.EXE\" \"%1\""


jj2007

Changing an existing value is a one-liner:

include \masm32\MasmBasic\MasmBasic.inc
   Init
   SetRegVal "HKCR\.ASC",0, "Assembler Source Code"
   Inkey "ok"
   Exit
end start

But you want to create and set a whole range of values:
- Export the good & tested values from regedit, and
- use ShellExecute to launch the *.reg file.

You may occasionally have problems with protection - system administrators tend to protect the HKCR section of the registry.

dedndave

i know what you are looking for, Yves - an API function that you can call to create an association
other than the registry functions, it doesn't seem to exist
there is some help on MSDN...

http://msdn.microsoft.com/en-us/library/aa969371.aspx

ToutEnMasm


Here is the proc  CreateFileAsssociation who can need some modifies for special case
Quote
;pprjext = ".ext",0
;pTypeFichier = "ext blabla",0     ;view in explorer type of files
;peditmasmpath = Full path of executable file
;pnumIcon = "5",0    ;Num icon in the executable file
;I_RpcGetAssociationContext
;shlwapi.sdk AssocQueryString IShellFolder http://msdn.microsoft.com/en-us/library/bb761396(v=VS.85).aspx
;################################################################   

CreateFileAsssociation PROC uses esi edi  pprjext:DWORD, pTypeFichier:DWORD, peditmasmpath:DWORD,pnumIcon:DWORD
         Local  extfile[50]:BYTE,longextfile:DWORD,dwDisposition,Hsubkey,pshortname
         Local value:DWORD,sizevalue,phrase[MAX_PATH+3]:BYTE
         Local  retour:DWORD,Hkey
      mov retour,1
   mov longextfile,0
   mov Hkey,0
   ;------------------- erase old association ----------------------
   invoke RegOpenKeyEx,HKEY_CLASSES_ROOT,pprjext,NULL,KEY_ALL_ACCESS,addr Hkey
   .if Hkey != 0
      mov longextfile,sizeof extfile
      invoke RegQueryValueEx,Hkey,NULL,NULL,NULL,addr extfile,addr longextfile ;defautvlue prjfile      
      lea edx,extfile
      invoke RegCloseKey,Hkey      
      invoke SHDeleteKey,HKEY_CLASSES_ROOT,pprjext
      .if longextfile != 0
         invoke SHDeleteKey,HKEY_CLASSES_ROOT,addr extfile
         .if eax != ERROR_SUCCESS
            invoke RetrouveMessageErreur,SADR("SHDeleteKey failed")
         .endif
      .endif
   .endif
   ;------------------- creation-----------------------------
   ;.ext
   invoke RegCreateKeyEx,HKEY_CLASSES_ROOT,pprjext,NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hkey,addr dwDisposition
   ;.ext value    prjfile            
   mov esi,pprjext
   inc esi      ;passe .
   lea edi,extfile
   @@:
   .if byte ptr [esi] != 0
      movsb
      jmp @B
   .endif
   invoke lstrcpy,edi,SADR("file")
   ;defaut value
   invoke lstrlen,addr extfile
   mov edx,eax
   inc eax   ;add zero
   mov longextfile,eax
   ;HKEY_CLASSES_ROOT\.PRJ = prjfile
   invoke RegSetValueEx,Hkey,NULL,NULL,REG_SZ,addr extfile,longextfile
   ;.ext OpenWithList
   invoke RegCreateKeyEx,Hkey,SADR("OpenWithList"),NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hsubkey,addr dwDisposition   
   invoke RegCloseKey,Hkey
   PuPo Hkey,Hsubkey
   ;------ progname ----------------   
   mov esi,peditmasmpath
   invoke lstrlen,esi
   add esi,eax
   @@:
   .if byte ptr [esi] != "\"
      dec esi
      jmp @B
   .endif
   inc esi
   mov pshortname,esi
   ;----------- .ext OpenWithList   progname
   invoke RegCreateKeyEx,Hkey,esi,NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hsubkey,addr dwDisposition   
   invoke RegCloseKey,Hkey
   invoke RegCloseKey,Hsubkey   
   ;-----------------------------------------------------------------------------
      ;HKEY_CLASSES_ROOT\.PRJ = prjfile
   ;HKEY_CLASSES_ROOT\.PRJ\OpenWithList
   ;HKEY_CLASSES_ROOT\.PRJ\OpenWithList\editmasm.exe   
   ;-----------------------------------------------------------------------------
   ;HKEY_CLASSES_ROOT\prjfile
   invoke RegCreateKeyEx,HKEY_CLASSES_ROOT,addr extfile,NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hkey,addr dwDisposition
   ;HKEY_CLASSES_ROOT\prjfile values   
   ;--Projet editmasm -----------
   invoke lstrlen,pTypeFichier
   mov edx,eax
   inc edx
   invoke RegSetValueEx,Hkey,NULL,NULL,REG_SZ,pTypeFichier,edx    ;defaut value  Projet editmasm
   mov value,0 ;FTA_..
   invoke RegSetValueEx,Hkey,SADR("EditFlags"),NULL,REG_DWORD,addr value,4   
   mov value,8
   invoke RegSetValueEx,Hkey,SADR("BrowserFlags"),NULL,REG_DWORD,addr value,4
   ;HKEY_CLASSES_ROOT\prjfile\DefaultIcon
   invoke RegCreateKeyEx,Hkey,SADR("DefaultIcon"),NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hsubkey,addr dwDisposition   
   ;E:\Program Files\editmasm\editmasm.exe,5   ;5 numero icone
   invoke lstrcpy,addr phrase,peditmasmpath
   invoke lstrcat,addr phrase,SADR(",")
   invoke lstrcat,addr phrase,pnumIcon
   invoke lstrlen,addr phrase
   mov edx,eax
   inc edx
   invoke RegSetValueEx,Hsubkey,NULL,NULL,REG_SZ,addr phrase,edx
   invoke RegCloseKey,Hsubkey
   ;HKEY_CLASSES_ROOT\prjfile + shell\open\command
   invoke RegCreateKeyEx,Hkey,SADR("shell\open\command"),NULL,NULL,REG_OPTION_NON_VOLATILE,
               KEY_ALL_ACCESS,NULL,addr Hsubkey,addr dwDisposition
   invoke RegCloseKey,Hkey   
   PuPo Hkey,Hsubkey
   ;value command
   mov esi,peditmasmpath
   lea edi,phrase
   mov al,34
   stosb
   @@:
   .if byte ptr [esi] != 0
      movsb
      jmp @B
   .endif
   mov al,34
   stosb
   stosb
   mov al,"%"   
   stosb
   mov al,"1"
   stosb
   mov al,34
   stosb
   mov al,0
   stosb
   invoke lstrlen,addr phrase
   mov edx,eax
   inc edx
   invoke RegSetValueEx,Hkey,NULL,NULL,REG_SZ,addr phrase,edx   
   invoke RegCloseKey,Hkey   
      
   fini:
   invoke SHChangeNotify,SHCNE_ASSOCCHANGED,SHCNF_IDLIST,NULL,NULL
FindeCreateFileAsssociation:
         mov eax,retour
         ret
CreateFileAsssociation endp

mineiro

you can call the assoc command line(cmd.exe), but now I do not remember if previous versions before xp have this one.
assoc .asm=txtfile

dedndave

if you wanted to go that route, create a REG file using the INI file API functions
then shell out to REG.EXE - that's not too different from what typical installers do
the uninstall files are made at the same time - more INI file format stuff

Yves has a good plan
although, he may want to add some shell context menu stuff (HKCU)
and a UAC permissions call for vista and the HKCR stuff