Application updater
-
Hello!
I write a simple application autoupdater.
Updater is located in: C:\Program Files (x86)\Corp\Prod\updater.exe
It started and downloaded new executable file to: C:\Program Files (x86)\Corp\Prod\my_qt_application.exe
But it fails to save with "No permissions" error.
How I can ride this? How I can ask user to take an administrators permissions?
-
Hi,
You should rather ask this question on a Microsoft forum, you'll have more chance to get a useful answer there.
As a side note, are you sure you want to develop your own solution ? There already exists several frameworks to do that, KDAB's KDTools and WinSparkle comes to mind.
Hope it helps
-
Hi,
starting with Vista it's tricky for for normal apps to write files in C:\Program Files or C:\Program Files (x86), only installers are allowed to do that.
Maybe you can try saving your executable in C:\Users\JohnDoe\AppData\Roaming instead, like Minecraft or WoW do.
Rgrds Henry
-
KDTools - seems have very bad support, and I found many compilation errors ..
WinSparkle - not providing update mechanism, only forward clients to the web site.
I need update my exe file only, and need a most simple solution.
[quote author="SGaist" date="1375561276"]Hi,
You should rather ask this question on a Microsoft forum, you'll have more chance to get a useful answer there.
As a side note, are you sure you want to develop your own solution ? There already exists several frameworks to do that, KDAB's KDTools and WinSparkle comes to mind.
Hope it helps[/quote]
[quote author="hskoglund" date="1375562663"]Hi,
starting with Vista it's tricky for for normal apps to write files in C:\Program Files or C:\Program Files (x86), only installers are allowed to do that.
Maybe you can try saving your executable in C:\Users\JohnDoe\AppData\Roaming instead, like Minecraft or WoW do.
Rgrds Henry
[/quote]I will try to do this.
-
Hi hskoglund,
I have the same error whet I store my executables in "User's personal data folder"..
-
Hi, You can use this to check whether you are running with elevated permissions:
@
bool isElevated()
{
bool result = false;
HANDLE hToken = NULL;if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) { TOKEN_ELEVATION elevation; DWORD dwSize; if(GetTokenInformation(hToken, TokenElevation, &elevation, sizeof(elevation), &dwSize)) result = elevation.TokenIsElevated != 0; CloseHandle(hToken); } return result;
}
@
and if not, restart your updater asking user for elevation:
@
void restartElevated()
{
wchar_t fileName[MAX_PATH];
wchar_t workingDir[MAX_PATH];
qApp->applicationFilePath().toWCharArray(fileName);
QDir::currentPath().toWCharArray(workingDir);SHELLEXECUTEINFO shex = {0}; shex.cbSize = sizeof(SHELLEXECUTEINFO); shex.lpVerb = L"runas"; shex.lpFile = fileName; shex.lpDirectory = workingDir; shex.nShow = SW_NORMAL; ::ShellExecuteEx(&shex); qApp->closeAllWindows(); //or however you want to exit
}
@
To use these you need to link to shell32 and advapi32.
Just remember to check first if the update is really available and don't bother user if you're not gonna need the extended permissions. -
Hey Chris Kawa, thanks for the information !
IIRC you've already provided several windows related neat tips and tricks like that one, did you consider making a Wiki page with them ? :)
-
you may find "this thread":https://qt-project.org/forums/viewthread/28600 also interesting.
-
Hi Chris Kawa,
could you please help me again? I tried the solution and it works but sometimes the following error appears:!http://i020.radikal.ru/1308/71/dc886dd13fe4.png(error)!
I translate: "Unable to find "D:/Dropbox/...", Check file name and try again."
Seems something wrong with '\0'?
-
I add the following lines:
@fileName[QApplication::applicationFilePath().length()] = '\0';
workingDir[QDir::currentPath().length()] = '\0';@now it works fine, thanks! :)
-
Yeah, sorry. I mixed and matched some scraps from my old code and forgot to zero out the arrays.
Glad you fixed it.