Sign in to follow this  
Followers 0
thepip3r

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?


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


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


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


Link to post
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?


My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Share this post


Link to post
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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

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

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
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?

Thanks in advance.

Reginald0

Share this post


Link to post
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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

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

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
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

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  
Followers 0