Notifications
Clear all

[Closed] Creating Windows Shortcuts in project Folders

Hi Guys,

I have a little project setup tool, that builds folder structures for new projects. But we have just started dropping frames on to a different drive (network speed issues), so I have been asked to not only create these folders, but within them to place windows shortcuts to link over to the new drive.

How do I create these windows short cuts? I have used an incredibly small amount of .net stuff in max to open up explorer windows into different areas of the project, but I cannot find anything that would help create a windows shortcut.

My searches keep bringing up this “IWshRuntimeLibrary” for the windows scripting host. Can I include this as a dotnet library in some way and then access it through dotnet in maxscript? I guess the library has to be downloaded from somewhere? And then installed? Is this just a process of dropping a .dll file into a folder somewhere?

Is there another much easier way of doing this? Sorry folks, but at the moment I am completely stumped.

Advice would be hugely appreciated!

Cheers,

Rich

2 Replies

my suggestion would be to grab one of many command-line tools that can create a shortcut quite easily… or even this craziness: http://www.robvanderwoude.com/amb_shortcuts.html

However, it does seem silly that this can’t just be done straight out of .NET itself through the Windows namespace somewhere.

[the following does not contain any solution but perhaps somebody with more C# knowledge finds use in it]

I’ve only gotten as far as trying to compile a new assembly in-memory (using http://area.autodesk.com/index.php/forums/viewthread/13286/ as the basis, replacing the functions with a single function to create a shortcut, with String parameters for the file location and target location) to execute some of the sample code out there, but they all use the aforementioned IWshRuntimeLibrary. An assembly version of this can be found here and there (or created by yourself using TlbImp), but getting that assemble to load in a way that the c# code I’m trying to compile recognizes it is beyond my C# understanding so far.

Alternatively, it should be possibly to use the loaded assembly directly. But although I can create a shortcut instance …


  a = dotNet.loadAssembly "c:\\w\\IWshRuntimeLibrary.dll"
  dotNetObject:System.Reflection.Assembly
  b = a.createInstance "IWshRuntimeLibrary.WshShellClass"
  dotNetObject:IWshRuntimeLibrary.WshShellClass
  c = b.createShortcut "c:\\w\	est.lnk"
  dotNetObject:System.__ComObject
  

That instance then completely lacks the target field and the Save method… so that doesn’t seem too useful.

Thanks for looking into that! I thought I was missing something really obvious, since I thought that shortcut creation had to be incorporated somewhere!

I had a look at the link you posted:

http://www.robvanderwoude.com/amb_shortcuts.html

The batch file requires 4 inputs, the 3rd being the complete path to the programs folder. I am running XP, which means this path should be something like this (I think):

C:\Documents and Settings\Richard\Start Menu\Programs

In the example it show example of this path being something like:

c:\windows\start menu\programs, or possibly
c:\windows\profiles\xxx\start menu\programs

both of which I imagine are for older versions of Windows. Unfortunately, I must have been making some lame mistake since I could not get this to work at all The file simply failed to produce anything, but I am sure that someone with an ounce of intelligence could get it to work.

Instead I had a hunt around after your command line suggestion and found this very cool website:

http://www.xxcopy.com/xxcopy38.htm

You can just download a little exe file, and then run that through a DOSCOMMAND in max. So if I wanted to create a shortcut from my C drive to my temp folder (very random and useless example) I could simply use the command:

DOSCOMMAND “C:\XXMKLINK “C:\My Shortcut.lnk” c:\ emp”

Assuming my XXMKLINK.exe file was saved directly onto the C Drive.

It is free for personal use, but you have to email for permissions if you plan to distribute it anywhere.

Thanks for the tips Rich, much appreciated!

Cheers,

Rich