dshirsh
 New Member Posts:7

 |
| 03 Jan 2008 08:15 PM |
|
Trying to develop a script to go out and close all open files using the filename(or portion thereof) as the search parameter. I had thought that get-process would provide the needed data but I can't seem to get the objects necessary to isolate the filenames. I suspect it's the handles that need walked to find actual file system connections. Am I getting warm here ??? TIA |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 03 Jan 2008 08:18 PM |
|
You could use handle.exe to find the open files, but I am not sure what you mean by close. Can you clarify? |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
dshirsh
 New Member Posts:7

 |
| 03 Jan 2008 08:25 PM |
|
I'm trying to pull this off without using an external executable. When I say close file I mean to break the link between the user who has the file open and the file itself. Basically, I'm trying to accomplish the same thing as if I went into the Computer Management MMC and then into Open Files. |
|
|
|
|
EBGreen
 New Member Posts:64

 |
| 03 Jan 2008 08:34 PM |
|
I would have to think that there would be significant risk for data loss in this. |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 03 Jan 2008 08:47 PM |
|
You realize that the files you see Computer Management are remotely open files right? Is that what your looking for? |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
dshirsh
 New Member Posts:7

 |
| 03 Jan 2008 08:50 PM |
|
Remote files are correct. The nature of the application is such that closing file connections is not an issue. The files are being accessed from a file server so all are remote access. |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 03 Jan 2008 09:04 PM |
|
Maybe I am wrong and hopefully someone will correct me, but I don't think easily do what your wanting. I think handle.exe is your best bet. Why do you want to close these connections? |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
dshirsh
 New Member Posts:7

 |
| 03 Jan 2008 09:08 PM |
|
We have a legacy database application and when we go to run the daily index rebuilds and backup it will fail if there are any open files. We currrently have to manually go in and close the open files that the application uses. After that is done the rebuilds and backup run fine. It's basically a case of a few users who forget to log out and leave their connections active. |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 03 Jan 2008 09:14 PM |
|
I will give people more time to respond to you. If you dont get a better response I will help you use handle.exe |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:335

 |
| 04 Jan 2008 01:21 PM |
|
This is an interesting one. I looked to see what vbscript resources were out there and came acorss this (don't get excited, it doesn't have the solution): http://www.scriptinganswers.com/Archive/articles/CloseopenAccessDB.htm. Further searching shows that this question has been asked time and time again but I don't see any answers. It can be done using 'net file', but I can't seem to find the mechanism that is used so that we can go after that using .NET. |
|
Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast Author, TechProsaic |
|
|
dshirsh
 New Member Posts:7

 |
| 07 Jan 2008 06:33 PM |
|
Caught a blurb where someone in VB was utilizing WMI and using resource.user and resource.path to grab this info to display. Can WMI be used to close the open file links as well? |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 07 Jan 2008 06:39 PM |
|
What WMI class? |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
dshirsh
 New Member Posts:7

 |
| 07 Jan 2008 06:50 PM |
|
Here's a URL to a VB script that allegedly does this. Some users say it doesn't. http://www.microsoft.com/technet/scriptcenter/resources/qanda/feb05/hey0216.mspx Outdated object reference maybe?? |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 07 Jan 2008 06:54 PM |
|
Not outdated, but not WMI either... that references a COM interface. The problem is that you can actuall access that in Powershell but it does not act the same. I am posting an question about this in another group that includes MS dev. |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
dshirsh
 New Member Posts:7

 |
| 18 Jan 2008 07:47 PM |
|
Any luck from the developers side on this issue? |
|
|
|
|
bsonposh
 Basic Member Posts:393

 |
| 18 Jan 2008 07:53 PM |
|
No Luck. I got a response, but it wasnt the one you were hoping for I am sure. I would say you have three options 1) Use a VBScript 2) Use VBScript in Powershell 3) I would guess you could use IronPython in Powershell as well. |
|
Brandon Shell ---------------- Microsoft Powershell MVP https://mvp.support.microsoft.com/profile/Brandon Blog: http://www.bsonposh.com |
|
|
mjolnir
 New Member Posts:12

 |
| 23 Jan 2008 01:17 AM |
|
As an alternative to closing the files, how about logging off the users? If you can find the users that are logged onto the server, you can set the "Enforce logoff when allowed logon hours expire" on the domain, and then script setting the allowed logon hours for those users that are still connected. Once they've been logged off, the files should be closed, and you can re-set the allowed logon hours back to their normal settings, and run your backups. |
|
|
|
|
rbuhrt
 New Member Posts:2

 |
| 07 Feb 2008 04:37 PM |
|
Dim ServerName Dim FileName ServerName = "servername" 'example. fileserver.microsoft.local or fileserver FileName = "local file path" 'example. D:\Group\Users.xls Set objConnection = GetObject("WinNT://" & ServerName & "/LanmanServer") Set colSessions = objConnection.Sessions Set colResources = objConnection.Resources Set Shell = CreateObject("WScript.Shell") On Error Resume Next For Each objResource in colResources If objResource.Path = FileName Then Shell.Run "net files "& objResource.Name & " /close",1,True End If Next |
|
|
|
|
rbuhrt
 New Member Posts:2

 |
| 07 Feb 2008 04:41 PM |
|
The above script I posted will work on Windows 2000,XP,2003.
Define your variables and save it as a vbscript (.vbs) |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:335

 |
|
DyJohnnY
 New Member Posts:1

 |
| 14 May 2008 10:21 AM |
|
Hi all,
Not an expert at this, but why not use psfile utility from Sysinternals to accomplish this?
I've been using this successfully in the past, in our environment. it only works for remote files, just FYI
|
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:335

 |
| 14 May 2008 12:58 PM |
|
Well, this being a powershell forum, we were trying to find the "most native" way to solve the problem. So that means roughly in this order: cmdlet, .NET object, WMI, ADSI, COM, console executable (i.e. psfile). But definitely use what works. It just turns out that for some weird reason there's never been an integrated way to do this. On the other hand, there are much worse fates than being forced to use sysinternals utilities. :) |
|
Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast Author, TechProsaic |
|
|