May 04, 2024, 06:19:41 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


ShellExecuteExA and System

Started by Andy, July 03, 2017, 10:33:32 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

July 03, 2017, 10:33:32 PM Last Edit: July 03, 2017, 10:36:03 PM by Andy
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.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Larry, tried that one, all it does is open the text file in notepad instead of finding it and highlighting it.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

oops, misread your question.
I don't see a way
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

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

Andy

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.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.