Hello again.
I have another problem =).
I need to change the 1.lnk "pointing" path, i can get it with the following code :

string path = @"c:\1.lnk";
            FileInfo fi = new FileInfo(@path);
            if (fi.FullName.EndsWith("lnk"))
            {
                IWshShell shell = new WshShell();
                var lnk = shell.CreateShortcut(fi.FullName) as IWshShortcut;
                if (lnk != null)
                {
                    textBox1.Text = lnk.FullName;
                }
            }

But when i try to do the next :

IWshShell shell = new WshShell();
                    FileInfo fi = new FileInfo(@fixme);
                    var lnk = shell.CreateShortcut(fi.FullName) as IWshShortcut;
                    lnk.FullName = "c:\1.exe";

The compiler gives me the next error : Property or indexer 'IWshRuntimeLibrary.IWshShortcut.FullName' cannot be assigned to -- it is read only .
So how can i write to it ?
Thanks in advance.

Recommended Answers

All 5 Replies

If you want to change file name you need to use the

System.IO.File

class, like this:

System.IO.File.Move(@"c:\1.lnk", @"c:\1.exe");

That is if you want to change and delete the old one, and if you want to keep both of the files use:

System.IO.File.Copy(@"c:\1.lnk", @"c:\1.exe", false);

The last parm that you send to the method ("false") it to not overwrite en old file, you can change it to true if you want to overwrite the old file!

Enjoy!

I dont want to rename the file or copy it ,i want to change one of the properties of an .lnk file(windows shortcut format) . And the propertie is named FullName .

Yea i understood that, but you cant change this property as it read only, so you need to move or copy the file and then use it with the new name..!

Ok. Than gonna try searching on how to create a .lnk file . Thanks for the response any other ideia is wellcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.