Fosco
Fri Feb 13 09:22:24 CST 2004
"Barry Brown"
> I'm not sure if a function indicates whether the file is in use or not.
> This appears to be causing the error - Distiller is still using the file
copied from here :
http://groups.google.com/advanced_group_search
www.google.com
http://www.allmyfaqs.com/faq.pl?How_to_post
Alexander Mueller wrote:
> in order to share resources in 'mutually exclusive'
> manner Windows uses Mutex-kernelobjects among others. For
> Windows 98 there was a tiny ActiveX-Dll "AMutex.Mutex"
>
http://pragmaticlee.safedataisp.net/ -> testmutex.zip
> which enables use of muteces for WSH on this Platform.
> It doesnt' seem to work for me on XP.
> Does anyone know another mutex/semaphore
> wrapper for XP?
Hi
I use a file lock technique for this, that way you don't need to use any 3rd
party component at all. If the script that has locked the file (created the
mutex) crashes, the lock will automatically be removed (mutex will be
released).
Const ForAppending = 8
' file that will be locked
sLckFile = "k:\script.lck"
Set oFSO = CreateObject("Scripting.FileSystemObject")
bUpdFinished = False
iLoops = 0
On Error Resume Next
Do
' open for appending
Set f = oFSO.OpenTextFile(sLckFile, ForAppending, True)
If Err.Number = 70 Then
'Permission denied error
' Waiting 1/2 a second before trying again
WScript.Sleep 500
ElseIf Err.Number <> 0 then
WScript.Echo "Unexpected Error #: " & Err.Number
bUpdFinished = True
Else
On Error GoTo 0
' do the job here, the file will now be locked by this script and
' nobody else will be able to continue until the f.Close instruction
'below is run...
' close the file so others can be able to continue
f.Close
bUpdFinished = True
End If
Err.Clear
Loop Until bUpdFinished
On Error GoTo 0
--
torgeir
'| Is there a way, with WSH and perhaps ADSI, to look at a particular file
'and
'| see if it is currently open? Ideally I would like to know who has it open,
'| but just knowing it is really open would get me what I really need.
'Assuming that you know that you have no permission issues with the file, an
'old scripting workaround (I think I got it from one of Torgeir Bakken's
'posts) is to open the file for append, error-trapped, and test for error 70
'(permission denied). It's only kicked up for permission and in-use issues.
'Coarse, but works fine for local computer usage. (air code)
'---
set oFso= createobject("scripting.fileSystemObject")
on error resume next
sfile="C:\TEST.txt"
set oFile= oFso.openTextFile(sfile, 8, false)
nErr= err: sErr= err.description: err.clear
oFile.close
on error goto 0
select case nErr
case 0: msgbox "File is not in use."
case 70: msgbox "File is in use."
case else: msgbox "Error: " & nErr & vbCr _
& sErr
end select
'---
'Joe Earnest
Or run distiller and wait for close
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])
bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the
next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code
returned by the program. If set to false (the default), the Run method returns immediately after starting the program,
automatically returning 0 (not to be interpreted as an error code).
set oShell = CreateObject("WScript.Shell")
oShell.run"calc",1,true
' run Acrobat Distiller
msgbox "closed"
'wait close
'run your outlook stuff
or
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("notepad")
Do While oExec.Status = 0
WScript.Sleep 10
Loop
WScript.Echo "status" &" >>>"& oExec.Status &" " &"Closed"
--
Fosco