CreateShortcut fails

  • Thread starter Thread starter frederikbnielsen
  • Start date Start date
F

frederikbnielsen

Hi

Im using the following code to create a shortcut on one of out network
drives.

WshShell shell = new WshShell();
IWshShortcut link = shell.CreateShortcut(myURL) as IWshShortcut;
link.WindowStyle = 1;
link.TargetPath = TargetURI;
link.IconLocation = @"%SystemRoot%\system32\SHELL32.dll, 85";
link.Save();

It creates the link well enough, but i seem to have some kind of
problem. When the users try to open the link, it starts the "Open
with..." window. It should just open the network folder it links to.

What i need it to do is to create a link from my code on one server
and placeing the link on another.

I have been trying several things and everything is fine when i create
the link locally or from a 32 bit server. But from a 64 bit to a 32
bit (my situation) is does not work.


The strange part is if I open the properties of the link and change
the simplest of things and apply them, it works all of a sudden.


Can someone help me???
 
What language and application type is this? What version of Windows is this?
I may be wrong, but I don't think WSH (or any Active Scripting host) will
host C# scripts. It is unusual to use a COM object provided by WSH except in
a script hosted by WSH, but I don't see why it shouldn't work.

What is the value of "myURL" (hopefully a file name for the shortcut file,
and not a URL at all)? What is the value if "TargetURI"?

On Windows XP, I tested the effect of a similar VBScript hosted by WSH.

If my shortcut file name ended in .lnk, I could set the properties as you
describe and opening it did in fact open Internet Explorer with the URL I
specified. However, it is a "Shortcut" file and not an "Internet Shortcut"
file, so the properties dialog did not look right.

If my shortcut file name ended in .url, I could set only the TargetPath
property of those you describe (the other properties were not present). This
created an "Internet Shortcut" file which behaved normally.

I had hoped that the IShellLink documentation, which I presume is the
underlying interface used, would shed some light on this behaviour, but it
does not:
http://msdn2.microsoft.com/en-us/library/bb774950(VS.85).aspx

This page is about Internet Shortcuts, it also doesn't help much:
http://msdn2.microsoft.com/en-us/library/bb776784.aspx

Paul
 
Oh, I see you are talking about a "network folder"?

It seems "myURL" is not a URL, it's a file name. It seems "TargetURI" is not
a URI, its a UNC path. File names and paths are not URLs. Please be careful
with your terminology!

Anyway, an equivalent VBScript file hosted by WSH works fine for me if
"myURL" is the file name with the extension .lnk and "TargetURI" is a UNC
path (with or without a trailing backslash). In fact, setting the
IconLocation property is not needed, it already gets the right icon (so you
should remove it or face the possibility that you will get the wrong icon in
future versions of Windows).

Paul
 
Oh, I see you are talking about a "network folder"?

It seems "myURL" is not a URL, it's a file name. It seems "TargetURI" is not
a URI, its a UNC path. File names and paths are not URLs. Please be careful
with your terminology!

Anyway, an equivalent VBScript file hosted by WSH works fine for me if
"myURL" is the file name with the extension .lnk and "TargetURI" is a UNC
path (with or without a trailing backslash). In fact, setting the
IconLocation property is not needed, it already gets the right icon (so you
should remove it or face the possibility that you will get the wrong icon in
future versions of Windows).

Paul

in message









- Vis tekst i anførselstegn -


Sorry about the terminology......

The code works fine when ever my code runs on a 32 bit Windows 2003
server and creates a link on another 32 bit Windows 2003 server. But
when im using a 64 bit Windows 2003 server to create the link on a 32
bit Windows 2003 server (my situation) - it fails!

More details...

Im trying to create a lnk file on a network folder (hosted on a 32 bit
server) from a Sharepoint server (64 bit). The myURL is in fact a
filename and the URI is like "\\projectsqa.xxxxportal.com\ps
\A900063\Documents"


Im really confused
 
Is the "URI" you mention the value you are using for TargetPath? Does the
value you're using for TargetPath work if you just paste it into the address
bar on the computer that will be opening the shortcut file?

If you're using Sharepoint, it should be an HTTP URL, shouldn't it?

Also, do you want it to be a shortcut to a web page that opens in Internet
Explorer or do you want it to be a web folder like in "My Network Places"
that integrates with Windows Explorer? The latter is not an LNK file, it's a
folder with a target.lnk file inside it.

Paul

Oh, I see you are talking about a "network folder"?

It seems "myURL" is not a URL, it's a file name. It seems "TargetURI" is
not
a URI, its a UNC path. File names and paths are not URLs. Please be
careful
with your terminology!

