1
Support and Feedback / Prevent folder from locking
« on: January 12, 2018, 16:56:36 »
Hi! How to prevent a folder from access(move/delete) locking while opened in MC?
MultiCommander v14.2 is released!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
X:\data\exec\!run.exe <--- Our tool. I called it "!run" because I have another program called "run"
X:\data\exec\script1.vbs <---vbs script
X:\data\exec\script2.bat <---batch script
X:\data\exec\mc\MultiCommander.exe
X:\data\exec\firefox\firefox.exe
X:\data\exec\sysinternals\procmon\procmon.exe
And so onfunction GetArgs()
{
@var $args = "";
@var $n;
@var $a;
for( $n = 1; $n < $argcount; $n = $n + 1 )
{
$a = $arg($n);
$args += ' "' + $a + '"';
}
return $args;
}
@var $cmd = GetTagValue("${mcinstallpath}") + "\\..\\!run.exe"; //change this line to your !run.exe path if needed!!!
@var $cmdargs = StrTrimLeft($arg(0), ":") + GetArgs();
if( StrFind($arg(0), ":", 0) == 0 )
MC.Run CMD="{$cmd}" ARG="{$cmdargs}" ADMIN
else
MC.Run CMD="{$cmd}" ARG="{$cmdargs}"
Note that script also allow you to run our tool with Admin rights by prefixing filename with ':'#include <stdint.h>
#include <string.h>
#include <Windows.h>
#include <Shlwapi.h>
#pragma comment(lib, "Shlwapi")
LPWSTR lpCmd;
LPWSTR *szArgList;
#define UNC_PREFIX L"\\\\?\\"
#define MAX_PATH_UNC (INT16_MAX-sizeof(UNC_PREFIX))
int ExecuteFile(const LPWSTR szPath)
{
WCHAR szCurPathUNC[INT16_MAX];
wcscpy(szCurPathUNC, UNC_PREFIX);
LPWSTR szCurPath = szCurPathUNC+4;
if (szPath)
{
if (wcscpy_s(szCurPath, MAX_PATH_UNC, szPath))
return FALSE;
}
else
{
GetModuleFileNameW(GetModuleHandle(NULL), szCurPath, MAX_PATH_UNC);
*wcsrchr(szCurPath, L'\\') = L'\0';
}
PathAddBackslashW(szCurPath);
size_t nLen = wcslen(szCurPath);
if (wcscat_s(szCurPath, MAX_PATH_UNC, szArgList[1]) ||
wcscat_s(szCurPath, MAX_PATH_UNC, L"*"))
return FALSE;
WIN32_FIND_DATAW ffd;
HANDLE hFind = FindFirstFileW(szCurPathUNC, &ffd);
szCurPath[nLen] = '\0';
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
LPWSTR pExt = PathFindExtensionW(ffd.cFileName);
static WCHAR szPathExt[1024];
if (!szPathExt[0])
GetEnvironmentVariableW(L"PATHEXT", szPathExt, sizeof(szPathExt));
PWCHAR buf, pPathExt = wcstok(szPathExt, L";", &buf);
while (pPathExt != NULL)
{
if (_wcsicmp(pExt, pPathExt) == 0)
{
if (wcscat_s(szCurPath, MAX_PATH_UNC, ffd.cFileName))
return FALSE;
PWCHAR pArgs = wcschr(lpCmd, L' ');
if (pArgs != NULL)
pArgs++;
ShellExecuteW(NULL, NULL, szCurPath, pArgs, NULL, SW_SHOW);
return TRUE;
}
pPathExt = wcstok(NULL, L";", &buf);
}
}
} while (FindNextFileW(hFind, &ffd) != 0);
}
if (wcscat_s(szCurPath, MAX_PATH_UNC, L"*"))
return FALSE;
hFind = FindFirstFileW(szCurPathUNC, &ffd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (wcscmp(ffd.cFileName, L".") != 0 && wcscmp(ffd.cFileName, L"..") != 0)
{
szCurPath[nLen] = '\0';
if (wcscat_s(szCurPath, MAX_PATH_UNC, ffd.cFileName))
return FALSE;
if (ExecuteFile(szCurPath))
return TRUE;
}
}
} while (FindNextFileW(hFind, &ffd) != 0);
}
return FALSE;
}
int WINAPI wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
int nArgCount;
szArgList = CommandLineToArgvW(GetCommandLineW(), &nArgCount);
lpCmd = lpCmdLine;
if (nArgCount == 1)
{
MessageBoxW(NULL, L"Usage: run <(beginning of)filename> [args]", L"Error", MB_ICONHAND);
return EXIT_FAILURE;
}
if(!ExecuteFile(NULL))
{
MessageBoxW(NULL, L"File not found", L"Error", MB_ICONASTERISK);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Extension "***" v1.0.0.0 is to old. It is built for Interface version 1.51.0.0. Extension is NOT loaded.
@var $cmdargs = "powershell dir " + GetTagValue("${focusfilepath}") + "-Recurse | Unblock-File";
MC.Run CMD="powershell" arg="{$cmdargs}"
function GetArgs()
{
@var $args = "";
@var $n;
for( $n = 1; $n < $argcount; $n = $n + 1 )
{
$args = $args + " ";
$args = $args + $arg($n);
}
return $args;
}
@var $s = GetTagValue("${mcinstallpath}") + "\\..\\";
$s = $s + $arg(0);
$s = $s + "\\";
$s = $s + $arg(0);
$s = $s + ".exe";
@var $args = GetArgs();
MC.Run CMD="{$s}" ARG="{$args}"
The problem is the script trims double quotemarks splitting "a complex argument" into 3 arguments:run test "a complex argument"
argc = 4So I can't send filepath with spaces
C:\mc\..\test\test.exe
a
complex
argument