Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

LockFile() - Lock a file to the current process only.


  • Please log in to reply
22 replies to this topic

#1 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 26 March 2012 - 11:25 AM

*
POPULAR

LockFile allows you to lock a file to the current process. This is useful if you want to interact with a specific file but wish to avoid the accidental deletion by another process or worse still a user.

Examples have been provided and any advice for improvements is much appreciated.

UDF:
AutoIt         
#include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: LockFile ; AutoIt Version : v3.3.0.0 or higher ; Language ......: English ; Description ...: Lock a file to the current process only. Any attempts to interact with the file by another process will fail. ; Note ..........: ; Author(s) .....: guinness ; Remarks .......: The locked file handle must be closed with the LockUnlock() function after use. ; =============================================================================================================================== ; #INCLUDES# ========================================================================================================= #include <WinAPI.au3> ; #GLOBAL VARIABLES# ================================================================================================= ; None ; #CURRENT# ===================================================================================================================== ; LockErase: Erase the contents of a locked file. ; LockFile: Lock a file to the current process only. ; LockRead: Read data from a locked file. ; LockReduce: Reduce the locked file by a certain percentage. ; LockWrite: Write data to a locked file. ; LockUnlock: Unlock a file so other processes can interact with it. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; None ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockErase ; Description ...: Erase the contents of a locked file. ; Syntax ........: LockErase($hFile) ; Parameters ....: $hFile               - Handle returned by LockFile. ; Return values .: Success - True ;                  Failure - False, use _WinAPI_GetLastError() to get additional details. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockErase($hFile)     _WinAPI_SetFilePointer($hFile, $FILE_BEGIN)     Return _WinAPI_SetEndOfFile($hFile) EndFunc   ;==>LockErase ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockFile ; Description ...: Lock a file to the current process only. ; Syntax ........: LockFile($sFilePath[, $fCreateNotExist = False]) ; Parameters ....: $sFilePath           - Filepath of the file to lock. ;                  $fCreateNotExist     - [optional] Create the file if it doesn't exist (True) or don't create (False). Default is False. ; Return values .: Success - Handle of the locked file. ;                  Failure - Sets @error to non-zero, call _WinAPI_GetLastError() to get extended error information. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockFile($sFilePath, $fCreateNotExist = False)     Return _WinAPI_CreateFile($sFilePath, BitOR($CREATE_ALWAYS, ($fCreateNotExist ? $CREATE_NEW : 0)), BitOR($FILE_SHARE_WRITE, $FILE_SHARE_DELETE), 0, 0, 0) ; Creation = 2, Access = 2 + 4, Sharing = 0, Attributes = 0, Security = 0. EndFunc   ;==>LockFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockRead ; Description ...: Read data from a locked file. ; Syntax ........: LockRead($hFile) ; Parameters ....: $hFile               - Handle returned by LockFile. ; Return values .: Success - Data read from the file. ;                  Failure - '' and sets @error to non-zero ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockRead($hFile)     Local $iFileSize = (_WinAPI_GetFileSizeEx($hFile) + 1), _             $sText = ''     Local $tBuffer = DllStructCreate('byte[' & $iFileSize & ']')     _WinAPI_SetFilePointer($hFile, $FILE_BEGIN)     _WinAPI_ReadFile($hFile, DllStructGetPtr($tBuffer), $iFileSize, $sText)     Return SetError(@error, 0, BinaryToString(DllStructGetData($tBuffer, 1))) EndFunc   ;==>LockRead ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockReduce ; Description ...: Reduce the locked file by a certain percentage. ; Syntax ........: LockReduce($hFile, $iPercentage) ; Parameters ....: $hFile               - Handle returned by LockFile. ;                  $iPercentage         - A percentage value to reduce the file by. ; Return values .: Success - True ;                  Failure - False, use _WinAPI_GetLastError() to get additional details. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockReduce($hFile, $iPercentage)     $iPercentage = Int($iPercentage)     If $iPercentage > 0 And $iPercentage < 100 Then         Local $iFileSize = _WinAPI_GetFileSizeEx($hFile) * ($iPercentage / 100)         _WinAPI_SetFilePointer($hFile, $iFileSize)         Return _WinAPI_SetEndOfFile($hFile)     EndIf     Return LockErase($hFile) EndFunc   ;==>LockReduce ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockWrite ; Description ...: Write data to a locked file. ; Syntax ........: LockWrite($hFile, $sText) ; Parameters ....: $hFile               - Handle returned by LockFile. ;                  $sText               - Data to be written to the locked file. ; Return values .: Success - Number of bytes written to the file. ;                  Failure - 0 and sets @error to non-zero ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockWrite($hFile, $sText)     Local $iFileSize = _WinAPI_GetFileSizeEx($hFile), _             $iLength = StringLen($sText), _             $iWritten = 0     Local $tBuffer = DllStructCreate('byte[' & $iLength & ']')     DllStructSetData($tBuffer, 1, $sText)     _WinAPI_SetFilePointer($hFile, $iFileSize)     _WinAPI_WriteFile($hFile, DllStructGetPtr($tBuffer), $iLength, $iWritten)     Return SetError(@error, @extended, $iWritten) ; Number of bytes written. EndFunc   ;==>LockWrite ; #FUNCTION# ==================================================================================================================== ; Name ..........: LockUnlock ; Description ...: Unlock a file so other applications can interact with it. ; Syntax ........: LockUnlock($hFile) ; Parameters ....: $hFile               - Handle returned by LockFile. ; Return values .: Success - True ;                  Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func LockUnlock($hFile)     Return _WinAPI_CloseHandle($hFile) EndFunc   ;==>LockUnlock
Example 1: (with LockFile)
AutoIt         
#include <Constants.au3> #include 'LockFile.au3' ; Include the LockFile.au3 UDF. Example_1() ; LockFile by guinness. Func Example_1()     ; Path of the locked file.     Local $sFilePath = @TempDir & '\Example.txt'     ; Lock the file to this process alone and create if not already created.     Local $hLock = LockFile($sFilePath, True)     ; Erase the contents of the locked file.     LockErase($hLock)     ; Write random data to the locked file.     For $i = 1 To 5         LockWrite($hLock, RandomText(10) & @CRLF)     Next     ; Read the locked file.     Local $sRead = LockRead($hLock)     ; Display the contents of the locked file that was just read.     MsgBox($MB_SYSTEMMODAL, '', $sRead)     ; Display the current file size of the locked file. For example 60 bytes.     MsgBox($MB_SYSTEMMODAL, "", _ByteSuffix(_WinAPI_GetFileSizeEx($hLock)))     ; Reduce the file size by 50%.     LockReduce($hLock, 50)     ; Display the reduced size. This will be 50% less than before. For example 30 bytes.     MsgBox($MB_SYSTEMMODAL, "", _ByteSuffix(_WinAPI_GetFileSizeEx($hLock)))     ; Delete the locked file. As this is locked the deletion will fail     MsgBox($MB_SYSTEMMODAL, '', 'Delete the locked: ' & _             @CRLF & _             @CRLF & _             FileDelete($sFilePath) & ' (this will return 0, as the file is currently locked.)')     ; Unlock the locked file.     LockUnlock($hLock)     ; Delete the file as it is now unlocked.     MsgBox($MB_SYSTEMMODAL, '', 'Delete the locked: ' & _             @CRLF & _             @CRLF & _             FileDelete($sFilePath) & ' (this will return 1, as the file is unlocked.)') EndFunc   ;==>Example_1 Func _ByteSuffix($iBytes, $iRound = 2) ; By Spiff59     Local Const $aArray[9] = [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']     Local $iIndex = 0     While $iBytes > 1023         $iIndex += 1         $iBytes /= 1024     WEnd     Return Round($iBytes, $iRound) & $aArray[$iIndex] EndFunc   ;==>_ByteSuffix Func RandomText($iLength) ; Creating random text.     Local $sData = '', $sRandom = ''     For $i = 1 To $iLength         $sRandom = Random(55, 116, 1)         $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65))     Next     Return $sData EndFunc   ;==>RandomText
Example 2: (without LockFile)
AutoIt         
#include <Constants.au3> Example_2() ; Traditional approach to reading and writing to a file. Due to the nature of AutoIt the file isn't locked, thus allowing other processes to interact with the file. Func Example_2()     ; Path of the locked file.     Local $sFilePath = @TempDir & '\Example.txt'     ; Lock the file to this process alone and create if not already created. This is writing mode.     Local $hLock = FileOpen($sFilePath, $FO_OVERWRITE)     ; Erase the contents of the locked file.     FileWrite($hLock, '')     ; Write random data to the locked file.     For $i = 1 To 5         FileWrite($hLock, RandomText(10) & @CRLF)     Next     ; Close the file handle and another handle to read the file contents.     FileClose($hLock)     $hLock = FileOpen($sFilePath, $FO_READ)     ; Read the locked file.     Local $sRead = FileRead($hLock)     ; Display the contents of the locked file that was just read.     MsgBox($MB_SYSTEMMODAL, '', $sRead)     ; Delete the locked file. As this is locked is not locked by AutoIt the file will be deleted.     MsgBox($MB_SYSTEMMODAL, '', 'Delete the locked: ' & _             @CRLF & _             @CRLF & _             FileDelete($sFilePath) & ' (this will return 1, as the file is''t locked by AutoIt due to safety measures in place.)')     ; Unlock the locked file.     FileClose($hLock) EndFunc   ;==>Example_2 Func RandomText($iLength) ; Creating random text.     Local $sData = '', $sRandom = ''     For $i = 1 To $iLength         $sRandom = Random(55, 116, 1)         $sData &= Chr($sRandom + 6 * ($sRandom > 90) - 7 * ($sRandom < 65))     Next     Return $sData EndFunc   ;==>RandomText
All of the above has been included in a ZIP file.
Previous download: 720+ Attached File  LockFile.zip   3.39KB   130 downloads

