Jump to content
Sign in to follow this  
Dev

Run A Shortcut?

Recommended Posts

how do i find out what extension it is? its a shortcut i know that but what?

if its not .lnk or .shortcut thenw what could it be?, its definitely not .exe

*edit* it is not .url either

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

$sSearch = FileFindFirstFile(@DesktopDir & "\*.*")
If NOT @Error Then
$sList = ""
While 1
    $sFile = FileFindNextFile($sSearch)
    If @Error Then ExitLoop
    If StringInStr(FileGetAttrib(@DesktopDir & "\" & $sFile), "D") Then ContinueLoop
    $sList &= $sFile & @CRLF
Wend
FileClose($sSearch)
MsgBox(0, "Results", $sList)

See what shows in the list for BitComet


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

shows it as BitComet.lnk

thanks for the code btw :D

but if i use the code:

ShellExecute(@DesktopDir & "\BitComet.lnk")

nothing happens whatsoever when i run the script

tried disabling my firewall, as that tends to stop things, and that didnt change the result

why is it that something that works for everyone else does not work for me?

i have Windows XP Pro

Service Pack 2

Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

shows it as BitComet.lnk

thanks for the code btw :D

but if i use the code:

ShellExecute(@DesktopDir & "\BitComet.lnk")

nothing happens whatsoever when i run the script

tried disabling my firewall, as that tends to stop things, and that didnt change the result

why is it that something that works for everyone else does not work for me?

i have Windows XP Pro

Service Pack 2

Okay we will take this a step further.

$aLink = FileGetShortcut (@DesktopDir & "\BitComet.lnk")
If NOT @Error Then ShellExecute($aLink[0], "", $aLink[1])

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

shows it as BitComet.lnk

thanks for the code btw :D

but if i use the code:

ShellExecute(@DesktopDir & "\BitComet.lnk")

nothing happens whatsoever when i run the script

tried disabling my firewall, as that tends to stop things, and that didnt change the result

why is it that something that works for everyone else does not work for me?

i have Windows XP Pro

Service Pack 2

Are you sure the lnk is in @DesktopDir? You can also try @DesktopCommonDir, that's where most of my LNKs are since my programs weren't installed just for me.

Share this post


Link to post
Share on other sites

The code I gave him to test shows it's in @DesktopDir


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

AutoIT doesn't execute some LNK files properly (especially MSI advertised shortcuts). I'm not sure why AutoIT wouldn't be using ShellExecuteEX by now, as that always works for any types of shortcuts. However, through consistent testing, AutoIT *still* fails to open these shortcuts properly. DOS 'start' doesn't work either.

I would assume that these would normally apply to Start Menu items, but probably some Desktop shortcuts created by installs as well.

A good indication of whether it is a MSI shortcut is exactly what types of things you get back from FileGetShortcut. Try using that and relaying that information to us.


Share this post


Link to post
Share on other sites

...I'm not sure why AutoIT wouldn't be using ShellExecuteEX by now, as that always works for any types of shortcuts. ....

We don't know that it isn't on the list of several hundred things people have asked for. It all takes time. Even if a Teature request is approved it doesn't mean that it will be ready for release within a day.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

AutoIT doesn't execute some LNK files properly (especially MSI advertised shortcuts). I'm not sure why AutoIT wouldn't be using ShellExecuteEX by now.....

As far as I know is ShellExecute using the ShellExecuteEX() function. How did you conclude otherwise?

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As far as I know is ShellExecute using the ShellExecuteEX() function. How did you conclude otherwise?

Jos

Because using ShellExecute() on a shortcut doesn't work, but using a DLLCall to ShellExecuteEX works. Same shortcut was used each time.

It could be that AutoIT *is* using ShellExecuteEX, but its not setting the flags appropriately? Whatever the case, MSI advertised shortcuts have never worked properly with it in my testing.


Share this post


Link to post
Share on other sites

Because using ShellExecute() on a shortcut doesn't work, but using a DLLCall to ShellExecuteEX works. Same shortcut was used each time.

It could be that AutoIT *is* using ShellExecuteEX, but its not setting the flags appropriately? Whatever the case, MSI advertised shortcuts have never worked properly with it in my testing.

Just tried ShellExecute() on one of my desktop shortcuts and it worked fine.

Do you have an example for me that shows the issue and the DllCal that does work for you?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

The AutoIT built-in code (doesn't work):

ShellExecute("C:\Documents and Settings\All Users\Start Menu\Programs\Graphics View+Edit\ACD Systems\ACDSee Pro 2.5.lnk")

Using _ShellExecuteEx (modified from MrCreatoR's function of the same name), which works as it should:

_ShellExecuteEx("C:\Documents and Settings\All Users\Start Menu\Programs\Graphics View+Edit\ACD Systems\ACDSee Pro 2.5.lnk")

Func _ShellExecuteEx($sCmd, $sParams = "", $sFolder = "", $sVerb = "", $iState = @SW_SHOWNORMAL,$bCloseProcessHandle=True)
    Local $stINFO,$stVerb,$stPath,$stArgs,$stWDir,$aRet,$hWnd=0,$aProcessArray[2]=[0,0]
    Local $iParamLen,$iCmdLen,$iFolderLen
    
    ; Check lengths of strings. Is this arbritrary? Check w/MrCreatoR..
    ; Longest 'proper' verb I know of is 'properties' which is 11 (10+1 null-term),
    ;   but what if new ones are introduce or already available..
    ; If StringLen($sVerb)>14 Then Return SetError(1,0,0)

    $iParamLen=StringLen($sParams)
    ; Verify string lengths are less than maximum.
    ; Through testing, 1997 (1996+1 NULL-term) is the maximum parameter length for this call (Unicode)
    If $iParamLen>1996 Then Return SetError(1,0,0)
    
    $iCmdLen=StringLen($sCmd)
    ; Verify string lengths are less than maximum. [MAX_PATH is 260, but Unicode allows exceptions]
    ; 32767 max length for Unicode strings if prefixed with '\\?\'
    If $iCmdLen>259 Then
        ; 32767-NULL=32766 - 4 (\\?\) = 32762
        If $iCmdLen>(32766-4) Then Return SetError(1,0,0)
        $sCmd='\\?\' & $sCmd
    EndIf       
    
    $iFolderLen=StringLen($sFolder)
    ; Verify string lengths are less than maximum. [MAX_PATH is 260, but Unicode allows exceptions]
    ; 32767 max length for Unicode strings if prefixed with '\\?\'
    If $iFolderLen>259 Then
        ; 32767-NULL=32766 - 4 (\\?\) = 32762
        If $iFolderLen>(32766-4) Then Return SetError(1,0,0)
        $sFolder='\\?\' & $sFolder
    EndIf
        
    ; Setup string structures
    $stVerb = DllStructCreate("wchar["&(StringLen($sVerb)+1)&"]")
    $stPath = DllStructCreate("wchar[" &($iCmdLen+1)& "];wchar")
    $stArgs = DllStructCreate("wchar[" &($iParamLen+1)& "];wchar")
    $stWDir = DllStructCreate("wchar[" &($iFolderLen+1)& "];wchar")
    
    ; Initialize string structures (which are then used by pointer in the larger SHELLEXECUTEINFO structure)
    DllStructSetData($stVerb, 1, $sVerb)
    DllStructSetData($stPath, 1, $sCmd)
    DllStructSetData($stWDir, 1, $sFolder)
    DllStructSetData($stArgs, 1, $sParams)
    
    ; SHELLEXECUTEINFO structure
    $stINFO = DllStructCreate("ulong;ulong;long;ptr;ptr;ptr;ptr;long;long;ptr;ptr;long;ulong;long;long")

    ; SHELLEXECUTEINFO structure initialize
    DllStructSetData($stINFO, 1, DllStructGetSize($stINFO)) ; cbSize, size (in bytes) of structure
    ; ------------------------------------------------------------------------------------------------------
    ; fMask Options:
    ;   0x40 = SEE_MASK_NOCLOSEPROCESS. The 15th element in structure (hProcess) will be set with the Process handle
    ;       NOTE: per MSDN, this handle *must* be closed by the caller. (similar to how "OpenProcess" must use "CloseProcess")
    ;   0x400 = SEE_MASK_FLAG_NO_UI = Do not display an error message box if an error occurs.
    ;       This is not default ShellExecute() behavior, which will display the error message box
    ; ------------------------------------------------------------------------------------------------------
    DllStructSetData($stINFO, 2, BitOR(0x40,0x400)) ; fMask
    ; HWND - MSDN: A window handle to any message boxes that the system might produce while executing this function.
    DllStructSetData($stINFO, 3, $hWnd) ; Is this supposed to *receive* instead of send? I have yet to get clarity on this.
    DllStructSetData($stINFO, 4, DllStructGetPtr($stVerb))  ; lpVerb: pointer to the verb string
    DllStructSetData($stINFO, 5, DllStructGetPtr($stPath))  ; lpFile: pointer to the $cmd string
    DllStructSetData($stINFO, 6, DllStructGetPtr($stArgs))  ; lpParameters: pointer to the parameters/arguments string
    DllStructSetData($stINFO, 7, DllStructGetPtr($stWDir))  ; lpDirectory: pointer to working directory string
    DllStructSetData($stINFO, 8, $iState)   ; nShow = state to show window as

#cs     
    ; ------------------------------------------------------------------------------------------------------
    ; Per MSDN Documentation, the following call should be done prior to calling ShellExecuteEx:
    ; CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) ; COINIT_APARTMENTTHREADED = 0x2,COINIT_DISABLE_OLE1DDE = 0x4
    ; Reason:
    ;   "Because ShellExecuteEx can delegate execution to Shell extensions (data sources, context menu handlers, verb implementations)
    ;   that are activated using Component Object Model (COM), COM should be initialized before ShellExecuteEx is called.
    ;   Some Shell extensions require the COM single-threaded apartment (STA) type. In that case, COM should be initialized as shown here.
    ;   There are certainly instances where ShellExecuteEx does not use one of these types of Shell extension and those instances would not
    ;   require COM to be initialized at all. Nonetheless, it is good practice to always initalize COM before using this function."
    ; ------------------------------------------------------------------------------------------------------
#ce
    DllCall("ole32.dll", "int", "CoInitializeEx", "ptr", Chr(0), "dword", BitOR(2,4))
    ; I don't care if it succeeds. Doesn't seem to make much difference even to call it.
        
    $aRet=DllCall("shell32.dll", "int", "ShellExecuteExW", "ptr", DllStructGetPtr($stINFO))

    If @error Or Not $aRet[0] Then
        ; DLLStructDelete()'s:
        $stINFO=0
        $stVerb=0
        $stPath=0
        $stArgs=0
        $stWDir=0
        Return SetError(2,@error,0)
    EndIf
    ; Get Process Handle, if one exists (non-NULL if new process started, otherwise
    ;   NULL if app that performs 'verb' is already running, or is perhaps a 'properties' dialog etc)
    $aProcessArray[1]=DllStructGetData($stINFO,15)
    ; Get Process ID from Handle
    If ($aProcessArray[1]) Then
        $aRet=DllCall("Kernel32.dll","dword","GetProcessId","long",$aProcessArray[1])
        If IsArray($aRet) Then $aProcessArray[0]=$aRet[0]
    EndIf
    
    ;ConsoleWrite("Handle passed to function:" & Number($hWnd) & ", Handle AFTER call:" & Number(DllStructGetData($stINFO,3)) & @CRLF)
    ;ConsoleWrite("Process Handle:" & Number($hProcess) & ", Process ID:" & Number($vProcessID) & @CRLF)

    ; Close Handle
    If $bCloseProcessHandle And $aProcessArray[1] Then DllCall('kernel32.dll','ptr', 'CloseHandle','ptr', $aProcessArray[1])
    
    ; DLLStructDelete()'s:
    $stINFO=0
    $stVerb=0
    $stPath=0
    $stArgs=0
    $stWDir=0
    If ($bCloseProcessHandle) Then Return SetError(0,0,$aProcessArray[0])
    SetError(0,0)
    Return $aProcessArray
EndFunc

p.s. - this function has a header and also a _ShellExecuteExWait() counterpart function (due to the possibility it will return a Process Handle), but I'm just giving a clipped version of the code to show how it applies.

Edited by ascendant

Share this post


Link to post
Share on other sites

I don't have ACDSee installed so tried a few others and am getting an "Invalid parameter" when doing:

ShellExecute("C:\Documents and Settings\All Users.WINDOWS\Start Menu\Programs\Microsoft Office\Microsoft Office Word 2007.lnk")

Will have a look to see if I can spot the difference.

Jos


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok, The problem is that we do a ShellExcecuteEx() with a default verb of "open" as described in the Helpfile.

This seems to be working for most but not for some of the shortcuts. There is currently no way to change the verb to "".

We are discussing the best solution for this issue.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Jos, are you certain that's what the problem is? I've added the "open" verb to my _ShellExecuteEx() call, and it still works. What about your Word shortcut? Have you tested it with the UDF version of ShellExecuteEx, with/without "open"?

Thanks

p.s. what flags are you setting? If you set the wrong ones it'd probably have the wrong effect - for example, if '0xc' is set (as it was in MrCreatoR's original version), it will require lpIDList is set correctly, which has to do with the way 'verbs' are treated.

Edited by ascendant

Share this post


Link to post
Share on other sites

Okay we will take this a step further.

$aLink = FileGetShortcut (@DesktopDir & "\BitComet.lnk")
If NOT @Error Then ShellExecute($aLink[0], "", $aLink[1])
hahaha typical, an array saves the day, thankyou GEOSoft :D Edited by snowman533

Intermediate AutoIt/Autohotkey User

Share this post


Link to post
Share on other sites

Jos, are you certain that's what the problem is? I've added the "open" verb to my _ShellExecuteEx() call, and it still works. What about your Word shortcut? Have you tested it with the UDF version of ShellExecuteEx, with/without "open"?

Thanks

p.s. what flags are you setting? If you set the wrong ones it'd probably have the wrong effect - for example, if '0xc' is set (as it was in MrCreatoR's original version), it will require lpIDList is set correctly, which has to do with the way 'verbs' are treated.

I tested with the Word shortcut which failed using the current AutoIt3 ShellExecute() and worked with the posted UDF.

After changing the default from "open" to "", the Word shortcut opened fine.

As I do not have ACDSee I don't know if the issue you have is the same as I had... do you have any other examples to verify this with?

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

I'm gonna have to find more MSI Advertised shortcuts...I'll give it a look tomorrow to see if I have any others or if someone I know does.

One good indicator is when you do FileGetShortcut(), and what returns for the 'Target Path' is something like "C:\Windows\Installer\{2D95950E-6D76-43E7-94A5-D9DBA2FD29E4}\SomeExeName_F29342392.exe"

(anything in the Windows\Installer folder is as good an indicator as I've seen)


Share this post


Link to post
Share on other sites

I'm gonna have to find more MSI Advertised shortcuts...I'll give it a look tomorrow to see if I have any others or if someone I know does.

One good indicator is when you do FileGetShortcut(), and what returns for the 'Target Path' is something like "C:\Windows\Installer\{2D95950E-6D76-43E7-94A5-D9DBA2FD29E4}\SomeExeName_F29342392.exe"

(anything in the Windows\Installer folder is as good an indicator as I've seen)

Just installed ACDsee trial version which installs a shortcut in "C:\Documents and Settings\All Users.WINDOWS\Start Menu\Programs\ACD Systems"

Then Used this path to start your shown shortcut. It gave me the exact same error as the office lnk : Invalid Parameter when using the buildin function.

I am getting the exact same error from the UDF when using the Verb="open" and changing this line to ensure errors are shown:

DllStructSetData($stINFO, 2, 0x40); fMask
Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

you know, you're absolutely correct. I had done a stupid thing and put "open" in the wrong field (folder -oops) - but yes, adding 'open' does cause the same problem. So what do you think, should the "open" verb be removed for shortcut (LNK) files?

By the way, take a look at _FileGetShortcutEx(), done by ProgAndy - which returns the correct target for MSI advertised shortcuts. Do you think that could/should be incorporated as part of FileGetShortcut()? (kinda unrelated, perhaps.. but it just came to mind)

Edited by ascendant

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...