Followers 0

# How do you run/shellexecute "special" link files?

## 9 posts in this topic

When you right-click on a Windows shorcut, the "target" field usually dispalys the absolute path to the source file, but for some files, like Microsoft Office files and the Administrative Tools, the Target field is grayed out and says something else instead of a path -- almost like some sort of special shortcut. And I've tried passing the path with both Run and ShellExecute and ShellExecute gives me an error stating "parameter incorrect".

Does anyone know how you'd actually get one of those files to execute? Or how to check for one of those special files so I can treat it differently?

##### Share on other sites

Could you give me an idea of what file your opening? like...Control panel? or anything like that...you can call a .dll...to open it....is that what your asking?

##### Share on other sites

#3 ·  Posted (edited)

When you right-click on a Windows shorcut, the "target" field usually dispalys the absolute path to the source file, but for some files, like Microsoft Office files and the Administrative Tools, the Target field is grayed out and says something else instead of a path -- almost like some sort of special shortcut. And I've tried passing the path with both Run and ShellExecute and ShellExecute gives me an error stating "parameter incorrect".

Does anyone know how you'd actually get one of those files to execute? Or how to check for one of those special files so I can treat it differently?

I'm not sure how to determine the path from the shortcut file, but one method you can use until someone comes along who can figure it out, is to just ShellExecute the shortcut file. Other than that you could just try and manually locate the .exe that the shortcuts point to.

*Edit: And just for reference, I think the OP is talking about shortcuts that look like this: http://www.therks.com/public/wordshortcut.gif

Edited by Saunders

##### Share on other sites

that pic is exactly right Saunders. And my problem is that when I pass the shortcut file (like the one u uploaded) to run or shellexecute, i get errors so I was just wondering if there was a way around this?

##### Share on other sites

Hi,

I use this UDF to execute those kind of shortcuts:

_ShellExecuteEx(@AppDataDir & "\Microsoft\Internet Explorer\Quick Launch\Microsoft Word.lnk")

Func _ShellExecuteEx($sCmd,$sArgs = "", $sFolder = "",$sVerb = "", $iState = @SW_SHOWNORMAL,$hWnd = 0)
Local $stINFO = DllStructCreate("long;long;long;ptr;ptr;ptr;ptr;long;long;long;ptr;long;long;long;long") Local$stVerb = DllStructCreate("char[15];char")
Local $stPath = DllStructCreate("char[255];char") Local$stArgs = DllStructCreate("char[255];char")
Local $stWDir = DllStructCreate("char[255];char") DllStructSetData($stVerb, 1, $sVerb) DllStructSetData($stPath, 1, $sCmd) DllStructSetData($stWDir, 1, $sFolder) DllStructSetData($stArgs, 1, $sArgs) DllStructSetData($stINFO, 1, DllStructGetSize($stINFO)) DllStructSetData($stINFO, 2, BitOR(0xC, 0x40, 0x400))
DllStructSetData($stINFO, 3,$hWnd)
DllStructSetData($stINFO, 4, DllStructGetPtr($stVerb))
DllStructSetData($stINFO, 5, DllStructGetPtr($stPath))
DllStructSetData($stINFO, 6, DllStructGetPtr($stArgs))
DllStructSetData($stINFO, 7, DllStructGetPtr($stWDir))
DllStructSetData($stINFO, 8,$iState)

Local $aRet = DllCall("shell32.dll", "int", "ShellExecuteEx", "ptr", DllStructGetPtr($stINFO))
If Not IsArray($aRet) Or Not$aRet[0] Then Return SetError(2, 0, 0)

Return 1
EndFunc

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

My Work...

Spoiler

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating )

* === My topics === *

==================================================

==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

##### Share on other sites

Thanx Ms... that is exactly what I needed.

##### Share on other sites

Hi, folks!

I tried the _ShellExecuteEx UDF function to start a shortcut to a dial-up connection that requires authentication, but strangely, if I don't put some sleep after the function call, the dial-up authentication screen doesn't appear, and if I put Sleep(5000), for example, the screen appear and close after 5 seconds.

Is there some way to make it work without the wait?

Reginald0

##### Share on other sites

Is there some way to make it work without the wait?

Maybe try this:

Run(@ComSpec & ' /c Start "" "Path\to\Dial-Up.lnk"', '', @SW_HIDE)

Or look at the shortcut properties, is there some special CLSID? i think you could use that to execute it directly... or use RasDial...

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

My Work...

Spoiler

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating )

* === My topics === *

==================================================

==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

##### Share on other sites

MrCreator, thanks for your tips. I have already tried the Run(@ComSpec...) alternative, but with the /c option it did nothing, and with /k option works, but open another CMD.EXE window that @SW_HIDE doesn't catch.

The RasDial alternative is really functional, and in fact I was using it to circumvent the ShellExecuteEx problem, but I just don't understand why this function didn't work the way I was expecting, since it loads the DialUp connection, but if I don't put some sleep after the loaded screen, it closes immediatelly, and my impression is that the function itself is closing the process, because if I put 5 seconds of sleep, the screen closes right after that.

Anyway, many thanks for your attention.

Reginald0