VBScript to Refresh Desktop

Home Forums Scripting Windows Script Host VBScript to Refresh Desktop

This topic contains 5 replies, has 2 voices, and was last updated by Avatar Shazam 5 years, 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • Avatar
    Shazam
    Member
    #163853

    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?

    ‘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}”

    [/CODE][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}”

    [/CODE]

    Avatar
    Shazam
    Member
    #318958

    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?

    Avatar
    Shazam
    Member
    #318959

    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/desktop-does-not-refresh-automatically-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_ROOTWow6432NodeCLSID{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}Instance]
    “CLSID”=”{4D5C8C2A-D075-11D0-B416-00C04FB90376}”
    “DontRefresh”=dword:00000000

    Rems
    Rems
    Moderator
    #228438

    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 “HKCRWow6432NodeCLSID{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}Instance” /v DontRefresh /t REG_DWORD /d 0 /f[/CODE]

    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 [U][COLOR=”Red”]milliseconds[/COLOR][/U] delay,
    [code]
    Set WshShell = CreateObject(“WScript.Shell”)
    Set objShell = CreateObject(“Shell.Application”)

    strTartgetFile = “[COLOR=”blue”]\filesDATAHRPhone ListPhoneListPHONELST.pdf[/COLOR]”

    ShortcutName = “[COLOR=”blue”]PHONELST[/COLOR]”
    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”) : [B]WScript.Sleep 950[/B]

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    objFSO.DeleteFile(FilePath), true

    wscript.quit

    Function GetProgramAssocWith(strExt)
    Const HKCR=&H80000000
    Const HKCU=&H80000001
    Set objReg = GetObject(“winmgmts:\.rootdefault:StdRegProv”)

    strExt = Replace(strExt,”*”,””)
    If Left(strExt,1) “.” Then strExt = “.” & strExt

    strPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerFileExts” & 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 & “shellopencommand”
    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 & “MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar”
    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

    Avatar
    Shazam
    Member
    #318960

    Re: VBScript to Refresh Desktop

    Rems;284499 wrote:
    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):
    REG.exe ADD “HKCRWow6432NodeCLSID{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}Instance” /v DontRefresh /t REG_DWORD /d 0 /f[/CODE]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[/QUOTE]

    The solution I provided did not work on some of the computers I tried. Don’t know why.[CODE]REG.exe ADD “HKCRWow6432NodeCLSID{BDEADE7F-C265-11D0-BCED-00A0C90AB50F}Instance” /v DontRefresh /t REG_DWORD /d 0 /f[/CODE]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.

    Avatar
    Shazam
    Member
    #318961

    Re: VBScript to Refresh Desktop

    Rems;284499 wrote:
    here the new script where I added a 950 seconds delay,

    Code:
    Set WshShell = CreateObject(“WScript.Shell”)
    Set objShell = CreateObject(“Shell.Application”)

    strTartgetFile = “[COLOR=blue]\filesDATAHRPhone ListPhoneListPHONELST.pdf[/COLOR]”

    ShortcutName = “[COLOR=blue]PHONELST[/COLOR]”
    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”) : [B]WScript.Sleep 950[/B]

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    objFSO.DeleteFile(FilePath), true

    wscript.quit

    Function GetProgramAssocWith(strExt)
    Const HKCR=&H80000000
    Const HKCU=&H80000001
    Set objReg = GetObject(“winmgmts:\.rootdefault:StdRegProv”)

    strExt = Replace(strExt,”*”,””)
    If Left(strExt,1) “.” Then strExt = “.” & strExt

    strPath = “SoftwareMicrosoftWindowsCurrentVersionExplorerFileExts” & 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 & “shellopencommand”
    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 & “MicrosoftInternet ExplorerQuick LaunchUser PinnedTaskBar”
    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.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.