tags:

views:

1266

answers:

2

Hi,

I would like to create a shortcut on the desktop using VBScript code. I have a virtual Drive in my computer. (Virtual Drive is like G drive) I want this shortcut to explore that Drive directly. For this I find out that Shortcut with following string as a TargetPath would work for me:

C:\WINDOWS\explorer.exe /n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{89214D20-CAC1-4A33-8DF4-BD9D18A996B9}

While creating shortcut using vb script I need to enclose above string in " ", which don't work for me. I need to delete " " from the Target of the created Shortcut only then it works. Is there any way so that I can create shortcut programmatically, that can explore the virtual drive (available in my system). I need to get it in Vista OS.

Regards Sumeet Nandan Garg

+2  A: 

Google gives a lot of interesting result. For example, this - with P/Invoke calls, seems to be an answer. (this is for your post tag .NET)

Here an example for VBScript:

Set shell = WScript.CreateObject("WScript.Shell")
Set link= shell.CreateShortcut("Explorer.lnk")
link.TargetPath = "c:\windows\explorer.exe"
link.Save
abatishchev
Seems like I am not able to put the exact situation I am facing. I need to set TargetPath with no quotes (") programmatically.
Sumeet
What do you mean by "no quotes"? What problem with it? Do you have some string variable?
abatishchev
I need to put this in Target of the Shortcut:C:\WINDOWS\explorer.exe /n,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\::{89214D20-CAC1-4A33-8DF4-BD9D18A996B9}That too without enclosing in ".
Sumeet
First and last quotes means only string variable and will not be put in target shortcut target
abatishchev
when I check the property of the shortcut file manually. I found that the above string is enclosed with ". Hence, I have to remove them explicitly get it working.
Sumeet
And does it was not working, while having quotes in properties??All time I saw such situation, all was working fine, quotes was used just for paths with spaces escaping.
abatishchev
Yes.. with quotes it is not working. Infact, with quotes ,it is giving error on Apply.
Sumeet
I understood! Windows threats string in quotes as complete path. So it must be: "c:\windows\explorer.exe" /n,::..
abatishchev
Yes.. but while creating shortcut programmatically how can I set this value as TargetPath without enclosing in Quotes? This is my main issue.
Sumeet
I have no such problem in Windows 7. What is your OS? I will try it also in XP SP3 soon.
abatishchev
+1  A: 

I am generting .lnk file programmatically now using Win32 method i.e. (IWshShortcut)shell.CreateShortcut() to create the Shortcut file. And it works like charm. Thanks.!!

Sumeet