michaelslamet Posted July 23, 2013 Share Posted July 23, 2013 Let say I have a network file myservermyfoldermyfile.exe mapped as R:myfoldermyfile.exe This folder is shared and myfile.exe is accessed by many computers at the same time. I would like to delete the file but cant do it when it's running at any computers. How to know if that file is still opened on any computers on the network? Impossible to know? Link to comment Share on other sites More sharing options...
orbs Posted July 23, 2013 Share Posted July 23, 2013 (edited) _Net_Share_FileEnum() may come in handy. edit: in conjunction with _Net_Share_FileGetInfo(), if you need specific details. Edited July 23, 2013 by orbs michaelslamet 1 Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
guinness Posted July 23, 2013 Share Posted July 23, 2013 FileDelete will return 0. I would search the term 'shared file in use' on google or such-like. michaelslamet 1 UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Author Share Posted July 23, 2013 Wow, what a fast response! Thanks Orbs! Thanks Guinness! I was thinking that is not possible, now i know that I'm wrong Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 23, 2013 Moderators Share Posted July 23, 2013 (edited) Here is a snippet I use, just to show you another way. Will show who is using the file: Edit - forum is hating me this morning, won't let me post code for some reason. See below in plain text. $aSessions = $server.Resources For $element in $aSessions If $element.Path <> "" Then MsgBox(0, "", "Path: " & $element.Path & @CRLF & "User: " & $element.User) Next Edited July 23, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
guinness Posted July 23, 2013 Share Posted July 23, 2013 I presumed you weren't using a server, seems I was mistaken. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Author Share Posted July 23, 2013 Here is a snippet I use, just to show you another way. Will show who is using the file: Edit - forum is hating me this morning, won't let me post code for some reason. See below in plain text. $aSessions = $server.Resources For $element in $aSessions If $element.Path <> "" Then MsgBox(0, "", "Path: " & $element.Path & @CRLF & "User: " & $element.User) Next Thanks JLogan Could you please give more complete code for that? Because I have no idea what file need to be included and where $server come from Link to comment Share on other sites More sharing options...
michaelslamet Posted July 23, 2013 Author Share Posted July 23, 2013 I presumed you weren't using a server, seems I was mistaken. Not really a "server", just a network shared. Is that make any different for JLogan's snippet? Link to comment Share on other sites More sharing options...
orbs Posted July 23, 2013 Share Posted July 23, 2013 Not really a "server", just a network shared. Is that make any different for JLogan's snippet? i just took a look inside _Net_Share_FileEnum(), i expected to see a WMI call but i found a DllCall to local netapi32.dll, which means that it should work on network shares that don't have to be hosted on Windows servers - so Linux-hosted shares (i.e. most common storage devices) should be supported. i didn't check this, but if you have, as you say, Not really a "server", then what do you have? and if it's not a Windows server, can you check to tell us if it works? or has anyone else tried it already? Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 23, 2013 Moderators Share Posted July 23, 2013 (edited) Sorry, it seems that the forum hates me today, keeps stripping my code. Let's see if this gets through: Edit: Not sure why it is eating all my code today. Here is plain text: $aSessions = $server.Resources - Array of open files in used through Shared Folders area of System Management For $element in $aSessions If $element.Path <> "" Then MsgBox(0, "", "Path: " & $element.Path & @CRLF & "User: " & $element.User) - Cycle through array and output any for which the path is not empty Next Edit: Ah, screw it, forum does not like the first line in the script - see attached TestForumScripts.au3 Edited July 23, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
michaelslamet Posted July 26, 2013 Author Share Posted July 26, 2013 _Net_Share_FileEnum() may come in handy. edit: in conjunction with _Net_Share_FileGetInfo(), if you need specific details. I seems can not get this to work Running code below (taken from help file) always bring result: Error ...................: 0 Entries read ............: 0 Tried with WINXP machine/share and FreeBSD. Any ideas? expandcollapse popup#include <GUIConstantsEx.au3> #include <NetShare.au3> #include <WindowsConstants.au3> Global $iMemo _Main() Func _Main() Local $sServer, $aInfo ; Create GUI GUICreate("NetShare", 400, 300) ; Create memo control $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 296, $WS_VSCROLL) GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New") GUISetState() ; Get server and share information $sServer = InputBox("NetWork Demo", "Enter Server Name:", "\\MyServer", "", 200, 130) If @error Then Exit ; Enumerate open files on the server $aInfo = _Net_Share_FileEnum($sServer) MemoWrite("Error ...................: " & @error) MemoWrite("Entries read ............: " & $aInfo[0][0]) For $iI = 1 To $aInfo[0][0] MemoWrite("Resource ID .............: " & $aInfo[$iI][0]) MemoWrite("Resource permissions ....: " & _Net_Share_PermStr($aInfo[$iI][1])) MemoWrite("Resource locks ..........: " & $aInfo[$iI][2]) MemoWrite("Resource path ...........: " & $aInfo[$iI][3]) MemoWrite("Resource user ...........: " & $aInfo[$iI][4]) MemoWrite() Next ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ; Write message to memo Func MemoWrite($sMessage = "") GUICtrlSetData($iMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite Link to comment Share on other sites More sharing options...
michaelslamet Posted July 26, 2013 Author Share Posted July 26, 2013 (edited) Sorry, it seems that the forum hates me today, keeps stripping my code. Let's see if this gets through: Edit: Not sure why it is eating all my code today. Here is plain text: $aSessions = $server.Resources - Array of open files in used through Shared Folders area of System Management For $element in $aSessions If $element.Path <> "" Then MsgBox(0, "", "Path: " & $element.Path & @CRLF & "User: " & $element.User) - Cycle through array and output any for which the path is not empty Next Edit: Ah, screw it, forum does not like the first line in the script - see attached TestForumScripts.au3 I run the TestForumScripts.au3 and it display this error: C:UsersMSDesktopscriptsTestForumScripts.au3 (2) : ==> Variable must be of type "Object".: $aSessions = $server.Resources $aSessions = $server^ ERROR This is the code edit: seems i cant get this code to be displayed too, just like JLogan so I attached it here $aSessions = $server.Resources For $element in $aSessions If $element.Path <> "" Then MsgBox(0, "", "Path: " & $element.Path & @CRLF & "User: " & $element.User) Next Yes, I change the "myserver" string on line 1 to actual server name Edited July 26, 2013 by michaelslamet Link to comment Share on other sites More sharing options...
orbs Posted July 26, 2013 Share Posted July 26, 2013 (edited) Houston, we have a problem. ObjGet method the script suggested by JLogan3o13 has it's first line thus: edit: now i can't submit a tagged code too... never mind, this is it: edit2: what the... no code in body of post? ok, so download the thing and see the first line. unless i'm dreadfully mistaken, it looks for a WinNT object on a BSD server. no wonder it can not work. for now i abandon this trail. _Net_Share_FileEnum() function the comment in the help file for _Net_Share_FileEnum() says: Only members of the Administrators or Server Operators local group can execute this function to my testing, it seems this is wrong (although - or because - it's copied from MSDN). the word local is not correct. i can get this function working only by RunAs a server administrator on the remote Windows server (did not try on non-Windows server). PsFile external utility PsTools package has the program PsFile, which gives the same result: works when user has admin rights on remote server, "Access Denied" in any other case. these are preliminary results, i will now put some research into it, as i thought of using this feature in one of my scripts, now i see i 'll be facing a brick wall if&when i get to it on my script, so i better crash my head against it right now. if anyone has some insights on this issue, please share. updates to follow, orbs edit3: meanwhile, to focus on the original purpose, you can call FileMove() on the suspected file. if success, then file is not locked. although, if it fails, this will not give you any identification of the machine/process locking the file. Edited July 26, 2013 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted July 26, 2013 Moderators Share Posted July 26, 2013 Agreed, would have been good to know the OS's involved up front, as I wouldn't expect the code I provided to work on a FreeBSD machine. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
michaelslamet Posted July 27, 2013 Author Share Posted July 27, 2013 Agreed, would have been good to know the OS's involved up front, as I wouldn't expect the code I provided to work on a FreeBSD machine. Yes, I'm sorry for that I thought that will not make any different because they're using same protocol (SMB). Anyway, I'm trying to connect to WinXP share, same error message. Link to comment Share on other sites More sharing options...
michaelslamet Posted July 27, 2013 Author Share Posted July 27, 2013 Houston, we have a problem. ObjGet method the script suggested by JLogan3o13 has it's first line thus: edit: now i can't submit a tagged code too... never mind, this is it: edit2: what the... no code in body of post? ok, so download the thing and see the first line. unless i'm dreadfully mistaken, it looks for a WinNT object on a BSD server. no wonder it can not work. for now i abandon this trail. _Net_Share_FileEnum() function the comment in the help file for _Net_Share_FileEnum() says: Only members of the Administrators or Server Operators local group can execute this function to my testing, it seems this is wrong (although - or because - it's copied from MSDN). the word local is not correct. i can get this function working only by RunAs a server administrator on the remote Windows server (did not try on non-Windows server). PsFile external utility PsTools package has the program PsFile, which gives the same result: works when user has admin rights on remote server, "Access Denied" in any other case. these are preliminary results, i will now put some research into it, as i thought of using this feature in one of my scripts, now i see i 'll be facing a brick wall if&when i get to it on my script, so i better crash my head against it right now. if anyone has some insights on this issue, please share. updates to follow, orbs edit3: meanwhile, to focus on the original purpose, you can call FileMove() on the suspected file. if success, then file is not locked. although, if it fails, this will not give you any identification of the machine/process locking the file. Unfortunetely, I cant use FileMove() or FileDelete() for this purpose, because what I'm trying to do is applying self update, so I cant FileMove or FileDelete the script itself Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now