Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHELLEXECUTE REFUSES TO RUN NETSTAT!!!

Status
Not open for further replies.

castor2003

Programmer
Jul 5, 2003
115
0
0
LC
Why isnt Shellexecute creating ports.txt? I have run out of ideas. Could a kind heart assist. I am trying to go around the IPI* APIs.



Code:
=shellrun([NETSTAT -a -n],[],[open],[ >C:\ports.txt],1)

FUNCTION shellrun
PARAMETERS cfile as string,cdir as string,caction as string,cparams as String ,nWinMode as integer

LOCAL success as Integer

DECLARE INTEGER ShellExecute IN shell32.dll ; 
 INTEGER hndWin, ;
 STRING cAction, ;
 STRING cFile, ;
 STRING cParams, ;
 STRING cDir, ;
 INTEGER nWinMode

cAction = ALLTRIM(cAction)
cFile = ALLTRIM(cfile)

cDir    = ALLTRIM(cDir)


success =ShellExecute(0,cAction,cFile,cParams,cDir,nWinMode)

CLEAR DLLS shellexecute

RETURN success
 
Why complicate your life? I believe this solution was already suggested to you in another post.

RUN NETSTAT -a -n >c:\ports.txt

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

Sorry if I am appearing to be a problem. I believe in excellence and surely a flashing black screen in the middle of a Windows App is not excellence by my estimation.

If NETSTAT will not run silently, then I will have to go the more painful route of using GetTCP?????() API functions.
 
castor2003,

?winexecrun("NETSTAT -a -n > c:\ports2.txt") && Will Hide command window

FUNCTION winexecrun
PARAMETER cCommand

DECLARE INTEGER WinExec IN win32api ;
STRING command, INTEGER param

retval = WinExec(SYS(2004) + "FOXRUN.PIF /C " + cCommand, 0)

CLEAR DLLS WinExec

RETURN retval


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
castor2003,

In case you are interested, the reason that your ShellExecute wouldn't work for you is that NETSTAT is a DOS command and as such it needs either command.com or cmd.exe in order to run. It will not however allow you to hide the DOS window, but just for information sake the way to use it would have been:

?shellrun(GETENV("ComSpec"),"","open"," /c NETSTAT -a -n > c:\ports1.txt",1) && Will always show command window

FUNCTION shellrun
PARAMETERS cfile as string,cdir as string,caction as string,cparams as String ,nWinMode as integer

LOCAL success as Integer

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFile, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nWinMode

cAction = ALLTRIM(cAction)
cFile = ALLTRIM(cfile)

cDir = ALLTRIM(cDir)


success =ShellExecute(0,cAction,cFile,cParams,cDir,nWinMode)

CLEAR DLLS shellexecute

RETURN success


Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
castor2003,

What did you end up doing on this?

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
castor2003

'If NETSTAT will not run silently, then I will have to go the more painful route of using GetTCP?????() API functions'

To run the WinAPI call ShellExecute() hidden, the final parameter should be 0, not 1.

WinExec is provided only for compatability with 16-bit Windows, and is basically obsolete. It also requires a final parameter of 0 to run hidden

Instead of WinExec, Win32-based applications should use the WinAPI call CreateProcess() which will run hidden if you use the correct constant in GetStartupInfo().

FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top