mirror of
https://github.com/kimmknight/remoteapptool.git
synced 2025-10-09 08:58:08 +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:
@@ -100,11 +100,27 @@ Public Class RDPSign
|
||||
End If
|
||||
If CreateBackup Then
|
||||
Dim BackupFile = System.IO.Path.GetDirectoryName(RDPFileLocation) & "\" & System.IO.Path.GetFileNameWithoutExtension(RDPFileLocation) & "-Unsigned.rdp"
|
||||
System.IO.File.Copy(RDPFileLocation, BackupFile, True) 'backup file with overwrite
|
||||
Dim LockCheck As New LockChecker.LockChecker()
|
||||
Dim FileLocked As String
|
||||
Dim SkipFile As Boolean = False
|
||||
FileLocked = LockCheck.CheckLock(BackupFile)
|
||||
While Not (FileLocked = "No locks")
|
||||
If (MessageBox.Show("The file " + BackupFile + " is currently locked. Lock information:" + FileLocked + vbNewLine + "Do you want to try again?", "File Locked", MessageBoxButtons.YesNo) = DialogResult.Yes) Then
|
||||
FileLocked = LockCheck.CheckLock(BackupFile)
|
||||
Else
|
||||
MessageBox.Show("The following file will not be copied:" + vbNewLine + BackupFile)
|
||||
SkipFile = True
|
||||
FileLocked = "No locks"
|
||||
End If
|
||||
End While
|
||||
If Not (SkipFile) Then
|
||||
System.IO.File.Copy(RDPFileLocation, BackupFile, True) 'backup file with overwrite
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
'If we get here, we should be good to run the command to sign the RDP file.
|
||||
Dim Command As String = GetSysDir() & "\rdpsign.exe"
|
||||
'If we get here, we should be good to run the command to sign the RDP file.
|
||||
Dim Command As String = GetSysDir() & "\rdpsign.exe"
|
||||
If My.Computer.FileSystem.FileExists(Command) Then
|
||||
Dim Arguments As String
|
||||
Dim FileVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(Command)
|
||||
|
@@ -103,5 +103,11 @@
|
||||
<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" />
|
||||
</Project>
|
Reference in New Issue
Block a user