• Disable a desktop shortcut

    Author
    Topic
    #353244

    Hi all,

    Is there a way to disable or hide a desktop shortcut using VBA code? I would like to hide a shortcut until some of my code is finished running.

    Thanks,
    Michael Read

    Viewing 0 reply threads
    Author
    Replies
    • #516117

      I have good news and bad news: it is possible to toggle the hidden attribute of a desktop shortcut – but it doesn’t disable it. Here’s the code, perhaps it will work better for you. Plan B would be to perhaps move it temporarily, or disable the command string it contains. The former could be accomplished using the FileSystemObject, the latter probably requires further exploration of the WshShell object.

      Sub Tester()
      'determine desktop folder (might not work for individual profiles)
      Dim wshShell As Object, strDesktopFolder As String, strPath As String
      Set wshShell = CreateObject("WScript.Shell")
      strDesktopFolder = wshShell.SpecialFolders("desktop")
      Set wshShell = Nothing
       
      'toggle hidden status of file - example of Word shortcut
      strPath = strDesktopFolder & "" & "microsoft word.LNK"
      If ToggleFileHidden(strPath) = False Then
          MsgBox "File not found"
      Else
          MsgBox "Hidden attribute toggled!"
      End If
      End Sub
       
      Function ToggleFileHidden(strFullPath As String) As Boolean
      'set a reference to Microsoft Scripting Runtime
      'set file object and check attributes
      Dim fso As FileSystemObject, myFile As File
      Set fso = New FileSystemObject
      If Not fso.FileExists(strFullPath) Then
          ToggleFileHidden = False
          Set fso = Nothing
          Exit Function
      End If
      Set myFile = fso.GetFile(strFullPath)
      If myFile.Attributes And Hidden Then
          myFile.Attributes = myFile.Attributes - Hidden
      Else
          myFile.Attributes = myFile.Attributes + Hidden
      End If
      ToggleFileHidden = True
      Set myFile = Nothing
      Set fso = Nothing
      End Function
      • #516135

        Thanks Jefferson, I think!

        Boggles my marbles at first, but I think I get the drift.

        Thanks for your time,
        Michael Read

        • #516183

          I forgot to mention, if you are in Word, you can get the name of the desktop folder this way:

          strDesktop = System.PrivateProfileString(“”, _
          “HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders”, _
          “Desktop”)

          • #516213

            I tried it and it works, although I modified it to fit my purpose. The shortcut properties do change, however, like you say, the shortcut is still there.

            A great tool would be a “windows script recorder”, similar to the macro recorder in Excel, that could record scripts across the Office applications and/or within the Windows environment.

            Thanks Jefferson,
            Michael Read

    Viewing 0 reply threads
    Reply To: Disable a desktop shortcut

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: