IonicWind Software

IWBasic => General Questions => Topic started by: Andy on July 03, 2017, 10:33:32 PM

Title: ShellExecuteExA and System
Post by: Andy on July 03, 2017, 10:33:32 PM
I wondered for some time how you could open explorer.exe and get it to highlight a specific file.  After doing a little reading I managed it (at least on my win 10 pc).

string Option
string FullPath

Option   = "/select," 'Highlight the file.
FullPath = "C:\\bid\\2.txt" 'Full path of file to be highlighted.

system "explorer.exe", Option + FullPath
END


Now, System is invoking the ShellExecuteExA command - or that's what I've come to believe, so why can't I re-write the above with ShellExecuteExA.

The code below doesn't work, and I've tried many variations, i.e. changing the verb, file, parameters etc.

type SHELLEXECUTEINFO,4
def cbSize:int
def fMask:int
def hwnd:int
def lpVerb:pointer
def lpFile:pointer
def lpParameters:pointer
def lpDirectory:pointer
def nShow:int
def hInstApp:int
def lpIDList:int
def lpClass:pointer
def hkeyClass:INT
def dwHotKey:int
def hIcon:int
def hProcess:int
endtype

CONST WAITTIMEOUT = 258
CONST SEE_MASK_NOCLOSEPROCESS = 0x40
def info:SHELLEXECUTEINFO
def ret:int

DECLARE IMPORT,ShellExecuteExA(info:SHELLEXECUTEINFO),int
DECLARE IMPORT,WaitForSingleObject(handle:int,ms:int),int


info.cbSize = sizeof(SHELLEXECUTEINFO)
info.fMask = SEE_MASK_NOCLOSEPROCESS
info.hwnd = 0
info.lpVerb = ""
info.lpFile = "explorer.exe"
info.lpParameters = ""
info.lpDirectory = "c:\\Bid\\2.txt"
info.nShow = @SWRESTORE
info.hInstApp = 0


ShellExecuteExA(info)


So what would be the equivalent of the system command written as ShellExecuteExA?

Thanks,
Andy.
Title: Re: ShellExecuteExA and System
Post by: LarryMc on July 04, 2017, 09:57:21 AM
info.cbSize = sizeof(SHELLEXECUTEINFO)
info.fMask = SEE_MASK_NOCLOSEPROCESS
info.hwnd = 0
info.lpVerb = "open"
info.lpFile = "explorer.exe"
info.lpParameters = "c:\\Bid\\2.txt"
info.lpDirectory = ""
info.nShow = @SWRESTORE
info.hInstApp = 0
Title: Re: ShellExecuteExA and System
Post by: Andy on July 04, 2017, 12:20:09 PM
Larry, tried that one, all it does is open the text file in notepad instead of finding it and highlighting it.
Title: Re: ShellExecuteExA and System
Post by: LarryMc on July 04, 2017, 04:48:55 PM
oops, misread your question.
I don't see a way
Title: Re: ShellExecuteExA and System
Post by: fasecero on July 04, 2017, 07:45:10 PM
Hi, Andy. I am sure /select is correct but isn't working for me either, no idea why. Here's an alternative:



$INCLUDE "windowssdk.inc"
$INCLUDE "Shlobj.inc"

OleInitialize(0)
SelectExplorerFile("C:\\Users\\FC\\Desktop\\temp.txt")
OleUninitialize()
END

SUB SelectExplorerFile(string filename)
    pointer pidl = ILCreateFromPath(filename)

    IF pidl THEN
        SHOpenFolderAndSelectItems(pidl, 0, 0, 0)
        ILFree(pidl)
    ENDIF
ENDSUB
Title: Re: ShellExecuteExA and System
Post by: Andy on July 04, 2017, 10:44:25 PM
Larry, no problem I misread questions all the time!

Fasecero, good to hear from you again.
That's a nice little piece of code - thanks!

I wonder why /select doesn't work for you?, I'm on win 10 32 bit, I'll try it on win 7 later today.

Andy.