Hello,initially I wanted to test a scriipt on a Windows Server 2003, but since I don't have the environment to do, I want to run it on two virtual Windows 7 machines.The script code below, running as a logon script, should check if the file stored in the variable $fileName is open on the other machine. In case it's true a popup box should open to brief a user on the other machine that the file is open.
I'm pretty unsatisfied because something is wrong with the script. Would anybody kindly help me please? Maybe I'm completey wrong.I think I miss the forrest for the trees.
Thank you very much!
Chris
$fileName = "\\server\netlogon\testfile.txt"$file = New-Object -TypeName System.IO.FileInfo -ArgumentList $fileName$ErrorActionPreference = "SilentlyContinue"[System.IO.FileStream]$fs = $file.OpenWrite();if ($?) { #file open =true $msg = New-Object -ComObject WScript.Shell $msg.Popup("File $filename is open and you are not permitted to edit!", 5, "Message", 0) } else { #file open = false $fs.Dispose() $msg="Accessible to write" $msg}
Using openwrite() will only work for the machine the file is on. My testing shows it doesn't work across a UNC path
Thank you!
Could you give me a hint how to realize what I intend to do please?
I've got an idea that I'll try out tomorrow and let you know