Solved

VB, shell and wordpad

Posted on 1997-04-29
7
465 Views
Last Modified: 2012-06-27
       I created a program that creates a file and shells a copy of
wordpad so the the user can edit or print the data. After shelling
wordpad I must return back to processing within the program therefore I
cannot wait until wordpad has finished. If the operator presses this
button again I will again try to create a file and again try to start
wordpad. If the program is run inside of Win3.1 I get an error that I
can trap on but if it run in Win 95 all bets are off!!! 95 actually
allows me to do anything I want with the file but won't tell me that
wordpad is already using it. The problem is that I create the new file
and then try to start a new instance of wordpad. I get no indication
that it didn't work but there is only the original wordpad running with
the original file. Is there some way I can determine if someone is
already using this file in VB4.0 and Win95 so that I could start up
another copy of wordpad possibly with another filename?  Sorry the
description is so long but I wanted to give you as much info as
possible.

0
Comment
Question by:dougdjl
  • 5
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
milton042297 earned 180 total points
ID: 1425800
Use this:
result& = VerInstallFile&(0, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, TmpFile$, lpwTempFileLen%)

"VerInstallFile" is a API function, and "result&" is the return, and you can make a comparation like this:

****************************************************************
If (result& And VIF_FILEINUSE&) = VIF_FILEINUSE& Then
      X% = MsgBox("The file is aready in use, close all the            aplications and try again.", 34)
If X% = 3 Then
       CopyFile = False
ElseIf X% = 4 Then
       TryAgain% = True
       GoTo TryToCopyAgain
ElseIf X% = 5 Then
        CopyFile = True
        GoTo SkipThisFile
End If

*********************************************************

Search in "Win31wh.hlp" help file and Apilod16.exe program on "vb\winapi" directory for more details.

That's all, good luck.
0
 

Author Comment

by:dougdjl
ID: 1425801
I've tried the code and I am unable to load the version.dll in Win95. This function call is not available in Win31. Is this true? Any ideas about why I can't load the dll? It is dated 7-11-95. I get a runtime error 48. If you need the code let me know.
0
 
LVL 1

Expert Comment

by:milton042297
ID: 1425802
use this:
Declare Function VerInstallFile Lib "ver.dll" (ByVal Flags%, ByVal SrcName$, ByVal DestName$, ByVal SrcDir$, ByVal DestDir$, ByVal CurrDir As Any, ByVal TmpName$, lpTmpFileLen&) As Long

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:dougdjl
ID: 1425803
Here's my code. It compiles and runs now(thanks) but it still doesn't tell me if the file (Test.Fil) is in use by wordpad. See if I did anything wrong.

Milton, thanks again for all your help.
p.s. this is only a dummy program. the real one is too much to send.

On a blank form create a text box and a command button.

Declare Function VerInstallFile Lib "ver.dll" (ByVal Flags%, ByVal SrcName$, ByVal DestName$, ByVal SrcDir$, _
                  ByVal DestDir$, ByVal CurrDir As Any, ByVal TmpName$, lpTmpFileLen&) As Long
Public Const VIF_FILEINUSE = &H80&

Function OkToOpenFile(TestFile As String, TestPath As String) As Boolean
Dim lpwTempFileLen As Long
    SrcFilename$ = TestFile
    DestFileName$ = TestFile
    SourcePath$ = TestPath
    DestinationPath$ = TestPath
    CurrDir$ = App.Path

   
    result& = VerInstallFile(0, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, _
                    Tmpfile$, lpwTempFileLen)
    OkToOpenFile = True

    If (result& And VIF_FILEINUSE&) = VIF_FILEINUSE& Then
        X% = MsgBox("The file is aready in use, close all the aplications and try again.", 34)
        OkToOpenFile = False
    End If
End Function

Private Sub Command1_Click()
Dim ExecuteString As String
Dim RetVal As Variant
Dim TestResult As Boolean
Dim TestFile As String
   
    TestFile = "Test.Fil"
    If OkToOpenFile(TestFile, App.Path) Then
        TestFile = App.Path + "\Test.Fil"
        Open TestFile For Output As #1
        Write #1, Text1.Text
        Close #1
        ExecuteString = "Write " + TestFile
        RetVal = Shell(ExecuteString, vbNormalFocus)
    Else
        MsgBox ("File In Use")
    End If

End Sub
0
 
LVL 1

Expert Comment

by:milton042297
ID: 1425804
use the backlask ("\") at the end of the Path string.
ex.:

*********************************************************
Dim Path as string

Path = App.Path
if Right$(Path,1) <> "\" then
    Path = Path + "\"
end if
' now is your code, look the Path variable, is diferent now.

If OkToOpenFile(TestFile, Path) Then
etc
etc
etc
.
.
.
.



0
 
LVL 1

Expert Comment

by:milton042297
ID: 1425805
Hello dougdjl, how did you think about this ?
0
 
LVL 1

Expert Comment

by:milton042297
ID: 1425806
Hello dougdjl, how did you think about this ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now