Page 1 of 1

Register Shell Extension for attribute Specific Icon

Posted: Thu Oct 02, 2008 4:22 pm
by Tomi
Hello Everyone
I've hope to selected Topic name be correct. :?
I've a difficult ask, i use to tend the needed info by a simple text file but
with an extension "svs" as filename.svs . "svs" drived out from "Save Setting".

MyApplication task:
the Application do load a file and begin to process it and make a filename.svs in
adjacent to same file (processed).in again not need to process it, only read from filename.svs.

Request:
if it's possible, i want to add icon of MyApplication to any "filename.svs"s on hard.???
because as default ,windows add Unknown.ico to so files... that it's inelegant in view.
I think this work neede to the drastic programming that myself lack it certainly.
please help me, it can be useful for many people .

Tomi

Posted: Thu Oct 02, 2008 8:45 pm
by eJan
You can register new filetype using Windows Explorer > Tools > Folder Options: File Types > adding New (Button), then locate icon.
Or by using registry: open Regedit, go to: HKEY_CLASSES_ROOT\.doc
there you will see: (Default)______REG_SZ______WordPad.Document.1
next you have to locate its content type: HKEY_CLASSES_ROOT\Wordpad.Document.1
where DefaultIcon hold icon info for the .doc extension
Both keys must exist to work:
HKEY_CLASSES_ROOT\.doc
HKEY_CLASSES_ROOT\Wordpad.Document.1\DefaultIcon

Posted: Fri Oct 03, 2008 9:01 am
by Tomi
Hello
Your first way was true as thorough. but it need to provide a help
that per user do it himself, it is a little misrepresent. if was automatic is better than.

Your Sec way was false by me, maybe don't know it as thorough.
I think this way is thing i need it to automatic register icon with specific file extension.
I'm following Secth method and please to everybody put here your suggestions.
Very Thankful Mr eJan.

Edit:
Mean it i can make a new sub as .svs (same as .doc)and define locate of myApp?? :?:

Posted: Fri Oct 03, 2008 1:33 pm
by Tomi
Oh i take confused, i try several model registry chage,but result is false,
help me please men. :roll: :roll: :roll:

Posted: Fri Oct 03, 2008 9:10 pm
by eJan
This is registry script (.reg) when creating new file type (.svs). In this case icon for .svs extension is used from same program which opens it "C:\PB App"
Registry script (.reg):

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.svs]
@="svs_auto_file"

[HKEY_CLASSES_ROOT\svs_auto_file]
@=""

[HKEY_CLASSES_ROOT\svs_auto_file\shell]

[HKEY_CLASSES_ROOT\svs_auto_file\shell\open]

[HKEY_CLASSES_ROOT\svs_auto_file\shell\open\command]
@="\"C:\\PB App.exe\" \"%1\""

[HKEY_CURRENT_USER\Software\Classes\Applications\PB App.exe]

[HKEY_CURRENT_USER\Software\Classes\Applications\PB App.exe\shell]

[HKEY_CURRENT_USER\Software\Classes\Applications\PB App.exe\shell\open]

[HKEY_CURRENT_USER\Software\Classes\Applications\PB App.exe\shell\open\command]
@="\"C:\\PB App.exe\" \"%1\""
"C:\\PB App.exe\" should be changed to path and name of your file (same as this one \\). Compile it with icon.
Or in simple way:
1. Compile PB App.exe with icon on Desktop
2. Create New Text Document, change its extension to .cvs
3. Click New Text Document.svs properties, set it to opens with compiled PB exe on Deskop (Browse)
Now open Regedit and jump to (to see what have been created in Registry):
HKEY_CLASSES_ROOT\.svs
HKEY_CLASSES_ROOT\svs_auto_file
HKEY_CURRENT_USER\Software\Classes\Applications\PB App.exe

Posted: Fri Oct 03, 2008 9:15 pm
by Inf0Byt3
I've always used this to associate files:

Code: Select all


;Registry stuff found on the forum

#SHCNE_ASSOCCHANGED = $08000000
#SHCNF_IDLIST = $0