Edited by guinness, 02 July 2014 - 03:55 PM.

  • Sunaj, James, FireFox and 2 others like this

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014








#2 JScript

JScript

    I'm back ... I miss, why not!

  • Active Members
  • PipPipPipPipPipPip
  • 1,231 posts

Posted 26 March 2012 - 11:55 AM

Excellent!
It was missing a UDF with this ability!
Thanks for sharing.

Regards,

João Carlos.
http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)
Spoiler

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!       


#3 TheSaint

TheSaint

    *** Devil's Advocate ***

  • MVPs
  • 5,937 posts

Posted 26 March 2012 - 12:15 PM

Thanks for sharing.

Make sure brain is in gear before opening mouth! Ignoring those who try to divert conversation with irrelevancies. If I put effort into communication, I expect you to read properly & fully, or just not comment. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox


#4 IRON

IRON

    Seeker

  • Active Members
  • 8 posts

Posted 28 March 2012 - 08:28 AM

this could be very usefull for me.
thanks!

#5 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 28 March 2012 - 08:46 AM

Thanks to everyone who voted, liked and posted a message of thanks here.

I only created it for the forum and not for my personal use as I see the question asked quite a bit around here, but perhaps I will find use for it as well.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#6 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 28 March 2012 - 11:02 AM

