How to set "always open by this program" - vb.net

i want my program to ask user "Do u want to set .mp3 file type always default open by this program?" (for first time only) any example to do this?

First, you will need to familiarize yourself with the Windows Registry.
Associations between programs and extensions are handled inside the HKEY_CLASSES_ROOT key.
Each extension appears as a sub-key.
As each key's default value you will find the associated key that handles most of the operations, currently supported, for that particular file type.
For example, you might find the .mp3's default value is set to "WMP11.AssocFile.MP3" or perhaps it set to "VLC.mp3", if you have installed VLC and configured it as the default MP3 player.
So, now you need to locate that key, again, inside HKEY_CLASSES_ROOT.
Although this may vary, you should find that "VLC.mp3" (or whatever key was associated with the .mp3 extension) has a sub-key called "shell".
Under "shell" you will find another sub-key called "Open".
And, finally, under "Open" you will another sub-key called "Command".
The "Command" key is the one containing the information used by Windows (and other programs) to open/start whatever application is currently associated with the ".mp3" (or any other) extension.
Once you understand and feel comfortable with the way associations are handled in the Registry, you should then use .NET's Microsoft.Win32's Registry class to navigate and query the required keys and their values.
Here's a very basic illustration of how the code would look like:
Dim mp3 = Registry.ClassesRoot.OpenSubKey(".mp3")
Dim associatedValue = mp3.GetValue("")
Dim associatedKey = Registry.ClassesRoot.OpenSubKey(associatedValue)
Dim defaultProgram = associatedKey.OpenSubKey("Shell\Open\Command").GetValue("")
MsgBox("MP3 Files Are Opened Using: " + vbCrLf + defaultProgram)
Hope this helps...

You need to set file associations. See this article on Code Project on setting File Associations in VB.NET.

An error shows up again after importing and declaring it like
Dim rgText As Registry.ClassesRoot.OpenSubKey(".txt")
and the error looks like this:
Type 'Registry.ClassesRoot.OpenSubKey' is not defined.

Related

Synchronize modification between SWT table and TextEditor

I'm facing a problem and want to ask for a solution.
I'm working on an eclipse plugin project, in which an editor for a type of resource file is required. The resource file has similar structure like CSV file. My idea is to provide user the option to edit this type of file both in plain text format and also in an SWT table. Plain text is required for examining data and table provides more flexibility to editing such as sorting by column.
I have been able to create a MultiPageEditorPart, with one page of org.eclipse.ui.editors.text.TextEditor, and another page with a org.eclipse.swt.widgets.Table and several other widgets like search bar. The content of the resource file can be shown in the TextEditor, can also be edited and saved. On the other hand, the content can be loaded in the table too, sorting and searching all work good.
The problem is: when I edit a cell in the table, I want the change also reflected in the TextEditor, and vice versa. Since the resource file can be very large, I want the saving action happen only on the TextEditor, i.e. I don't want any modification in the table directly stored to resource file, but to mark the file dirty, but I can't figure out how. How can I for example get the content of EditorInput, check it line by line, and modify it outside TextEditor?
Or, are there more efficient ways to do this? Can anyone give any hints?
The IDocument used by the TextEditor gives you access to the document contents. Get this with something like:
IDocumentProvider provider = editor.getDocumentProvider();
IEditorInput input = editor.getEditorInput();
IDocument document = provider.getDocument(input);
IDocument has many methods for accessing lines such as:
int getLineOffset(int line);
int getLineLength(int line);
and methods for modify the text:
void replace(int offset, int length, String text);

How to modify {userinfoserial} via Pascal?

If I want to modify {userinfoserial} variable at the end of installation (user inputs only part of the serial during the installation process).
How can I modify {userinfoserial} through Pascal?
I do not want to create new variable, but modify existing.
I have tried several ways, but with no luck - unfortunately WizardUserInfoSerial is unknown identifier where WizardDirValue is OK what is strange to me...
If that is not possible, then I will create new variable.

How do I retrieve editors registered for a certain file extension in Eclipse?

I have two editors registered for one file extension and a file with that extension is opened in one of the editors. I now want to open this file programatically in the other editor as well, but without having to know its id. Is it possible to retrieve a list of editors that are registered for one file extension or is there a better way to do it?
You use the editor registry to do this. Get the registry with:
IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry();
The registry has a number of methods for finding editors, for example:
IEditorDescriptor [] desc = registry.getEditors("file name");
returns the editors that will work on a file name. There are also methods to get the default editor and editors associated with file content types.
The IEditorDescriptor contains the editor id which you can pass to open of the openEditor methods of IWorkbenchPage.
Update:
If you want to open the same file in two editors at the same time you will have to use the version of the IWorkbenchPage openEditor call which has the 'match flags' option:
public IEditorPart openEditor(final IEditorInput input,
final String editorId, final boolean activate, final int matchFlags)
Specify IWorkbenchPage.MATCH_NONE as the matchFlags to stop the search for an existing open editor.

WiX: How to create file name from a property value

I have a working WiX installer that correctly writes properties to certain INI files, which works fine, but I have a need to generate the name of an INI file on the fly, from the computer name, eg.
MACHINE(xxx).INI
where xxx is my computer name.
I have tried all sorts of combinations of properties and I just can't seem to get it working. Can anyone put me right ?
This is my latest attempt that doesn't work:
<Property Id="MACHINEINI" Value="MACHINE([%COMPUTERNAME]).ini" />
...
<IniFile Id="IniPermissions"
Directory="MYDIR"
Action="addLine"
Name="[MACHINEINI]"
Section="[ComputerName]"
Key="Permissions"
Value="TEST" />
I never see the value of MACHINEINI, as the filename that gets created is actually called
[MACHINEINI]
The value it writes in is correct, so I see the contents as follows:
[xxx] Permissions=TEST
(where xxx is my machine name)
I have tried using [ComputerName], [COMPUTERNAME], [%COMPUTERNAME]
When I build the installer, I get the following error:
C:\Source\blah\BLAH.wxs(50) : warning CNDL1077 : The 'MACHINEINI' Pro
perty contains '[COMPUTERNAME]' in its value which is an illegal
reference to an other property. If this value is a string literal,
not a property reference, pl ease ignore this warning. To set a
property with the value of another property, use a CustomAction with
Property and Value attributes.
The underlying Windows Installer table doesn't support this. Note that the FileName column is of type FileName. Only the Formatted type can take a [PROPERTY].
IniFile Table
You could need a custom action to write temporary records to the IniFile table to transform the file name. The advantage versus using a custom action to literally write the INI file is that rollback would be automatically handled for you.
It's not possible to tell you how to do this exactly since I don't know what language you'd want to use to write the custom action.
A simpler approach (from the installers perspective) would be to transform the [KEY] name inside a single INI instead of writing to different INI files.

Adding registry keys via .reg file

I have a small problem that I'm sure has a simple solution, although its only simple when you know how.
Using Windows8, I want to register my COM dll. I'm doing this via a .reg file. The problem comes with adding the InprocServer32 entry. For some reason the value that will point to my .dll file doesn't actually get added into the registry. The InprocServer32 key gets added but not the value.
I have this entry within the .reg file...
[HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{15C9923A-7847-4249-95C5-E521D8D614C9}\InprocServer32]
#="D:\COMTest\TestIObject.dll"
"ThreadingModel" = "Both"
There are several other entries that get added correctly, just not the 'value' of the InprocServer32. The ThreadingModel key and value are added as expected. Is the 'InprocServer32' key value protected against being added/changed in Windows8? If so what would be the correct solution?
You need to escape the backslash characters in the path:
#="D:\\COMTest\\TestIObject.dll"