Announcement

Collapse
No announcement yet.

VBScript to Refresh Desktop

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBScript to Refresh Desktop

    Hi,

    The VBScript you see below I added to that Rems script that he made for me and it works great.

    http://forums.petri.com/showthread.php?t=65971

    After I run Rems VBScript it leaves a desktop shortcut on the computer. So I run the VBScript you see below but it would not delete UNLESS I manually refresh the desktop. I tried various VBScripts on the internet and none of them works. Anyone has any ideas how to get this resolved?




    Code:
     
     'http://msdn.microsoft.com/en-us/library/zhy7593d(v=vs.84).aspx
    Set Shell = CreateObject("WScript.Shell")
    Set FSO = CreateObject("Scripting.FileSystemObject")
    DesktopPath = Shell.SpecialFolders("Desktop")
    FSO.DeleteFile DesktopPath & "\PHONELIST.lnk"
     
    'http://forums.devshed.com/visual-basic-programming-52/refreshing-desktop-vbscript-556658.html
    'Set WSHShell = CreateObject("WScript.Shell")
     'WshShell.SendKeys "{F5}"

  • #2
    Re: VBScript to Refresh Desktop

    It looks like the code works great in Windows 8.1 BUT not Windows 7. It turns out Windows 7 has a known bug for refreshing.


    How about this...


    How about having the code instead of deleting the file, it would move the file to the Recycle Bin?

    Can VBScript is able to do that?
    Last edited by Shazam; 13th June 2014, 19:15.

    Comment


    • #3
      Re: VBScript to Refresh Desktop

      Ok I created a Reg file to resolve my issue.

      I found the answer from the link below.

      http://www.thewindowsclub.com/deskto...ically-windows

      From the description below I copied it into a text file, saved it. Then I changed it extension from .txt to .reg, and ran it.

      Windows Registry Editor Version 5.00

      [HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance]
      "CLSID"="{4D5C8C2A-D075-11D0-B416-00C04FB90376}"
      "DontRefresh"=dword:00000000

      Comment


      • #4
        Re: VBScript to Refresh Desktop

        Did it solved the problem for you? If it is the solution you could make this a computer start up script, running this comand line (for 64-bits OS):
        Code:
        REG.exe ADD "HKCR\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance" /v DontRefresh /t REG_DWORD /d 0 /f
        Actually what I think the script was missing and would probably resolve the problem too, is a short delay between pinning and deleting the shortcut file on/from the desktop.

        here the new script where I added a 950 milliseconds delay,
        Code:
        Set WshShell = CreateObject("WScript.Shell")
        Set objShell = CreateObject("Shell.Application")
        
        strTartgetFile = "\\files\DATA\HR\Phone List\PhoneList\PHONELST.pdf"
        
        ShortcutName   = "PHONELST"
        ShortcutFolder = WshShell.SpecialFolders.Item("Desktop")
        ShortcutFile = ShortcutName & ".lnk"
        
        call PinToTaskbar("unpin")
        
        FilePath = ShortcutFolder & "\" & ShortcutFile
        
        With WshShell.CreateShortcut(FilePath)
           .TargetPath = GetProgramAssocWith("PDF")
           .Arguments = """" & strTartgetFile & """"
           .WorkingDirectory = "."
           .IconLocation = "imageres.dll, 124"
           .Description = "..."
           .Save
        End With
        
        call PinToTaskbar("pin") : WScript.Sleep 950
        
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        objFSO.DeleteFile(FilePath), true
        
        wscript.quit
        
        Function GetProgramAssocWith(strExt)
           Const HKCR=&H80000000
           Const HKCU=&H80000001
           Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
        
           strExt = Replace(strExt,"*","")
           If Left(strExt,1) <> "." Then strExt = "." & strExt
        
           strPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & strExt & "\UserChoice"
           objReg.GetExpandedStringValue HKCU, strPath, "Progid", strValue
           If IsNull(strValue) Then
             objReg.GetExpandedStringValue HKCR, strExt, strEntry, strValue
           End If
           If IsNull(strValue) Then wscript.quit
        
           strPath = strValue & "\shell\open\command"
           objReg.GetExpandedStringValue HKCR, strPath, strEntry, strValue
           strValue = Replace(strValue, """", "")
        
         ' http://www.akaplan.com/blog/2010/12/vbscript-to-get-program-associated-with-file-extension/
           If InStr(strValue,"rundll") Then
        	Dim tArray
        	tArray = split(strValue,",")
        	GetProgramAssocWith = replace(tArray(0),"rundll32.exe","")
           Else
        	strValue = LCase(strValue)
        	GetProgramAssocWith = Left(strValue,instrrev(strValue,".exe")+3)
           End If
        End Function
        
        Sub PinToTaskbar(choice)
        
           On Error Resume Next
        
           If Lcase(choice) = "unpin" then
        
             LnkFolder = WshShell.SpecialFolders.Item("AppData")
             LnkFolder = LnkFolder & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
             LnkFile = ShortcutName & ".lnk"
        
             Set objFolder = objShell.Namespace(LnkFolder)
             Set objFolderItem = objFolder.ParseName(LnkFile)
             Set colVerbs = objFolderItem.Verbs 
             For Each objVerb in colVerbs
               Select Case Replace(objVerb.name, "&", "")
                 case "Unpin from Taskbar" objVerb.DoIt
                 case "other language ..." objVerb.DoIt
                 case "other language ..." objVerb.DoIt
                 case "other language ..." objVerb.DoIt
               End Select
             Next
        
           ElseIf Lcase(choice) = "pin" then
        
             Set objFolder = objShell.Namespace(ShortcutFolder)
             Set objFolderItem = objFolder.ParseName(ShortcutFile)
             Set colVerbs = objFolderItem.Verbs
             For Each objVerb in colVerbs
               Select Case Replace(objVerb.name, "&", "")
                 case "Pin to Taskbar" objVerb.DoIt
                 case "Ajouter au menu Démarrer" objVerb.DoIt
                 case "Aggiungi a menu Start" objVerb.DoIt
                 case "An Startmenü anheften" objVerb.DoIt
                 case "Aan het menu Start vastmaken" objVerb.DoIt
                 case "Associar ao Menu Iniciar" objVerb.DoIt
                 case "Anclar al menú Inicio" objVerb.DoIt
               End Select
             Next
        
           End If
        End Sub
        /Rems
        Last edited by Rems; 14th June 2014, 07:42.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: VBScript to Refresh Desktop

          Originally posted by Rems View Post
          Did it solved the problem for you? If it is the solution you could make this a computer start up script, running this comand line (for 64-bits OS):
          Code:
          REG.exe ADD "HKCR\Wow6432Node\CLSID\{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}\Instance" /v DontRefresh /t REG_DWORD /d 0 /f
          Actually what I think the script was missing and would probably resolve the problem too, is a short delay between pinning and deleting the shortcut file on/from the desktop./Rems
          The solution I provided did not work on some of the computers I tried. Don't know why.

          Comment


          • #6
            Re: VBScript to Refresh Desktop

            Originally posted by Rems View Post
            here the new script where I added a 950 seconds delay,
            Code:
            Set WshShell = CreateObject("WScript.Shell")
            Set objShell = CreateObject("Shell.Application")
            
            strTartgetFile = "\\files\DATA\HR\Phone List\PhoneList\PHONELST.pdf"
            
            ShortcutName   = "PHONELST"
            ShortcutFolder = WshShell.SpecialFolders.Item("Desktop")
            ShortcutFile = ShortcutName & ".lnk"
            
            call PinToTaskbar("unpin")
            
            FilePath = ShortcutFolder & "\" & ShortcutFile
            
            With WshShell.CreateShortcut(FilePath)
               .TargetPath = GetProgramAssocWith("PDF")
               .Arguments = """" & strTartgetFile & """"
               .WorkingDirectory = "."
               .IconLocation = "imageres.dll, 124"
               .Description = "..."
               .Save
            End With
            
            call PinToTaskbar("pin") : WScript.Sleep 950
            
            Set objFSO = CreateObject("Scripting.FileSystemObject")
            objFSO.DeleteFile(FilePath), true
            
            wscript.quit
            
            Function GetProgramAssocWith(strExt)
               Const HKCR=&H80000000
               Const HKCU=&H80000001
               Set objReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
            
               strExt = Replace(strExt,"*","")
               If Left(strExt,1) <> "." Then strExt = "." & strExt
            
               strPath = "Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & strExt & "\UserChoice"
               objReg.GetExpandedStringValue HKCU, strPath, "Progid", strValue
               If IsNull(strValue) Then
                 objReg.GetExpandedStringValue HKCR, strExt, strEntry, strValue
               End If
               If IsNull(strValue) Then wscript.quit
            
               strPath = strValue & "\shell\open\command"
               objReg.GetExpandedStringValue HKCR, strPath, strEntry, strValue
               strValue = Replace(strValue, """", "")
            
             ' http://www.akaplan.com/blog/2010/12/vbscript-to-get-program-associated-with-file-extension/
               If InStr(strValue,"rundll") Then
                Dim tArray
                tArray = split(strValue,",")
                GetProgramAssocWith = replace(tArray(0),"rundll32.exe","")
               Else
                strValue = LCase(strValue)
                GetProgramAssocWith = Left(strValue,instrrev(strValue,".exe")+3)
               End If
            End Function
            
            Sub PinToTaskbar(choice)
            
               On Error Resume Next
            
               If Lcase(choice) = "unpin" then
            
                 LnkFolder = WshShell.SpecialFolders.Item("AppData")
                 LnkFolder = LnkFolder & "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"
                 LnkFile = ShortcutName & ".lnk"
            
                 Set objFolder = objShell.Namespace(LnkFolder)
                 Set objFolderItem = objFolder.ParseName(LnkFile)
                 Set colVerbs = objFolderItem.Verbs 
                 For Each objVerb in colVerbs
                   Select Case Replace(objVerb.name, "&", "")
                     case "Unpin from Taskbar" objVerb.DoIt
                     case "other language ..." objVerb.DoIt
                     case "other language ..." objVerb.DoIt
                     case "other language ..." objVerb.DoIt
                   End Select
                 Next
            
               ElseIf Lcase(choice) = "pin" then
            
                 Set objFolder = objShell.Namespace(ShortcutFolder)
                 Set objFolderItem = objFolder.ParseName(ShortcutFile)
                 Set colVerbs = objFolderItem.Verbs
                 For Each objVerb in colVerbs
                   Select Case Replace(objVerb.name, "&", "")
                     case "Pin to Taskbar" objVerb.DoIt
                     case "Ajouter au menu Démarrer" objVerb.DoIt
                     case "Aggiungi a menu Start" objVerb.DoIt
                     case "An Startmenü anheften" objVerb.DoIt
                     case "Aan het menu Start vastmaken" objVerb.DoIt
                     case "Associar ao Menu Iniciar" objVerb.DoIt
                     case "Anclar al menú Inicio" objVerb.DoIt
                   End Select
                 Next
            
               End If
            End Sub
            /Rems
            I tested on the trouble computers and it worked!!

            Thank you so much Rems.

            Comment

            Working...
            X