Anyway, an equivalent VBScript file hosted by WSH works fine for me if
"myURL" is the file name with the extension .lnk and "TargetURI" is a UNC
path (with or without a trailing backslash). In fact, setting the
IconLocation property is not needed, it already gets the right icon (so
you
should remove it or face the possibility that you will get the wrong icon
in
future versions of Windows).

Paul

"Paul Baker [MVP, Windows - SDK]" <[email protected]>
wrote
in message

What language and application type is this? What version of Windows is
this? I may be wrong, but I don't think WSH (or any Active Scripting
host)
will host C# scripts. It is unusual to use a COM object provided by WSH
except in a script hosted by WSH, but I don't see why it shouldn't work.
What is the value of "myURL" (hopefully a file name for the shortcut
file,
and not a URL at all)? What is the value if "TargetURI"?
On Windows XP, I tested the effect of a similar VBScript hosted by WSH.
If my shortcut file name ended in .lnk, I could set the properties as
you
describe and opening it did in fact open Internet Explorer with the URL
I
specified. However, it is a "Shortcut" file and not an "Internet
Shortcut"
file, so the properties dialog did not look right.
If my shortcut file name ended in .url, I could set only the TargetPath
property of those you describe (the other properties were not present).
This created an "Internet Shortcut" file which behaved normally.
I had hoped that the IShellLink documentation, which I presume is the
underlying interface used, would shed some light on this behaviour, but
it
does not:
http://msdn2.microsoft.com/en-us/library/bb774950(VS.85).aspx
This page is about Internet Shortcuts, it also doesn't help much:
http://msdn2.microsoft.com/en-us/library/bb776784.aspx

- Vis tekst i anførselstegn -


Sorry about the terminology......

The code works fine when ever my code runs on a 32 bit Windows 2003
server and creates a link on another 32 bit Windows 2003 server. But
when im using a 64 bit Windows 2003 server to create the link on a 32
bit Windows 2003 server (my situation) - it fails!

More details...

Im trying to create a lnk file on a network folder (hosted on a 32 bit
server) from a Sharepoint server (64 bit). The myURL is in fact a
filename and the URI is like "\\projectsqa.xxxxportal.com\ps
\A900063\Documents"


Im really confused
 
Is the "URI" you mention the value you are using for TargetPath? Does the
value you're using for TargetPath work if you just paste it into the address
bar on the computer that will be opening the shortcut file?

If you're using Sharepoint, it should be an HTTP URL, shouldn't it?

Also, do you want it to be a shortcut to a web page that opens in Internet
Explorer or do you want it to be a web folder like in "My Network Places"
that integrates with Windows Explorer? The latter is not an LNK file, it's a
folder with a target.lnk file inside it.

Paul

Yes the value works if I just paste in to Windows Explorer (or
Internet Explorer for that matter).

Even more details....We want the user to browse to their Sharepoint
sites document library from an application (like WORD, Notepad,
AutoCad etc). The way we (thought) we had it solved was to create a
link to the documen library on a network drive. The user will then
browse to out O-drive and find their project name (the lnk file) and
click on it - this should bring them to the document library in
windows explorer.

It has to be in windows explorer so the link has to be "\
\projectsqa.xxxxportal.com\ps\A900063\Documents"



The funny thing is when I open the (non working) lnk files properties
and add a comment like "Tested" and clicks OK - it suddenly works.
Every time I make a change by hand it somehow transforms the lnk
file, and then it works.
 
This is not really the right audience for your question. It looks very
unlikely that this is caused by either C# or WSH.

Your target appears to be a UNC file name. Please try a different UNC file
name that corresponds to a simple file share and see if that works.

If you can create a shortcut to a shared folder without issue, your problem
may be with Sharepoint, and it would be best to post to
microsoft.public.sharepoint.general. I don't understand how a UNC file name
is working with Sharepoint in Windows Explorer, I thought it had to be
accessed via HTTP. But someone reading that newsgroup would know more about
that.

If you have a problem creating a shortcut to a shared folder, your problem
may be with the shell, and it would be best to post to
microsoft.public.platformsdk.shell. The 64-bit thing may be relevant, and I
imagine someone reading that newsgroup would be more familiar than me about
that too.

You will need to rephrase your problem in a more concise manner, with only
relevant information, if you expect someone to take the time read it and
provide a useful answer. Please see these guidelines:
http://support.microsoft.com/kb/555375/en-us

I am not sure your solution is even necessary. What we do here is use the
Add Network Place Wizard to add a shortcut on each client, which is then
easily accessible from the Open dialog via My Network Places.

Paul
 
did you ever manage to solve this problem?
I'm experiencing exactly the same problem when trying to create a shortcut
to
a document library in sharepoint.

You did not reply to a thread but rather created a new thread, and you
didn't quote the original post, so no one here has any idea what you're
talking about or who you're talking to.
 
Back
Top