Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh view in start menu after removing *.lnk Files 1

Status
Not open for further replies.

alheim

IS-IT--Management
Sep 4, 2002
3
CH
Hi,

we delete old links in our start menu, using a script. The script deletes e.g. a file "test.lnk" in the %userprofile%\Start Menu.

if i run the script, the test.lnk will be deleted, but after that if i open the start menu, i still see the entry "Test". Only if i stop the process "explorer.exe" and then restart it, the entry "Test" disappears.

Has anybody an idea who i can do this "refresh" without restarting the process "explorer.exe". (Perhaps with a rundll32. command??)
 
Under Win2K Pro I see a lag of a few seconds, but the link does go away.

To force it you need to use the RefreshMenu method of the Windows Shell Application object.

Note that this is not the "shell" object you usually think of when working with WSH. That one seems to be called the "file shell" in the WSH documentation - the one with WScript.Shell as its progID. This one has Shell.Application as its progID, and is present on NT 4 and later, as well as Win98 and later, and even Win95 if the Desktop Update has been installed (an IE 4.x optional enhancement to Windows 95).

Please note the warning not to use RefreshMenu under WinXP. You might want to include logic to skip this part under WinXP. I haven't tested the scenario to see what "damage" RefreshMenu might do to XP.

And yeah, you can use a naked .VBS file and do CreateObject() calls instead of a .WSF as shown here:

StartShort.wsf
Code:
<job id=&quot;StartShort&quot;>
  <object id = &quot;objFileSh&quot; progid = &quot;WScript.Shell&quot;/>
  <object id = &quot;objDeskSh&quot; progid = &quot;Shell.Application&quot;/>
  <object id = &quot;objFSO&quot; progid = &quot;Scripting.FileSystemObject&quot;/>

  <script language = &quot;VBScript&quot;>
    Option Explicit

    Sub CreateShortcut()
      Dim strStartMenu, objShort

      strStartMenu = objFileSh.SpecialFolders(&quot;StartMenu&quot;)
      Set objShort = objFileSh.CreateShortcut(strStartMenu & &quot;\test.lnk&quot;)
      objShort.Description = &quot;Test Shortcut&quot;
      objShort.TargetPath = &quot;%WinDir%\notepad.exe&quot;
      objShort.IconLocation = &quot;notepad.exe,1&quot;
      objShort.WorkingDirectory = objFileSh.SpecialFolders(&quot;Desktop&quot;)
      objShort.WindowStyle = 1
      objShort.Save
      Set objShort = Nothing
    End Sub

    Sub RemoveShortcut()
      Dim strStartMenu

      strStartMenu = objFileSh.SpecialFolders(&quot;StartMenu&quot;)
      objFSO.DeleteFile(strStartMenu & &quot;\test.lnk&quot;)
    End Sub

    Sub RefreshMenu()
      'The functionality that RefreshMenu provides is handled
      'automatically under Microsoft® Windows® XP or later,
      'so do not call this method under that operating system. 

      objDeskSh.RefreshMenu
    End Sub

    CreateShortcut
    MsgBox &quot;Check Start Menu for &quot;&quot;Test Shortcut.&quot;&quot;  &quot; _
         & &quot;Ok to continue&quot;, vbOKOnly
    RemoveShortcut
    MsgBox &quot;Check Start Menu for &quot;&quot;Test Shortcut.&quot;&quot;  &quot; _
         & &quot;Gone yet?  Ok to continue&quot;, vbOKOnly
    RefreshMenu
    MsgBox &quot;Check Start Menu for &quot;&quot;Test Shortcut.&quot;&quot;  &quot; _
         & &quot;Should be gone for good.  Ok to complete&quot;, vbOKOnly
  </script>
</job>
 
i have found the post of much use
cheers
have a star
 
Thanks mrmovie. I should have noted in case anybody missed it that:
Code:
Set objShort = objFileSh.CreateShortcut(strStartMenu & &quot;\test.lnk&quot;)
Might more typically be:
Code:
Set objShort = objFileSh.CreateShortcut(strStartMenu & &quot;\Programs\test.lnk&quot;)
Doing it the first way stacks the shortcut at the top of the &quot;main&quot; Start Menu (the left-most popup, up where things like &quot;Windows Update&quot; like to live). The second way puts it into the &quot;Programs&quot; submenu.

If you make the change above, be sure to change it where it gets deleted too ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top