Jump to content

Help getting script to work properly


Recommended Posts

There is a restart.exe on the all users desktop i need to remove and a shortcut of it pinned to the desktop. I am deleting just fine. And i can pin to fine but it isn't removing for me. Any help would be greatly appreciated. 

;Unpin from Start Menu
func pinitem($file, $loc = 'task', $pin = False)
    if @OSBuild < 7600 then return seterror(1) ; Windows 7 only
    if not fileexists($file) then return seterror(2)
    local $sFolder = stringregexpreplace($file, (@DesktopCommonDir))
    local $sFile = stringregexpreplace($file, "Restart.exe")
    $ObjShell = objcreate("Shell.Application")
    $objFolder = $ObjShell.Namespace(@DesktopCommonDir)
    $objFolderItem = $objFolder.ParseName("Restart.exe")
    For $Val in $objFolderItem.Verbs()
        if $pin then
            if $loc = 'task' and $val() = "Pin to Tas&kBar" then
                $Val.DoIt()
                return
            elseif $loc = 'start' and $val() = "Pin to Start Men&u" then
                $Val.DoIt()
                return
            endif
        else
            if $loc = 'task' and $val() = "Unpin from Tas&kBar" then
                $Val.DoIt()
                return
            elseif $loc = 'start' and $val() = "Unpin from Start Men&u" then
                $Val.DoIt()
                return
            endif
        endif
    next
endfunc

;Sleep to allow time to Delete Pinned item
Sleep(5000)

;Deletes shortcut manually from all users desktop
   FileDelete(@DesktopCommonDir & "\Restart.exe")
Link to comment
Share on other sites

In the last two lines of Code you are commenting about delete a Shortcut but you are using EXE(.exe)Extension. If you want delete a shortcut then use Shortcut extension(.lnk) 

Like

FileDelete(@DesktopCommonDir & "\Restart.lnk")
;instead of
 FileDelete(@DesktopCommonDir & "\Restart.exe")
Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Link to comment
Share on other sites

In the last two lines of Code you are commenting about delete a Shortcut but you are using EXE(.exe)Extension. If you want delete a shortcut then use Shortcut extension(.lnk)

Like

FileDelete(@DesktopCommonDir & "\Restart.lnk")
;instead of
 FileDelete(@DesktopCommonDir & "\Restart.exe")

The file on the all users desktop is an exe. The shortcut is pinned to the start menu. I can delete the exe but the shortcut isn't unpinning.

Link to comment
Share on other sites

hello TheLug, welcome to AutoIt and to the forum!

pinned shortcuts are per user. i assume you want to unpin a shortcut from the currently logged-on user - the user that is executing the script.

have a look here:

http://sbctooling.com/how-to-automagically-remove-programs-that-are-pinned-to-the-start-menu/

basically, delete the shortcut from %APPDATA%MicrosoftInternet ExplorerQuick LaunchUser PinnedStartMenu

it will refresh at next logon (i think...), and you can play around with the registry to try to make it refresh immediately.

meanwhile, if a user clicks the pinned shortcut, of course it will not run, and it will say something like:

"The item you selected is unavailable.  It might have been moved, renamed, or removed.  Do you want to remove it from the list?"

if you want to go deeper, try this:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb774817(v=vs.85).aspx

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

hello TheLug, welcome to AutoIt and to the forum!

pinned shortcuts are per user. i assume you want to unpin a shortcut from the currently logged-on user - the user that is executing the script.

have a look here:

http://sbctooling.com/how-to-automagically-remove-programs-that-are-pinned-to-the-start-menu/

basically, delete the shortcut from %APPDATA%MicrosoftInternet ExplorerQuick LaunchUser PinnedStartMenu

it will refresh at next logon (i think...), and you can play around with the registry to try to make it refresh immediately.

meanwhile, if a user clicks the pinned shortcut, of course it will not run, and it will say something like:

"The item you selected is unavailable.  It might have been moved, renamed, or removed.  Do you want to remove it from the list?"

if you want to go deeper, try this:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb774817(v=vs.85).aspx

Awesome thanks for the advice. I hadn't even thought about just deleting the actual exe and if they ever click on it it will ask to remove. Brilliant! Thanks for the advice!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...