Jump to content

Path of one shortcut


ricky
 Share

Recommended Posts

Hello,

How can I do to found a shotcut in the startup menu with a specific path?

Explain :

  • I know the path of a software
  • I don't know the name of the shortcut
  • In the startup menu I have a lot of shotcuts
  • I want to found the shortcut with this path and delete it

I found this fonction FileGetShortcut but I don't know how to realise my needs.

Thanks in advance for your help

Edited by ricky03
Link to comment
Share on other sites

You'll need several functions for this. First, look up _FileListToArray() in the helpfile as well as the @StartupDir. Using something similar to this (I haven't tested it) you will be able to list all the shortcuts in your startup:

$shortCuts = FileListToArray(@StartupDir, '*.lnk', 1)
Then you'll need to go through each of those shortcuts and check if it has the path you want, like this (again, not tested):

For $i = 1 to $shortCuts[0] 
If FileGetShortcut($shortCuts[$i]) = 'Put your path here' then 
FileDelete($shortCuts[$i])
Exit;or maybe return if this just a function
EndIf
Next
The FileDelete obviously deletes the shortcut. Let me know if you didn't get any of that.
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Thanks for your response.

I try with this one :

#Include <File.au3>
#Include <Array.au3>
...
Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SoftwareTest", "InstallLocation") & "RunTest.exe"
Local $shortCuts = _FileListToArray(@StartupDir, '*.lnk', 1)
Local $shortCutsCommon = _FileListToArray(@StartupCommonDir, '*.lnk', 1)
...
DeleteShortcut($shortCuts,@StartupDir)
DeleteShortcut($shortCutsCommon,@StartupCommonDir)
...
Func DeleteShortcut($value,$directory)
    For $i = 1 to $value[0]
        If FileGetShortcut("$directory\$value[$i]") == '$sFile' then
            FileDelete("$directory\$value[$i]")
            CloseWindow()
            return
        EndIf
    Next
    EndFunc

And I have the error in attachment.

post-39014-1218622050_thumb.png

Link to comment
Share on other sites

I correct a lot of problems in my code, but the problem is the same, Somebody can correct my problems ore mistakes?

#Include <File.au3>
#Include <Array.au3>
...
Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SoftwareTest", "InstallLocation") & "RunTest.exe"
DIM $shortCuts = _FileListToArray(@StartupDir, '*.lnk', 1)
DIM $shortCutsCommon = _FileListToArray(@StartupCommonDir, '*.lnk', 1)

DeleteShortcut($shortCuts,@StartupDir)
DeleteShortcut($shortCutsCommon,@StartupCommonDir)
...
Func DeleteShortcut(ByRef $value,$directory)
    If $value[0]<> 0 Then
        For $i = 1 to $value[0]
            $details = FileGetShortcut($directory & "\" & $value[$i] & ".lnk")
            If $details[0] == $sFile then
                FileDelete($details)
                CloseWindow()
                return
            EndIf
        Next
    EndIf
    EndFunc

The error is the same...

Thanks in advance

Link to comment
Share on other sites

ricky03

Example:

Dim $program = "C:\Program Files\AutoIt3\Au3Info.exe"
Dim $path = @StartMenuCommonDir & "\Programs"

$shortcut = _Search($path)

MsgBox(0, "Result", $shortcut)

Func _Search($sPath)
    
    Local $search = FileFindFirstFile($sPath & "\*.*")
    If $search = -1 Then Return
    
    While 1
        Local $iFile = FileFindNextFile($search)
        If @error Then Return False
        
        If StringInStr(FileGetAttrib($sPath & "\" & $iFile), "D") Then
            Local $iLNK = _SearchSubDir($sPath & "\" & $iFile)
            If $iLNK Then Return $iLNK
        EndIf
        
        If StringRight($iFile, 4) = ".lnk" Then
            Local $aParams = FileGetShortcut($sPath & "\" & $iFile)
            If StringInStr($aParams[0], $program) Then Return $sPath & "\" & $iFile
        EndIf
    WEnd
    
    FileClose($search)
EndFunc

Func _SearchSubDir($sPath)
    Local $search = FileFindFirstFile($sPath & "\*.*")
    If $search = -1 Then Return False
    
    While 1
        Local $iFile = FileFindNextFile($search)
        If @error Then Return False
        
        If StringRight($iFile, 4) = ".lnk" Then
            Local $aParams = FileGetShortcut($sPath & "\" & $iFile)
            If StringInStr($aParams[0], $program) Then
                Return $sPath & "\" & $iFile
            EndIf
        EndIf
    WEnd
    
    FileClose($search)
EndFunc
Link to comment
Share on other sites

I'm newbie and I need to understand each line, but i found the best solution for me :

$sFile = "C:\Program Files\Sophos\AutoUpdate\ALMon.exe"
$path = @StartupCommonDir

_Search($path)

Func _Search($sPath)
   
    Local $search = FileFindFirstFile($sPath & "\*.lnk")
    If $search = -1 Then Return
    While 1
        Local $iFile = FileFindNextFile($search)
        If @error Then Return False
        
        Local $aParams = FileGetShortcut($sPath & "\" & $iFile)
        If StringInStr($aParams[0], $sFile) Then
            FileDelete($sPath & "\" & $iFile)
        EndIf
    WEnd
   
    FileClose($search)
EndFunc

Thanks a lot for your help...

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...