473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Getting Shortcuts from users desktop

!NoItAll
297 100+
Hi:
I'm using the following script to find a shortcut with a specific string in it. In the code below the example is the word "font"
My problem is that this code looks everywhere EXCEPT the individual users desktop - it does find all of the shortcuts in All Users, but not in specific users.
I am executing the code AS the user whose desktop I need to search so there shouldn't be a security issue.
I have to write a small routine to add to an installer that will delete and old shortcut from the user desktop so I would really appreciate some help.
Expand|Select|Wrap|Line Numbers
  1. . Dim sTargets
  2. . Dim sFileNames
  3. . Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
  4. . set SCs = oWMI.InstancesOf("Win32_ShortcutFile")
  5. . for each SC in SCs
  6. .    If (InStr(1, SC.Target, "font", 1)> 0) Then
  7. .        MsgBox "gotit"
  8. .        sTargets = SC.Target
  9. .        sFileNames = SC.Name
  10. .           Exit For
  11. .          End If
  12. .                 
  13. . Next
  14. . WScript.echo sTargets & vbcrlf & sFileNames
  15.  
This code works - but will not find anything in the users desktop, only in the all users desktop.

Des
Jun 6 '08 #1
1 1410
!NoItAll
297 100+
Well, I solved my own problem. As it turns out the method I was using has no options and therefore can not do what I need. Besides, it always searches the entire system and that can be very slow - so a new approach was required.
Here's the code:

Expand|Select|Wrap|Line Numbers
  1. 'this will find all of the shortcuts on the current users desktop that contain the
  2. 'string in "KillWithTarget" as the target of the shortcut.
  3.  
  4. Dim Shortcut,fso,fldr,fils,fil,WshShell,DeskTopPath,KillWithTarget
  5.  
  6. KillWithTarget="DVSConf.exe"
  7.  
  8. Set WshShell=CreateObject("WScript.Shell")
  9. DesktopPath=WshShell.SpecialFolders("Desktop")
  10.  
  11. Set fso=CreateObject("Scripting.FileSystemObject")
  12. Set fldr=fso.GetFolder(DeskTopPath)
  13. Set fils=fldr.files
  14.  
  15. For Each fil in fils
  16.  
  17.     If Right(fil.path,4) = ".lnk" Then
  18.         Set Shortcut=WshShell.CreateShortcut(fil.path)
  19.         If InStr(1, Shortcut.TargetPath, KillWithTarget, 1) > 0  Then
  20.             fso.deletefile fil.path
  21.         End If
  22.     End If
  23.  
  24. Next
  25.  
  26. 'cleanup
  27. Set WshShell = Nothing
  28. Set fso = Nothing
  29. Set fldr = Nothing
  30. Set fils = Nothing
  31.  
  32.  
So this looks in the user desktop, finds all shortcuts, then deletes any whose target application has a specific string (KillWithTarget) - case insensitive.
This makes an odd use of the createshortcut method - which is normally used to actually create a NEW shortcut. As it turns out if you call it on an existing shortcut it will open it and expose all of it's properties to you instead.

Des
Jun 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Blake | last post by:
Hello, Does anyone know if there is any way to add a condition to your setup project so that the user can choose if they want a desktop shortcut or a program menu by selecting a checkbox. I...
0
by: Jim | last post by:
I want the users to have the ability to control the installation of shortcuts to an application on the desktop. While a shortcut to the desktop can either be assigned to the Users Desktop folder or...
3
by: headware | last post by:
I have an issue that I've been encountering in an ASP application I'm working on. Most of the application is written in ASP, but there is one page written in ASP.NET. The ASP.NET page needs to have...
1
by: Richard Johansson | last post by:
Hi, I want to create an option for creating shortcuts to my application on the users desktop and Start menu in the setup. In my deployment project i have created the necessary checkboxes, and...
2
by: Mike Ridley | last post by:
I have a database of Access tables on the server and ODBC links to legacy systems. This is not too much of a problem as, at least, I have my tables/files in 2 distinct places. Unfortunately as...
0
by: GeorgeF | last post by:
How can I conditionally deploy shortcuts to my application? I have created a custom installer dialog box to give my users the option of creating desktop/start menu shortcuts, but the shortcuts do...
3
by: Michael D. Murphy | last post by:
Hi, I am searching for a way to creat desktop shortcuts when running the setup files that were created within a VB solution using the setup wizard. Thanks, Michael
2
by: reidarT | last post by:
I am making an installation program for an Access application. The application is run on both Office 2000, 2002, 2003 and soon 2007 versions of Office, When I install the application I need a...
4
by: David Jackson | last post by:
Hello, I've been asked to write a sort of "desktop clean-up" utility. Requirements are simple: iterate through the shortcuts (*.lnk files) on the currently logged-on user's desktop, and delete...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.