summaryrefslogtreecommitdiff
path: root/shared/ShadowCopy/LockFile.cpp
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:09 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:11:09 +0200
commit9cc790869ed3905c78c7eeeb0bb44f800b3f2af4 (patch)
tree1c085bbf2302be294866c4fc6e0d225f8abbc346 /shared/ShadowCopy/LockFile.cpp
parent3.14 (diff)
downloadFreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.tar.gz
FreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.tar.bz2
FreeFileSync-9cc790869ed3905c78c7eeeb0bb44f800b3f2af4.zip
3.15
Diffstat (limited to 'shared/ShadowCopy/LockFile.cpp')
-rw-r--r--shared/ShadowCopy/LockFile.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/shared/ShadowCopy/LockFile.cpp b/shared/ShadowCopy/LockFile.cpp
new file mode 100644
index 00000000..0761a3e3
--- /dev/null
+++ b/shared/ShadowCopy/LockFile.cpp
@@ -0,0 +1,44 @@
+// **************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
+// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
+// **************************************************************************
+//
+
+#include <string>
+#include <iostream>
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+
+int wmain(int argc, wchar_t* argv[])
+{
+ if (argc <= 1)
+ {
+ std::wcout << "Please enter the filename to be locked as %1 parameter!" << "\n\n";
+ system("pause");
+ return -1;
+ }
+ std::wstring filename = argv[1];
+
+ //obtain exclusive lock on test file
+ HANDLE hFile = ::CreateFile(filename.c_str(),
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_BACKUP_SEMANTICS,
+ NULL);
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ std::wcout << "Error obtaining exclusive lock on test file: " << filename << "\n\n";
+ system("pause");
+ return -1;
+ }
+
+ std::wcout << "File " << filename << " is locked! Press a key to unlock." << "\n\n";
+ system("pause");
+
+ ::CloseHandle(hFile);
+ return 0;
+}
+
bgstack15