Re: Shell Functions and DOS executables

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Randy,
You seem to be an API Expert, I thought there was an API that could be used
to create the process, and another one that could read the STDIO streams. I
did a quick search, but I couldn't find anything. Do you know what the
API's are, and if they are accessible in VB6?

Thanks
Lance

"Randy Birch" <rgb_removethis@xxxxxxxx> wrote in message
news:OSjGM7xHGHA.3036@xxxxxxxxxxxxxxxxxxxxxxx
Before you relocate the exe because of the short file name limitation of the
app, try using the API to get the short file path and name of the exe as
WIndows knows it, then use that ...

---- put in general declarations area of the form:

Private Const MAX_PATH = 260

Private Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long


---- put in some procedure:

Dim sShortPath As String
Dim nSize As Long
Dim ret As Long

sShortPath = Space$(MAX_PATH)
nSize = MAX_PATH
ret = GetShortPathName(sSource, sShortPath, nSize)

If ret > 0 Then

'remove trailing null
sShortPath = Left$(sShortPath, ret)
end if


--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/

Please reply to the newsgroups so all can participate.




"VB_Newby" <VB_Newby@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:43d2f2eb$0$75123$892e7fe2@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
: Lance Wynn said
:
: > That's interesting. I downloaded the EXE, and while I can't pass
: > it a valid file, I was able to retrieve output from it, albeit in
: > a round about way ;-)
: >
: > I had to create a .BAT file that actually made the call to the
: > exe, the .BAT file only needs one line:
: > D:\temp\cnvrtwfm.exe %*
: >
: > (or it's equivalent)
: >
: > Then, I run the BAT file just like I would the exe, but I tweaked
: > the code a bit to read the STDErr as well. Read the STDOut into
: > a variable, which will show you the output from the BAT, and
: > immediately following, read the STDErrResults which is where you
: > should see the output from the exe. Now, I believe the
: > STDOut.ReadAll call will not complete until the BAT file exits,
: > which is not until the exe finishes processing, so you should be
: > ok, but you may need to put a loop in there to check for
: > completion:
: >
: > Dim wsh As IWshRuntimeLibrary.WshShell
: > Dim wshExec As IWshRuntimeLibrary.wshExec
: > Dim STDErrResults As String
: > Dim STDOutResults As String
: > Set wsh = New WshShell
: > 'Set wshExec = wsh.Exec("D:\temp\cnvrtwfm.exe")
: > Set wshExec = wsh.Exec("C:\test.bat fdsfs -p -r -blah")
: > STDOutResults = wshExec.StdOut.ReadAll
: >
: >
: > STDErrResults = wshExec.StdErr.ReadAll
: >
: >
: > BTW, I'd love to hear if this works for you.
:
: Success!
:
: STDOutResults
: Reports (echo's) the command string whether the CNVRTWFM.EXE
: succeeds or fails. Example: "cnvrtwfm.exe -l TEK00009.wfm"
:
: STDErrResults
: Reports "Creating filename.dat" if successful
: (Example: Creating TEK00009.dat)
:
: Reports "Error Converting filename.wfm" if NOT successful
: (Example: Error Converting TEK00009.wfm)
:
: So, I interrogate STDErrResults for "Error", Presto!
:
:
: Next step: Now, I'm integrating yet another Tektronix conversion
: program (ConvertTekWfm.exe). This animal is much more verbose,
: doesn't need to be wrapped in a batch file, and reports ALL it's
: info via the STDOutResults. Go figure? ;-D
:
: Thanks again for all your help. I'd have never figured this out!
:
: Code Snippet:
: ################################
: If Option_TDS754C.Value = True Then
:
: ' Well this stinks.
: ' Apparently the TEK CNVRTWFM file cannot handle directories longer
: ' than 8 chars! So, copy the CNVRTWFM file to USER directory, do
: ' conversion, delete it, Ugh..... How crude is this?
:
: FileCopy (App.Path & "\" & "cnvrtwfm.exe"), _
: (File1.Path & "\" & "cnvrtwfm.exe")
:
: FileCopy (App.Path & "\" & "cnvrtwfm.bat"), _
: (File1.Path & "\" & "cnvrtwfm.bat")
:
: ChDir File1.Path 'USER dir
:
: strDOSCOMMAND = "cnvrtwfm.bat -l " & File1.filename
:
: Set wsh = New WshShell
: Set wshExec = wsh.Exec(strDOSCOMMAND)
: STDOutResults = wshExec.StdOut.ReadAll
: 'Copy of command string ("cnvrtwfm.exe -l TEK00009.wfm")
: STDErrResults = wshExec.StdErr.ReadAll
: '"Creating TEK00009.dat" if successful
: '"Error Converting TEK00009.dat" if failure
:
: On Error GoTo KillCNVRTWFMError
: Kill "CNVRTWFM.*" 'Death to both EXE and BATT
:
: If Left(STDErrResults, 5) <> "Error" Then
:
: ' Oddly enough, the TEK converter outputs a text file called .DAT?
: ' This .DAT file needs renamed to .txt - lest it be confused with
: ' a MathCad .DAT file
:
: ' Build string of .DAT filename,
: ' Build string of destination filename (.txt)
: strSource = (Left(File1.filename, (Len(File1.filename) - 4))) &
: ".dat"
: strDest = File1.Path & "\" & NewFileName
:
: On Error GoTo CopyDatToTxtError
: FileCopy strSource, strDest 'Copy .DAT to .TXT
:
: On Error GoTo KillSourceError
: Kill strSource 'Delete the .DAT file
:
: Else
:
: GoTo CNVRTWFM_Error 'Conversion error
:
: End If
: ################################


.



Relevant Pages

  • Re: Internet download
    ... Alot of times the kernel will alolow you to rename a file that is open to to ... the onew exe. ... Public Function GetProcessesAs String() ... Dim uProcess As PROCESSENTRY32 ...
    (microsoft.public.vb.enterprise)
  • Re: VBScript errors with Date?
    ... >I was playing with date functions in VBScript, ... One should *never* use a string representing a date in D M Y order, ... When converting "in detail" to a date string, ...
    (microsoft.public.scripting.vbscript)
  • RC4 StrToHex function
    ... encrypted RC4 string to hex. ... Converting to C# is beyond my skillset at the moment. ... Dim Pos As Long ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Shell Functions and DOS executables
    ... Before you relocate the exe because of the short file name limitation of the ... ByVal lpszShortPath As String, _ ... Dim sShortPath As String ... Reports "Error Converting filename.wfm" if NOT successful ...
    (microsoft.public.vb.general.discussion)
  • Re: Obtaining the variations of product version.
    ... So, if the Make version is set to say 3.2.0, the .exe version ... Private Type VS_FIXEDFILEINFO ... Private Function GetVersion(FileName As String) As String ... Dim lSize As Long ...
    (microsoft.public.vb.general.discussion)