QT application with admin privileges can't edit text file on startup - qt

I have created an application that is designed to startup, complete a form on my university website to allow access through the proxy for applications like google drive and steam (lel). It accesses a text file in the program directory to obtain the username and password (encrypted obviously). I've made it run on startup by adding it to the startup programs in the registry.
WINDOWS 7 WORKS PERFECTLY.
Here is what happens IN WINDOWS 8.1:
*Opening it from explorer manually, the program works as expected, accessing the username and password and automatically logging in. Running as admin also works perfectly.
*Allowing it to run on start up causes the program to give an error saying it can't read/write the file with the password in it, making me have to manually enter the username and password in. All folders/file in the program directory are all read/write enabled.
*Giving the program administrator rights by including a manifest file when compiling (has the UAC logo on the icon, so I know it has worked) or giving it admin rights via the .exe properties - opening it manually from explorer works perfectly, however on startup it won't even start the application.
Does anyone know the reason for my observations?
Registry command:
QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
settings.setValue("BorderAuth.exe", QCoreApplication::applicationFilePath().replace('/','\\'));
BorderAuth.exe.manifest:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0"
processorArchitecture="X86"
name="BorderAuth"
type="win32"/>
<description>Opens and closes the border of the network</description>
<!-- Identify the application security requirements. -->
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="requireAdministrator"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
.rc file:
IDI_ICON1 ICON DISCARDABLE "icon_blue.ico"
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "BorderAuth.exe.manifest"
.pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets webkitwidgets
TARGET = BorderAuth
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
settings.cpp
HEADERS += mainwindow.h \
settings.h
FORMS += mainwindow.ui \
settings.ui
RESOURCES += \
icons.qrc
RC_FILE = icon.rc
Thanks!

Related

Qt Installer InstallerApplicationIcon does not appear on Installer

I have created a qt installer and I am trying to set some icons on it,
Working on linux with the InstallerApplicationIcon I have managed the application logo to be displayed on each of Installer's page but building the same installer on Windows the Icon does not appear. I have tried several solutions with .ico or .bmp files but I have not managed to make it work
I found that in Windows 'InstallerApplicationIcon' without filename extension, but 'InstallerWindowIcon' needs it.
I have tried it on windows and it worked for me.
Inside my config directory I have two files Coffee.ico and document.png. The Coffee.ico is shown in the explorer for the installer icon, whereas the document.png is shown on every installer page on the top.
My config.xml basically looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>Your application</Name>
<Version>1.0.0</Version>
<Title>Your application Installer</Title>
<InstallerApplicationIcon>Coffee</InstallerApplicationIcon>
<InstallerWindowIcon>Document.png</InstallerWindowIcon>
</Installer>
Here is what I'll see:

Is it possible to use Qt VS Tools to work on a cross-platform project and have it automatically keep project changes synced in a .pro file?

I am trying to understand what the intended workflow is when using Qt VS Tools to develop a cross-platform application. If I have per-platform options in the .pro file, does that mean that I must manually keep the .pro file in sync with the .vcxproj file when working on Windows not using Qt Creator?
For example, I have set up a test project and implemented a little desktop application using Qt VS Tools. I can now select "Create Basic .pro File" from the Qt VS Tools extension menu. This will create the following .pro file which I can build and run from Qt Creator:
TEMPLATE = app
TARGET = TestQt
DESTDIR = ../x64/Debug
QT += core gui widgets
CONFIG += debug
DEFINES += _UNICODE _ENABLE_EXTENDED_ALIGNED_STORAGE WIN64 QT_DLL QT_WIDGETS_LIB
INCLUDEPATH += ./GeneratedFiles \
. \
./GeneratedFiles/$(ConfigurationName)
DEPENDPATH += .
MOC_DIR += ./GeneratedFiles/$(ConfigurationName)
OBJECTS_DIR += debug
UI_DIR += ./GeneratedFiles
RCC_DIR += ./GeneratedFiles
include(TestQt.pri)
Now say however I want to make the project have some platform-specific dependency. As an example say I add the following before "include(TestQt.pri)" in the above -- but this could be any kind of manual edit to the .pro file.
windows {
SOURCES += WindowsSpecific.cpp
}
This will work in Qt Creator but I would have to manually add the new file in Visual Studio. If I now add something platform agnostic in Visual Studio and rebuild the .pro file via the same extension menu item, I will lose anything that I manually added to the .pro file like the include of WindowsSpecific.cpp above.
So is the intention that I create a .pro file once and from then on manually edit the .pro file to keep it in sync with the Visual Studio project or is there some automatic way that I am missing.
I think there is no good way to do this.
A better workflow that solves the general issue, though, is to work in the reverse direction: add files and make project changes only through QtCreator / in the .pro file and when the project file changes sync Visual Studio by re-generating the .sln file with by opening the .pro file in Visual Studio via Extensions/Qt VS Tools/ Open Qt Project File.

QT framework installer - how to force targetDir