Procedure RegConvertRegKeyToTopKey(Key.s)
 
  topKey.s=StringField(Key,1,"\")
  topKey=UCase(topKey)
 
  Select topKey
   
    Case "HKEY_CLASSES_ROOT"
      retour=#HKEY_CLASSES_ROOT
     
    Case "HKEY_CURRENT_USER"
      retour=#HKEY_CURRENT_USER
     
    Case "HKEY_LOCAL_MACHINE"
      retour=#HKEY_LOCAL_MACHINE
     
    Case "HKEY_USERS"
      retour=#HKEY_USERS
     
    Case "HKEY_CURRENT_CONFIG"
      retour=#HKEY_CURRENT_CONFIG
     
  EndSelect
 
  ProcedureReturn retour
 
EndProcedure

Procedure.s RegConvertRegKeyToKeyName(Key.s)
  PositionSlash=FindString(Key,"\",1)
  retour.s=Right(Key,(Len(Key)-PositionSlash))
  ProcedureReturn retour
EndProcedure

Procedure.s RegListSubKey(Key.s, Index, ComputerName.s)

  topKey=RegConvertRegKeyToTopKey(Key)
  KeyName.s=RegConvertRegKeyToKeyName(Key)
 
  lpName.s
  lpftLastWriteTime.FILETIME
 
  If Left(KeyName, 1) = "\"
    KeyName = Right(KeyName, Len(KeyName) - 1)
  EndIf
 
  If ComputerName = "."
    GetHandle = RegOpenKeyEx_(topKey, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
  Else
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
  EndIf
 
  If GetHandle = #ERROR_SUCCESS
    lpcbName = 255
    lpName = Space(255)
   
    GetHandle = RegEnumKeyEx_(hKey, Index, @lpName, @lpcbName, 0, 0, 0, @lpftLastWriteTime)
   
    If GetHandle = #ERROR_SUCCESS
      ListSubKey.s = Left(lpName, lpcbName)
    Else
      ListSubKey.s = ""
    EndIf
  EndIf
  RegCloseKey_(hKey)
  ProcedureReturn ListSubKey
EndProcedure

Procedure.l RegDeleteKey(Key.s, ComputerName.s) 

  topKey=RegConvertRegKeyToTopKey(Key)
  KeyName.s=RegConvertRegKeyToKeyName(Key)
 
  If Left(KeyName, 1) = "\"
    KeyName = Right(KeyName, Len(KeyName) - 1)
  EndIf
 
  If ComputerName = "."
    GetHandle = RegDeleteKey_(topKey, @KeyName)
  Else
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
    GetHandle = RegDeleteKey_(lhRemoteRegistry, @KeyName)
  EndIf
 
  If GetHandle = #ERROR_SUCCESS
    DeleteKey = #True
  Else
    DeleteKey = #False
  EndIf
  ProcedureReturn DeleteKey
EndProcedure

Procedure.l RegDeleteKeyWithAllSubInternal(Key.s,ComputerName.s)
 
  topKey=RegConvertRegKeyToTopKey(Key)
  KeyName.s=RegConvertRegKeyToKeyName(Key)
 
  i=0
  a$=""
  Repeat
    b$=a$
    a$=RegListSubKey(Key,0,"")
    If a$<>""
      RegDeleteKeyWithAllSubInternal(Key+"\"+a$,"")
    EndIf
  Until a$=b$
  RegDeleteKey(Key, ComputerName)
EndProcedure

Procedure.l RegKeyExists(Key.s, ComputerName.s) 
 
  topKey=RegConvertRegKeyToTopKey(Key)
  KeyName.s=RegConvertRegKeyToKeyName(Key)
 
  If Left(KeyName, 1) = "\"
    KeyName = Right(KeyName, Len(KeyName) - 1)
  EndIf
 
  If ComputerName = "."
    GetHandle = RegOpenKeyEx_(topKey, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
  Else
    lReturnCode = RegConnectRegistry_(ComputerName, topKey, @lhRemoteRegistry)
    GetHandle = RegOpenKeyEx_(lhRemoteRegistry, KeyName, 0, #KEY_ALL_ACCESS, @hKey)
  EndIf
 
  If GetHandle = #ERROR_SUCCESS
    KeyExists = #True
  Else
    KeyExists = #False
  EndIf
  ProcedureReturn KeyExists
EndProcedure

Procedure.l RegDeleteKeyWithAllSub(Key.s,ComputerName.s)
 
  retour1 = RegKeyExists(Key.s,ComputerName.s)
  retour2+ RegDeleteKeyWithAllSubInternal(Key,ComputerName)
 
  If retour1=1 And  retour2=0 : retour=1 : EndIf
 
  ProcedureReturn retour
EndProcedure

Procedure.l SetKey(fold,Key$,Subkey$,Type,Adr,len)
  If RegCreateKeyEx_(fold, Key$, 0, 0, #REG_OPTION_NON_VOLATILE, #KEY_ALL_ACCESS, 0, @NewKey, @KeyInfo) = #ERROR_SUCCESS
    RegSetValueEx_(NewKey, Subkey$, 0, Type,  Adr, len)
    RegCloseKey_(NewKey)
  EndIf
EndProcedure

;Assoc stuff

Procedure.l AssociateFileEx(ext$,ext_description$,programm$,Icon$,prgkey$,cmd_description$,cmd_key$)
  cmd$=Chr(34)+programm$+Chr(34)+" "+Chr(34)+"%1"+Chr(34)
  If GetVersion_() & $ff0000  ; Windows NT/XP
    SetKey(#HKEY_CLASSES_ROOT, "Applications\"+prgkey$+"\shell\"+cmd_description$+"\command","",#REG_SZ,@cmd$,Len(cmd$)+1)
    If ext_description$
      Key$=ext$+"_auto_file"
      SetKey(#HKEY_CLASSES_ROOT,"."+ext$,"",#REG_SZ,@Key$,Len(Key$)+1)
      SetKey(#HKEY_CLASSES_ROOT,Key$,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
      If Icon$
        SetKey(#HKEY_CLASSES_ROOT,Key$+"\DefaultIcon","",#REG_SZ,@Icon$,Len(Icon$)+1)
   
      EndIf
    EndIf
    SetKey(#HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"Application",#REG_SZ,@prgkey$,Len(prgkey$)+1)
  Else ;Windows 9x
    SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\."+ext$,"",#REG_SZ,@prgkey$,Len(prgkey$)+1)
    If ext_description$
      SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$,"",#REG_SZ,@ext_description$,Len(ext_description$)+1)
    EndIf
    If Icon$
      SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\DefaultIcon","",#REG_SZ,@Icon$,Len(Icon$)+1)
    EndIf
    If cmd_description$<>cmd_key$
      SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$,"",#REG_SZ,@cmd_description$,Len(cmd_description$)+1)
    EndIf
    SetKey(#HKEY_LOCAL_MACHINE,"Software\Classes\"+prgkey$+"\shell\"+cmd_key$+"\command","",#REG_SZ,@cmd$,Len(cmd$)+1)
  EndIf
EndProcedure

Procedure.l AssociateFile(ext$,ext_description$,programm$,Icon$)
  AssociateFileEx(ext$,ext_description$,programm$,Icon$,GetFilePart(programm$),"open","open") 
EndProcedure

Procedure.l RemoveAssociateFile(ext$,prgkey$)
 If ext$ <> "" And prgkey$ <> ""
  If GetVersion_() & $ff0000 ; Windows NT/XP
    RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\Applications\"+prgkey$,"")
    Key$=ext$+"_auto_file"
    RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\."+ext$,"")
    RegDeleteKeyWithAllSub("HKEY_CLASSES_ROOT\"+Key$,"")
    RegDeleteKeyWithAllSub("HKEY_CURRENT_USER\"+"Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\."+ext$,"")
  Else ;Windows 9x
    RegDeleteKeyWithAllSub("HKEY_LOCAL_MACHINE\"+"Software\Classes\."+ext$,"")
    RegDeleteKeyWithAllSub("HKEY_LOCAL_MACHINE\"+"Software\Classes\"+prgkey$,"")
  EndIf
 EndIf
EndProcedure

Procedure.l AssociationsRefresh()
 
 ProcedureReturn SHChangeNotify_(#SHCNE_ASSOCCHANGED, #SHCNF_IDLIST, 0, 0)

EndProcedure

;little Example
;AssociateFile("pb","Pure Basic Source","C:\Programme\PureBasic\PureBasic.exe","F:\icon.bmp,0")
;and now an addition context-item
;AssociateFileEx("pb","","F:\alternate rich\jaPBe.exe","","PureBasic.exe","Open with jaPBe","open_with_japbe") 

Posted: Sat Oct 04, 2008 6:40 am
by Tomi
Very Very thanksful :) :) :)
The Both methods is cool really, There work nice on xp. :)
I will try on Vista and say the result . :)
Thanks men :)