Hey all.
I have been researching this problem and am basically coming up empty. I need to do in code what Unlocker essentially does as an app...That is, remove a lock on a folder that has been locked by some other application. For instance, Photoshop will not lock a file name for a file that is opened, but it WILL lock the containing folder path.
I looked into using a simple lock/unlock example in vb.Net using:
'Lock:
Dim fs As FileSystemSecurity = File.GetAccessControl(PathName_edit.Text)
fs.AddAccessRule(New FileSystemAccessRule(Environment.UserName, _
FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(PathName_edit.Text, fs)
'-----------------------------------------------------------------------------
'Unlock:
Dim fs As FileSystemSecurity = File.GetAccessControl(PathName_edit.Text)
fs.RemoveAccessRule(New FileSystemAccessRule(Environment.UserName, _
FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(PathName_edit.Text, fs)
Unfortunately, it only works in a limited sense in that so long as you lock the folder yourself, you can unlock it. But it does not seem to be able to steal control from another app that owns the folder. That seems to me to be something a bit more lower level like an API solution or something. So I went to my win32 references and they are weak on NTFS security topics. Googling this problem only brings up the standard approach above, and a slew of links to little apps that do it for you, but nothing on what is actually happening that makes it possible. I get the impression it is not a simple call, but maybe something that uses SendMessage() or SetWindowsHook() as part of the trick to intercept the messages sent between the owner app and the resource.
I have been researching this problem and am basically coming up empty. I need to do in code what Unlocker essentially does as an app...That is, remove a lock on a folder that has been locked by some other application. For instance, Photoshop will not lock a file name for a file that is opened, but it WILL lock the containing folder path.
I looked into using a simple lock/unlock example in vb.Net using:
Quote:
'Lock:
Dim fs As FileSystemSecurity = File.GetAccessControl(PathName_edit.Text)
fs.AddAccessRule(New FileSystemAccessRule(Environment.UserName, _
FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(PathName_edit.Text, fs)
'-----------------------------------------------------------------------------
'Unlock:
Dim fs As FileSystemSecurity = File.GetAccessControl(PathName_edit.Text)
fs.RemoveAccessRule(New FileSystemAccessRule(Environment.UserName, _
FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(PathName_edit.Text, fs)