-
Create a shortcut on user desktop using VB shell command
Hi All
How do I create a shortcut on user desktop using VB shell command?
Can I use something like this in VB 6.0:
************************************************
Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\test.lnk")
link.Description = "test shortcut"
link.TargetPath = "c:\blah\app.exe"
link.WindowStyle = 3
link.Save
************************************************
Is WScript.Shell usually found on all user machines with Windows 2000 and XP.
I dont want to install any OCXs on user machine,
thanks
vbdude
-
Set C = CreateObject("WScript.Shell")
DesktopPath = C.SpecialFolders("Desktop")
Set link = C.CreateShortcut(DesktopPath & "\test.lnk")
link.Description = "test shortcut"
link.TargetPath = "c:\blah\app.exe"
link.WindowStyle = 3
link.Save
You cant save as shell because its a vb thing i forget.
-
Hi
Is WScript.Shell a DLL/OCX that is found on ALL user machines with Windows 2000 and XP ??
I dont want to install any OCXs on user machine.
Also, do I need to include any References into my VB project?
Thanks
vbdude
-
no you do not need to include any references or OCXS because windows 2000 and XP has wScript.shell.
The wScript.Shell is located under system32 as description Microsoft (r) Windows Based Script Host.
Last edited by XRsTX; 03-09-2005 at 07:33 PM.
-
What if the shortcut already exist on user desktop ?
How to delete the old one before addeing new one
Thanks
vbdude
-
And is there any way of error checking?
I mean, how do i make sure that shortcut was created successfully?
Thanks
vbdude
-
 Originally Posted by vbdude
And is there any way of error checking?
I mean, how do i make sure that shortcut was created successfully?
Thanks
vbdude
There are 2 approaches I can think of:
1) After the line Set link = C.CreateShortcut(DesktopPath & "\test.lnk"), test for whether link Is Nothing. This will tell you if the shortcut was created, but not whether it was created with the name & target you want, as the name & target setting happens later in the code.
2) After all your code to create the shortcut runs, you could use the Dir$ function to check the existence of the .lnk file in the Desktop folder. Use code to determine the location of the Desktop folder. Since you're already using the Windows Scripting Host (set a reference to "Windows Script Host Object Model" first), this code will give you the full path to the Desktop folder:
Code:
Dim Wshl As WshShell
Set Wshl = New WshShell
Dim strLocation As String
strLocation = Wshl.SpecialFolders("Desktop")
You can now take the strLocation variable and use it with the Dir$ function- see VB's Help or http://www.msdn.com for details.
-Andrew
-
Great. Appreciate it.
Thanks
vbdude
-
I have need useing the above script with GPO and it has been working great.
My question is how to I use or edit the script to remove a desktop icon or shortcut.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks