mirror of
https://github.com/kimmknight/remoteapptool.git
synced 2025-10-10 17:38:10 +00:00
Check if file is locked or not and present to end user if it is locked and by what.
Resulted in breaking some of my habits and putting a messagebox windows in libraries. Not my favorite thing, but it works. This helps debug issue 3, it does not resolve issue 3. To test it - open an office document (such as Word or Excel) and try to overwrite the office document with the RDP file including the office document extention (xls, xlsx, doc, docx, etc). The application will tell you that the file is locked, locked by Word/Excel/etc and the PID that is locking it just in case you have multiple copies of the application that is locking it open. A lot of the code was borrowed from Microsoft (https://code.msdn.microsoft.com/windowsapps/How-to-know-the-process-170ed5f3/sourcecode?fileId=151114&pathId=1558127374).
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
Public Class RDPFile
|
||||
Imports System.Windows.Forms
|
||||
Imports LockChecker
|
||||
|
||||
Public Class RDPFile
|
||||
Public administrative_session As Integer = 0
|
||||
Public allow_desktop_composition As Integer = 0
|
||||
Public allow_font_smoothing As Integer = 0
|
||||
@@ -76,7 +79,23 @@
|
||||
Public winposstr As String = "0,3,0,0,800,600"
|
||||
|
||||
Public Sub SaveRDPfile(FilePath As String, Optional SaveDefaultSettings As Boolean = False)
|
||||
My.Computer.FileSystem.WriteAllText(FilePath, GetRDPstring(SaveDefaultSettings), False)
|
||||
Dim LockCheck As New LockChecker.LockChecker()
|
||||
Dim FileLocked As String
|
||||
Dim SkipFile As Boolean = False
|
||||
FileLocked = LockCheck.CheckLock(FilePath)
|
||||
While Not (FileLocked = "No locks")
|
||||
If (MessageBox.Show("The file " + FilePath + " is currently locked. Lock information:" + FileLocked + vbNewLine + "Do you want to try again?", "File Locked", MessageBoxButtons.YesNo) = DialogResult.Yes) Then
|
||||
FileLocked = LockCheck.CheckLock(FilePath)
|
||||
Else
|
||||
MessageBox.Show("The following file will not be copied:" + vbNewLine + FilePath)
|
||||
SkipFile = True
|
||||
FileLocked = "No locks"
|
||||
End If
|
||||
End While
|
||||
If Not (SkipFile) Then
|
||||
|
||||
My.Computer.FileSystem.WriteAllText(FilePath, GetRDPstring(SaveDefaultSettings), False)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Function GetRDPstring(Optional SaveDefaultSettings As Boolean = False)
|
||||
|
@@ -46,6 +46,7 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -100,6 +101,12 @@
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LockChecker\LockChecker.vbproj">
|
||||
<Project>{029C010D-728B-4B87-B54A-08B2BBF49BD7}</Project>
|
||||
<Name>LockChecker</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
Reference in New Issue
Block a user