I've updated the UDF with fixes to the return values of LockErase & included a new function called LockReduce. Download available in the initial post.

Edited by guinness, 28 March 2012 - 11:03 AM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#7 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 28 March 2012 - 12:17 PM

Thats awesome.... accept my greetings :oops:

Regards
Deltarocked

#8 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 28 March 2012 - 05:54 PM

I might add something similar in the future but for now for those who use WinAPIEx.au3 by Yashied check out the following functions to accompany this UDF. Just pass the handle returned by LockFile() to the functions.

_WinAPI_FileInUse
_WinAPI_GetFinalPathNameByHandle


Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#9 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 29 March 2012 - 08:37 AM

A sample script. Its a culmination of LockFile, WinAPIEx. A lot more things can be done. Basically, wrote this code to test "Unlocker Assistant", which can unlock any locked file.

Why this? well for a small project.

Regards
DeltaRocked

[seems like some issue with fileinuse... testing]

Well I had to download the WinAPIEx by Yashied and reinstalled it (used the installer). now the below script is working fine. and am using the latest version of Autoit v3.3.8.1.


Plain Text         
#cs ---------------------------------------------------------------------------- Functions by Yashied WinAPIEx.au3 _WinAPI_FileInUse, _WinAPI_CreateFileEx #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include "access.au3" #include "array.au3" #include "date.au3" #include "LockFile.au3" #include <WinAPIEx.au3> ; had to download the latest WinAPIEx.au3 AdlibRegister('CheckLock', 200) Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") Global $lockStat = 0 Global $sFilePath = @ScriptDir & 'test.mdb' Global $hLock $hLock = LockFile($sFilePath, 0) $lockStat = 1 LockUnlock($hLock) $lockStat = 0 Sleep(2000) $val = _accessAddRecord($sFilePath, '', 'tran', '|test|10|0|0|' & _Now() & '|0|0', 2) $hLock = LockFile($sFilePath, 0) $lockStat = 1 If $val == 0 Then     SplashOff()     SplashTextOn('', 'successfull', 500, 50, -1, -1, 1)     Sleep(2000)     SplashOff() Else     SplashOff()     SplashTextOn('', 'unsuccessfull ' & @error, 500, 50, -1, -1, 1)     Sleep(5000)     SplashOff() EndIf While 1     ;this loop is used to test unlocker assistant which can unlock locked files.     Sleep(1000) WEnd Exit Func CheckLock()     If _WinAPI_FileInUse($sFilePath) == 0 Then         If $lockStat == 1 Then             $hLock = LockFile($sFilePath, 0)             ConsoleWrite('locked ' & $lockStat & @CRLF)         Else             ConsoleWrite('unlocked by app' & _WinAPI_FileInUse($sFilePath) & $lockStat & @CRLF)         EndIf     EndIf EndFunc   ;==>CheckLock

Edited by deltarocked, 29 March 2012 - 10:15 AM.


#10 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 29 March 2012 - 09:56 AM

Thanks deltarocked, but I'm getting a lot of errors with your code.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#11 DeltaRocked

DeltaRocked

    Prodigy

  • Active Members
  • PipPipPip
  • 186 posts