I would like to force my targetDir directory installation usign QT Installer Framework v. 3.0.
Currently this is my config.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Installer>
<Name>QSSWeb2Board</Name>
<Version>1.0.0</Version>
<Title>QSSWeb2Board</Title>
<Publisher>BQ Educacion</Publisher>
<ProductURL>https://bitbloq.bq.com</ProductURL>
<InstallerWindowIcon>bitbloq</InstallerWindowIcon>
<InstallerApplicationIcon>bitbloq</InstallerApplicationIcon>
<Logo>bitbloq.png</Logo>
<StartMenuDir>Bitbloq</StartMenuDir>
<TargetDir>C:/QSSWeb2Board</TargetDir>
</Installer>
It works well, but I can modify the target dir on the installer. I would like to set a fixed value that cannot be modified.
Self-solution:
On the installer script, adding this line:
currentPage.TargetDirectoryLineEdit.enabled = false;
Try to use installer.setDefaultPageVisible(QInstaller.TargetDirectory, false)
as in http://doc.qt.io/qtinstallerframework/qt-installer-framework-systeminfo-packages-root-meta-installscript-qs.html . Since the default page for the choice of the install directory will not be shown thus, the install directory path will not be modified.

Run the Qt application as administrator on Windows

Is there a way I can run the Qt application as an administrator? I have an auto-updater for my application. It needs administrator privileges to replace the files in Program Files folder and hence it requires administrator privileges.
Running your application with administrator privileges does not have a whole lot to do with Qt. There are two approaches.
The "simple" one is to manually set your application to run with administrator privileges. You can do so by right-clicking on the executable. Then on the "Compatibilty" tab, you can choose to "Run this application as an administrator" under "Privilege level".
However, if you automatically want to achieve the same, you will have to embed a manifest into your application. What you're looking for is to set the requestedExecutionLevel to requireAdministrator. A bit more information can be found on MSDN or in this Wikipedia entry on UAC.
For your application as built in Qt Creator, it means you will need to embed the manifest by including a reference to it in a Resource (.rc) file. This resource file can then be added to your .pro file by specifying RC_FILE = myapp.rc. An informative blog post on this very issue is this one, as well as this post on the QtCentre forum.
A very simple solution for this, if you're using MSVC toolkit, is to add the following into the project file:
QMAKE_LFLAGS_WINDOWS += "/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\""
I am using Qt 5.12 msvc2017.
I've found this to be quite neat, as from what I see in generated Makefile, Qt is already adding some manifest related link flags, and this approach wouldn't interfere with already embedding manifest, as manually adding manifest from existing file.
Other manifest link options can be easily added. You can read the docs for VS compiler, and/or you can check what flags/options Visual Studio IDE has to offer in Project properties/Linker/Manifest File and then check Command Line section of the Linker to see how it adds them.
Not sure how would this be done in gcc or clang builds, it would probably require solutions provided by #H Aßdøµ, and #Bart.
From the article that referred to Mr #Bart:
Application Manifest
First, we have to prepare an application manifest file. This one below is for application that does not require administrator rights:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="2.0.2.0" processorArchitecture="X86" type="win32"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Second, we need the MT.exe tool from the Microsoft Windows SDK to embed this XML in our executable. To do it use the following command:
mt.exe –manifest MyApp.exe.manifest -outputresource:MyApp.exe;1
Automatic Manifest Embedding
Manually executing the mt command after each compilation is a tedious task. What about convincing qmake to do it for us? After studying the docs it looks like the following line should do the trick:
win32 {
WINSDK_DIR = C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A
WIN_PWD = $$replace(PWD, /, \\)
OUT_PWD_WIN = $$replace(OUT_PWD, /, \\)
QMAKE_POST_LINK = "$$WINSDK_DIR/bin/x64/mt.exe -manifest $$quote($$WIN_PWD\\$$basename(TARGET).manifest) -outputresource:$$quote($$OUT_PWD_WIN\\${DESTDIR_TARGET};1)"
}
The above code will automatically execute the mt.exe program from WINSDK_DIR and embed a manifest file that is located in the project root directory and named after project's target (ie. MyApp.manifest). That's all to adding a manifest, now let's move on and specify the version information.
Orginal post: http://blog.strixcode.com/2010/08/embedding-application-manifest-and.html

where does qtcreator with cmake store run and build settings, and how to set via script?

In my usage at least, I sometimes delete my CMake build folder and create a new one, or have multiple build folders (one per computer) but only one source folder (nfs mount).
From what I can tell, QT Creator saves settings into CMakeLists.txt.user inside the source tree, and some others settings into the 'project.cbp' file in the build folder. If I set settings from the GUI, they are lost after wipe/create build folder. Fair enough, but I'd like to use a script to set them up again when a new build is made.
So, how do I:
a) make QT Creator write the CMakeLists.txt.user folder somewhere other than the source tree so that machine-specific settings are kept (e.g. debug on the development computer, release on the test computer) ?
b) read/write the build and run settings from QT Creator project, such as debug arguments for each executable and extra build commands (e.g. -j8) ?
Then I would do something like "execute_process( ... )" in CMakeLists.txt to set some debug and build arguments for the QT Creator project.
Ah, actually the command args, build settings, and related items are set in the CMakeLists.txt.user from QTCreator...
for example:
<valuemap key="ProjectExplorer.Target.RunConfiguration.1" type="QVariantMap">
<value key="CMakeProjectManager.BaseEnvironmentBase" type="int">2</value>
<value key="CMakeProjectManager.CMakeRunConfiguation.Title" type="QString">matching_test</value>
<value key="CMakeProjectManager.CMakeRunConfiguration.Arguments" type="QString">camera.pklogitech.yml 0 .</value>
so the args that are used are " camera.pklogitech.yml 0 . " for this binary's entry...
So I guess a script could be made to go in and set those values by default... too bad QT Creator doesn't provide a nicer interface to import them.

Resources