Das Notes Forum

Domino 9 und frühere Versionen => Entwicklung => Thema gestartet von: Zsolt_Hermann am 10.04.02 - 11:55:18

Titel: Windows Programme über die API starten
Beitrag von: Zsolt_Hermann am 10.04.02 - 11:55:18
Hallo Leute,

wir haben eine selbstgestrickte ProjectDB im Einsatz. Diese funktioniert ganz gut nur habe ich da ein Problem mit dem Aufruf von anderen Programmen.

Also in einen Listenfeld speichere ich den UNC Pfad zu einer/(mehreren  Datei(en) beliebigen Typs (doc, xls, txt . . .). Jetzt soll der User die Möglichkeit haben diese Datei per Anwahl und Knopfdruck zu öffnen. Temporär habe ich die "Shell"-Lösung (siehe unten) eingesetzt, da habe ich aber das Problem, das wenn ein anderer User die Datei bereits offen hat, kann der zweite User Sie nicht öffnen Fehlermeldung "The process cannot access the file because it is being used by another process.".
Alles klar, logisch wenn die Datei bereits geöffnet ist sollte man sie auch nicht mehr ein zweites mal im Edit - Modus öffnen. Wenn man aber über Word, Excel usw. eine Datei das zweitemal versucht zu öffnen bekommt man die Meldung das jemand anderes die Datei bereits im EditModus offnen hat und man kann nur im Lesemodus zugreifen.

Kennt jemand eine Lösung für das Problem? Eine Suche im Forum auf Anwendung öffnen über API brachte keinen Erfolg.

Danke für Eure Hilfe.

Gruß Zsolt Hermann

Shell-Lösung:

Sub Click(Source As Button)
     
     On Error Goto ErrHandler
     
     Dim fileObj As String
     Dim ws As New NotesUIWorkspace
     Dim doc As NotesUIDocument
     Dim taskID As Integer
     
     Set doc = ws.Currentdocument
     FileObj =  Trim(Strright(doc.FieldGetText("JobDokumentReferences"), "]"))
     If FileObj <> "" Then
           FileObj = {Cmd.EXE /K "Start "" "} + FileObj + {"&&Exit"}
           taskID = Shell(fileObj , 2)
           doc.Save
     Else
           Messagebox "You has'nt select a file!", 0, "Info"
     End If
     
Finish:
     Exit Sub
     
ErrHandler:
     Messagebox Error(), 0, "Error"
     Exit Sub
End Sub
Titel: Re: Windows Programme über die API starten
Beitrag von: Axel am 10.04.02 - 13:01:02
Hi,

ich hab in meinem Fundus was gefunden. Es ist nicht ganz genau was du brauchst, aber vielleicht kannst du Teile daraus verwenden oder anpassen.

Zitat
Start one or all attachments with the appropriate file extension executable, using shell32.dll.

Declare Function SleepEx Lib "kernel32" Alias "SleepEx" (Byval
dwMilliseconds As Long, Byval bAlertable As Long) As Long
Declare Function ShellExecute Lib "shell32.dll" Alias
"ShellExecuteA" (Byval hwnd As Long, Byval lpOperation As String,
Byval lpFile As String, Byval lpParameters As String, Byval
lpDirectory As String, Byval nShowCmd As Long) As Long

Function ExtractAndView(Doc As NotesDocument)
     On Error Goto ErrorExtractAndStartAttchments
     If Doc.HASEMBEDDED = True Then
            Forall eItem In Doc.ITEMS
                   If (eItem.Type = Clng(RICHTEXT))  Then
                         If Not (Isempty(eItem.EMBEDDEDOBJECTS)) Then
                                Forall  fItem In eItem.EMBEDDEDOBJECTS
                                      If fItem.Type = EMBED_ATTACHMENT Then
                                             Call fItem.EXTRACTFILE( "C:\Temp" & fItem.Name)
                                            ret = ShellExecute(handle&, "open", "C:\Temp" & fItem.Name, "", "", 1&)
                                             xx = SleepEx (4000,0)
                                             Doevents
                                                'Exit Forall ' Only First attachment
                                      End If
                                End Forall
                          End If
                   End If
            End Forall
     End If
ExitExtractAndStartAttchments:
            Exit Function
ErrorExtractAndStartAttchments:
            Msgbox ("in ExtractAndView: " + Error$(Err))
            Resume ExitExtractAndStartAttchments
End Function


Gruss
Axel
Titel: Re: Windows Programme über die API starten
Beitrag von: eknori am 10.04.02 - 13:14:30
Ich denke, das ist nicht DAS Problem.

Wenn du ein Dokument, das schon geöffnet ist noch einmal öffnen willst, wirst du das nicht über den Shell befehl hinbekommen, da du als Parameter nicht mitgeben kannst, daß Word das Doc schreibgeschützt öffnen soll.
Ich denke du mußt da so etwas wie CreateObject verwenden. Ich habe schon gesucht, aber in der VBA Hilfe von Winword noch nichts gefunden.

Eine andere Möglichkeit, die du hast, ist , den Zugriff auf das Doc gänzlich zu verwehren, solange es noch von einem anderen User geöffnet ist.

Ich habe dazu etwas "fremden" Code in meiner DB gefunden. der Code ist ursprünglich für Visual Basic.


--------------------------------------------------------------------------------
Modules: Determining who has Word Doc file open
--------------------------------------------------------------------------------
 

   In order to determine whether a Word document is currently opened by an user, we can try to open the file in code with lock rights.  If our code fails to gain an  exclusive lock on the file, a runtime error will be generated allowing us to conclude that the file is currently opened somewhere else.

'*********** Code Start **********
Function fIsDocFileOpen(ByVal strDocFileName As String) As Boolean
'*******************************************
'Name:      fIsDocFileOpen (Function)
'Purpose:   Checks to see if the Word document is already open
'Author:     Dev Ashish
'Date:        February 11, 1999, 05:50:58 PM
'Called by:  Any
'Calls:       None
'Inputs:      strDocFileName: Full path to the Word document
'Output:     True if file is open, false otherwise
'*******************************************
On Error GoTo ErrHandler
Dim intFree As Integer
  intFree = FreeFile()
  Open strDocFileName For Input Lock Read As intFree
  fIsDocFileOpen = False
ExitHere:
  On Error Resume Next
  Close #intFree
  Exit Function
ErrHandler:
  fIsDocFileOpen = True
  Resume ExitHere
End Function
'*********** Code End **********
   By following the same technique of opening the file in code, we can also determine the loginId of the user who has the Word document open.

   Microsoft Word creates a temporary file whose name is the same as the original file, but with ~$ as the leading two characters.  This file contains the loginid of the user who has the Doc file open.  We can open this temporary file in shared mode and retrieve the username.

'*********** Code Start **********

Function fWhoHasDocFileOpen(ByVal strDocFile As String) As String
'*******************************************
'Name:      fWhoHasDocFileOpen (Function)
'Purpose:   Returns the network name of the user who has
'              strDocFile open
'Author:     Dev Ashish
'Date:        February 11, 1999, 07:28:13 PM
'Called by: Any
'Calls:       fFileDirPath
'Inputs:      strDocFile - Complete path to the Word document
'Output:     Name of the user if successful,
'               vbNullString on error
'*******************************************
On Error GoTo ErrHandler
Dim intFree As Integer
Dim intPos As Integer
Dim strDoc As String
Dim strFile As String
Dim strExt As String
Dim strUserName As String

 intFree = FreeFile()
 strDoc = Dir(strDocFile)
 intPos = InStr(1, strDoc, ".")
 If intPos > 0 Then
   strFile = Left$(strDoc, intPos - 1)
   strExt = Right$(strDoc, Len(strDoc) - intPos)
 End If
 intPos = 0
 If Len(strFile) > 6 Then
   If Len(strFile) = 7 Then
     strDocFile = fFileDirPath(strDocFile) & "~$" & _
       Mid$(strFile, 2, Len(strFile)) & "." & strExt
   Else
     strDocFile = fFileDirPath(strDocFile) & "~$" & _
       Mid$(strFile, 3, Len(strFile)) & "." & strExt
   End If
 Else
   strDocFile = fFileDirPath(strDocFile) & "~$" & Dir(strDocFile)
 End If
 Open strDocFile For Input Shared As #intFree
 Line Input #intFree, strUserName
 strUserName = Right$(strUserName, Len(strUserName) - 1)
 fWhoHasDocFileOpen = strUserName
ExitHere:
 On Error Resume Next
 Close #intFree
 Exit Function
ErrHandler:
 fWhoHasDocFileOpen = vbNullString
 Resume ExitHere
End Function

Private Function fFileDirPath(strFile As String) As String
'Code courtesy of
'Terry Kreft & Ken Getz
Dim strPath As String
 strPath = Dir(strFile)
 fFileDirPath = Left(strFile, Len(strFile) - Len(strPath))
End Function

'*********** Code End **********


Titel: Re: Windows Programme über die API starten
Beitrag von: Silvio am 19.04.02 - 10:50:36
Hi Leute, ich hab auch noch was. Quelle: http://www.keysolutions.com/
Ein wenig abändern und sollte dann auch funktionieren.

Public Type STARTUPINFO
 cb As Long
 lpReserved As String
 lpDesktop As String
 lpTitle As String
 dwX As Long
 dwY As Long
 dwXSize As Long
 dwYSize As Long
 dwXCountChars As Long
 dwYCountChars As Long
 dwFillAttribute As Long
 dwFlags As Long
 wShowWindow As Integer
 cbReserved2 As Integer
 lpReserved2 As Long
 hStdInput As Long
 hStdOutput As Long
 hStdError As Long
End Type

Public Type PROCESS_INFORMATION
 hProcess As Long
 hThread As Long
 dwProcessID As Long
 dwThreadID As Long
End Type

Declare Function WaitForSingleObject Lib "kernel32" (Byval _
 hHandle As Long, Byval dwMilliseconds As Long) As Long

Declare Function CreateProcessA Lib "kernel32" (Byval _
 lpApplicationName As Long, Byval lpCommandLine As String, Byval _
 lpProcessAttributes As Long, Byval lpThreadAttributes As Long, _
 Byval bInheritHandles As Long, Byval dwCreationFlags As Long, _
 Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long, _
 lpStartupInfo As STARTUPINFO, lpProcessInformation As _
 PROCESS_INFORMATION) As Long

Declare Function CloseHandle Lib "kernel32" (Byval _
 hObject As Long) As Long

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&

Public Sub ShellAndWait(Byval RunProg As String)
 ' From Kevin Pauli (kcpauli@usa.net)
 Dim RetVal As Long
 Dim proc As PROCESS_INFORMATION
 Dim StartInf As STARTUPINFO
 StartInf.cb = Len(StartInf)
 'Execute the given path
 RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&, _
 NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)

 'Disable this app until the shelled one is done
 RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
 RetVal = CloseHandle(proc.hProcess)
End Sub

Titel: Re: Windows Programme über die API starten
Beitrag von: Zsolt_Hermann am 25.04.02 - 13:11:32
Super hat soweit funktioniert.

DANKE

Zsolt Hermann

;D ;D ;D ;D ;D ;D ;D ;D 8) 8) 8)