Posted 29 March 2012 - 10:23 AM

Hi Guinness,

I modified the script (which is now posted in the previous post) and also had to download the latest version of WinAPIEx .

The output of the running script:

Secondly, you will have to create a test.mdb and then execute the addrecord function. I am using a modified version of addrecord (which uses password as one of the parameter) I think in the original UDF password option is not available.

Last but not the least - for a faction of a second the DB is unlocked but you can open the DB in exclusive mode so that it is again inaccessible.


>Running:(3.3.8.1):C:Program FilesAutoIt3autoit3.exe "C:Documents and SettingsDesktopProd_LockNew AutoIt v3 Script.au3"
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
unlocked by app00
locked 1 -----> this happens when I am using unlocker assistant and the file is test.mdb

Plain Text         
Func _accessAddRecord($adSource, $adPwd, $adTable, $rData, $adCol) If Not IsArray($rData) Then   $rData = StringSplit($rData, '|') EndIf $oADO = 'ADODB.Connection' If IsObj($oADO) Then   $oADO = ObjGet('', $oADO) Else   $oADO = _dbOpen($adSource, $adPwd) EndIf If IsObj($oADO) = 0 Then Return SetError(1) If Not IsObj($oADO) Then Return SetError(2, 0, 0) $oRec = _dbOpenRecordset();ObjCreate("ADODB.Recordset") If IsObj($oRec) = 0 Then Return SetError(2) With $oRec   .Open("SELECT * FROM " & $adTable, $oADO, $adOpenStatic, $adLockOptimistic)   .AddNew   If IsArray($rData) Then    For $I = $adCol To $rData[0]     $rData[$I] = StringStripWS($rData[$I], 1) ;~   ConsoleWrite(.Fields.Item($I-1).name &'--'&$rData[$I]&@CRLF)     .Fields.Item($I-1) = $rData[$I]    Next   Else    .Fields.Item($adCol) = $rData   EndIf   .Update   .Close EndWith $oADO.Close() EndFunc   ;==>_accessAddRecord


Func _dbOpen($adSource, $adPwd) $oADO = ObjCreate("ADODB.Connection") $oADO.Provider = $adoProvider If $adPwd <> '' Then $oADO.Properties("Jet OLEDB:Database Password") = $adPwd $oADO.Open($adSource) Return $oADO EndFunc   ;==>_dbOpen


Func _dbOpenRecordset() $oRec = ObjCreate("ADODB.Recordset") Return $oRec EndFunc   ;==>_dbOpenRecordset

Edited by deltarocked, 29 March 2012 - 10:26 AM.


#12 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 29 March 2012 - 12:36 PM

I don't use Access but I'm glad you're using my UDF to your advantage. Any ideas for new functions let me know and I'll see what I can come up with.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#13 forever0donotknowme

forever0donotknowme

    Prodigy

  • PipPipPip
  • 163 posts

Posted 30 March 2012 - 11:26 AM

good script

can you create gui that contain folder open dialog and sub folders or files
after that choise some folder to lock it and another bottun to unlock it

#14 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 30 March 2012 - 12:03 PM

good script

can you create gui that contain folder open dialog and sub folders or files
after that choise some folder to lock it and another bottun to unlock it

This is going beyond the idea of the UDF, but there is nothing stopping you from creating it.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#15 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 20 September 2012 - 10:23 AM

Updated the UDF will only a few cosmetic changes. I also won't be adding _WinAPI_FileInUse or _WinAPI_GetFinalPathNameByHandle, since the latest AutoIt beta/alpha versions contain WinAPIEx.au3, so seems silly to duplicate code that already exists.

Edited by guinness, 20 September 2012 - 10:23 AM.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#16 FireFox

FireFox

    It slips through our fingers, like a fist full of sand.

  • MVPs
  • 5,382 posts

Posted 20 September 2012 - 11:05 AM

Nice UDF, 5*.

Br, FireFox.

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.

Hardware : Intel® Core™ i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Updated 07 November, 2013 - If you find dead links please send me a PM, do not post in the topics !


#17 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 20 September 2012 - 11:40 AM

Cheers FireFox. Much appreciated.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#18 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 16 January 2013 - 12:57 AM

To make it clear, this UDF is for those who want to 'lock' a file to the current process. If you have no idea as to why you would be required to do that, then you don't need this UDF.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#19 nend

nend

    Prodigy

  • Active Members
  • PipPipPip
  • 188 posts

Posted 18 January 2013 - 11:10 AM

Nice script I think I can find a good use for this.

Is this also possible to do it the other way around.
So to unlock a file that is locked?

#20 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,661 posts

Posted 18 January 2013 - 11:15 AM

Not to my knowledge. You would need to do a bit more work to the UDF to 'unlock' a file by another process, like Unlocker.

Search the Forum as some users have tried to create an Unlocker like application.

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users