1217
// Launch a second instance of the updater with the runas verb on Windows
1218
// when write access is denied to the installation directory.
1220
NS_tchar updateLockFilePath[MAXPATHLEN];
1221
NS_tsnprintf(updateLockFilePath, MAXPATHLEN,
1222
NS_T("%s/update_in_progress.lock"), argv[3]);
1224
// The update_in_progress.lock file should only exist during an update. In
1225
// case it exists attempt to remove it and exit if that fails to prevent
1226
// simultaneous updates occurring.
1227
if (!_waccess(updateLockFilePath, F_OK) &&
1228
NS_tremove(updateLockFilePath) != 0) {
1229
fprintf(stderr, "Update already in progress! Exiting\n");
1233
HANDLE updateLockFileHandle;
1234
updateLockFileHandle = CreateFileW(updateLockFilePath,
1235
GENERIC_READ | GENERIC_WRITE,
1239
FILE_FLAG_DELETE_ON_CLOSE,
1242
NS_tchar elevatedLockFilePath[MAXPATHLEN];
1243
NS_tsnprintf(elevatedLockFilePath, MAXPATHLEN,
1244
NS_T("%s/update_elevated.lock"), argv[1]);
1246
if (updateLockFileHandle == INVALID_HANDLE_VALUE) {
1247
if (!_waccess(elevatedLockFilePath, F_OK) &&
1248
NS_tremove(elevatedLockFilePath) != 0) {
1249
fprintf(stderr, "Update already elevated! Exiting\n");
1253
HANDLE elevatedFileHandle;
1254
elevatedFileHandle = CreateFileW(elevatedLockFilePath,
1255
GENERIC_READ | GENERIC_WRITE,
1259
FILE_FLAG_DELETE_ON_CLOSE,
1262
if (elevatedFileHandle == INVALID_HANDLE_VALUE) {
1263
fprintf(stderr, "Unable to create elevated lock file! Exiting\n");
1267
PRUnichar *cmdLine = MakeCommandLine(argc - 1, argv + 1);
1269
CloseHandle(elevatedFileHandle);
1273
SHELLEXECUTEINFO sinfo;
1274
memset(&sinfo, 0, sizeof(SHELLEXECUTEINFO));
1275
sinfo.cbSize = sizeof(SHELLEXECUTEINFO);
1276
sinfo.fMask = SEE_MASK_FLAG_DDEWAIT |
1277
SEE_MASK_FLAG_NO_UI |
1278
SEE_MASK_NOCLOSEPROCESS;
1280
sinfo.lpFile = argv[0];
1281
sinfo.lpParameters = cmdLine;
1282
sinfo.lpVerb = L"runas";
1283
sinfo.nShow = SW_SHOWNORMAL;
1285
BOOL result = ShellExecuteEx(&sinfo);
1289
WaitForSingleObject(sinfo.hProcess, INFINITE);
1290
CloseHandle(sinfo.hProcess);
1294
LaunchCallbackApp(argv[3], argc - 4, argv + 4);
1296
CloseHandle(elevatedFileHandle);
1215
1301
gSourcePath = argv[1];
1230
1316
if (gSucceeded && argc > 4)
1231
1317
LaunchWinPostProcess(argv[4]);
1318
CloseHandle(updateLockFileHandle);
1319
// If elevated return early and let the process that launched this process
1320
// launch the callback application.
1321
if (!_waccess(elevatedLockFilePath, F_OK) &&
1322
NS_tremove(elevatedLockFilePath) != 0)
1234
1326
// The callback to execute is given as the last N arguments of our command