HELP! - Calling Windows Scripting Host from C# to Create Shortcuts

  • Thread starter Thread starter G$
  • Start date Start date
G

G$

I'm trying to write some C# code to call the Windows Scripting Host (WSH) to
create shortcuts, but I'm having problems.

First, I referenced Windows Script Host Object Model. Then, I wrote the
code:

IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
// Neither one of the next two lines work
string sAllUsersDesktop =
shell.SpecialFolders.Item("AllUsersDesktop").ToString();
string sAllUsersDesktop = shell.SpecialFolders("AllUsersDesktop");

All I'm trying to do is get the AllUsersDesktop special folder, but the code
above won't even compile. I get the following errors:

The best overloaded method match for
'IWshRuntimeLibrary.IWshCollection.Item(ref object)' has some invalid
arguments
Argument '1': cannot convert from 'string' to 'ref object'
'IWshRuntimeLibrary.IWshShell3.SpecialFolders' denotes a 'property' where a
'method' was expected


What am I doing wrong with the WSH code?

Or, is there a better way of creating shortcuts in C# code (they'll need to
be created to AllUsersDesktop or AllUsersStartMenu)?

Thanks.
 
I'm trying to write some C# code to call the Windows Scripting
Host (WSH) to create shortcuts, but I'm having problems.

First, I referenced Windows Script Host Object Model. Then, I
wrote the code:

IWshRuntimeLibrary.WshShell shell = new
IWshRuntimeLibrary.WshShell(); // Neither one of the next two
lines work string sAllUsersDesktop =
shell.SpecialFolders.Item("AllUsersDesktop").ToString();
string sAllUsersDesktop =
shell.SpecialFolders("AllUsersDesktop");

All I'm trying to do is get the AllUsersDesktop special folder,
but the code above won't even compile. I get the following
errors:

The best overloaded method match for
'IWshRuntimeLibrary.IWshCollection.Item(ref object)' has some
invalid arguments
Argument '1': cannot convert from 'string' to 'ref object'
'IWshRuntimeLibrary.IWshShell3.SpecialFolders' denotes a
'property' where a 'method' was expected


What am I doing wrong with the WSH code?

Or, is there a better way of creating shortcuts in C# code
(they'll need to be created to AllUsersDesktop or
AllUsersStartMenu)?


A C# example:

http://www.vbaccelerator.com/home/NET/Code/Libraries/Shell_Projects/C
reating_and_Modifying_Shortcuts/article.asp

or

http://tinyurl.com/3rztd



A VB.Net example:
http://www.developerfusion.com/show/245/
 
Back
Top