Why don't QLocalSocket/Server connections work when one process was invoked by an NSIS installer? - qt

I have an NSIS installer that installs my Qt application. At the end of the install process, the installer gives the user the option to launch the application immediately.
My application uses QLocalSocket/QLocalServer to talk to other local instances of the application. (They talk to each other basically just to ensure that there's only one instance of the app running at a time.) However, on Vista, if one of the instances was started up by the installer, then other instances cannot talk to that instance unless they were also started by the installer (or uninstaller, interestingly).
The NSIS installer launches the app with the Exec command. The client tries to connect to the server through QLocalSocket::connectToServer, which fails with the error "QLocalSocket::connectToServer: Unknown error 5".
Can anyone explain this? What's the best way to work around it?

If 5 is a windows error code, it would mean access denied. Is there a way for you to change the security on this server (You would need to access the native pipe handle)?
The finish page run option has more issues than just this, the new process gets the wrong HKCU and user profile etc.
I would recommend just disabling the run checkbox on the finish page. (This issue goes all the way back to win2000 when RunAs was added)
If you really really want this run checkbox, you can use the UAC plugin, it will allow you to start a child process as the "correct" user.

Finally figured this out. The installer was running as admin (the install script said "RequestExecutionLevel admin"), and apparently it launched my app with those elevated permissions, which meant that other instances of my app running with user-level permissions couldn't connect to it. QLocalSocket/Server uses named pipes on windows, so I figure this is a windows security feature. I'm planning to work around this by using the UAC NSIS plugin, which I believe lets you run a process with user-level permissions.

Related

How to create an installer with self updates on windows server for an dotnet core console/service application

I have an application, an aspnet core website 3.0 that is currently running in a console application.
A client is interested in installing it on their internal network.
I am thinking that its best to convert it to a background service and windows can ensure that its running. Following: https://dotnetcoretutorials.com/2019/12/07/creating-windows-services-in-net-core-part-3-the-net-core-worker-way/
What are my options to create an installer for this? Is there anything new out of the box with dotnet core that makes this easy, or should I just go with older "best practice" aka google it to create an installer? Or is it best to just use that sc create TestService BinPath=C:\full\path\to\publish\dir\WindowsServiceExample.exe command to install it.
Author of the blog post here. It really depends on who the target audience is. If it's someone trying to deploy it on an internal network, IMO the SC commands are fine because either
A. It's an IT person installing it anyway so they won't have fear of double clicking a .bat file.
B. The IT team uses some sort of GPO/scripting to keep all machines in line in which case they can surely run a one line command to install it anyway.
An installer is only useful if the end user is non-IT, a customer etc.

windeployqt.exe not working ? Application does not start

I have a simple application using
QT += core gui network webkitwidgets
I've used windeployqt.exe to generate the 32 bits release on my win-10 64 bit computer. When I put the folder on a win-7 64 Bit desktop and double-click the app.exe, it never starts.
I can see it in the task manager, but I can't kill it, and if I try I cannot close the explorer folder in which I double clicked anymore.
I've checked the usual platform, ICU, qwindows.dll, and so on.
http://doc.qt.io/qt-5/windows-deployment.html
EDIT Precisions:
I've compiled with default 32 Bit kit: "build-Test-Desktop_Qt_5_5_1_MinGW_32bit-Release" with "mingw492_32"
I have a package "release" generated by windeployqt.exe using the --webkit switch. I start a command prompt:
> set path=
> set mingw=
Then I make sure that no Qt/Mingw things exists anymore in my environment variables.
I also rename "c:\Qt" into "c:\ __Qt".
I move my release folder on my desktop.
I start release\test.exe ( from the clean path shell )
Everything runs fine! So The release/test.exe has everything it needs without the path/mingw variable.
But as soon as I put the folder on another windows machine ( 7 instead of 10 ) it never starts.
I tried dependency walker. It shows a lot of "API-MS-WIN*.dll" missing...
It even shows much more missing dlls on the "good" machine than on the bad one !!!
Every single "missing dll" on the "bad" target machine is actually in system32 on this machine.
Thanks for advice, every advice is welcome, I'm a bit desperate... :)
Edit
It seems to be related to the machine itself. I have successfully deployed this (very small) app to 2 non developer machine on win7 and win8 respectively. But the above "bad machine" still resits running it...
Edit
The problem seems not to be general but related to this one particular machine. Hence, feel free to close or move to the appropriate forum as it is not related to Qt/windeplyqt. If I figure out a solution, and question is closed, I'll simply add a last edit. Safe Boot and malwarebyte are my next actions.
After a long investigation.
Do not believe dependency walker, it used to be a top notch tool but it is now outdated.
If there is a missing dll, the system will prompt you with "cannot load dll xxx.dll" anyway.
Your best shot in case a soft runs on machine X but not on Machine Y is:
start in safe mode ( run: msconfig --> diagnostic startup )
turn off any antivirus or non microsoft/driver software,
"run as administrator".
If you can run with step 3. Then proceed by elimination:
run without admin rights,
Start anti spyware, etc...
Add appropriate exception to your antivirus if it is the root cause.
If the antivirus is not the root cause, run process monitor on both machines. Then compare, what Failed on one machine and not the other ? Read the windows event log and compare any error messages on both machines.
run sfc /scannow to check disk
run a complete anti spyware scan/ pc-repair tool ( malwarebytes, combofix, ... )
Make sure you really have the very same package on both machines, make sure you are not trying to run an exe on mac OS, make sure your computer is on.
Call the oracle, you are in the matrix...
In my case the problem was Avast and it was solved by adding appropriate exception.

QProcess: Make the process independent & issues with Windows

Well, i have a QProcess that works as my program updater, but on Windows you CAN'T modify exe files when they're running, but if you close the program that created the Updater process i suppose that the Updater closes too. It's possible to make the Updater process independent?
Then, on Windows Vista (and later) it's impossible to run my updater because it returns that i need to elevate my level to administrator, It is possible to elevate the permissions for the process?
First of all, in opposite to Linux, Windows processes are independent from their parents by default and would not be closed after parent process closes.
Right way to solve your problem would be making your updater a Windows service. Then, it wouldn't be launched by application and it will have privileges to write to system folders etc. (see here)
Here is library for services support in Qt (and it actually works).
If you want simpler solution, you can use ShellExecute to escalate privileges to launch your updater.

Adobe AIR NativeProcess - UAC problems when trying to run update installers

I'm trying to use Adobe AIR 2's NativeProcess API to emulate the ApplicationUpdater but I'm encountering problems when I try to run the downloaded AppUpdater.exe file on computers with UAC (User Account Control) enabled.
When run without UAC enabled, the AppUpdater opens as usual and displays the standard Adobe replace dialog box. With UAC enabled, nothing happens at all.
Having run a few traces, it seems the problem arises when I call NativeProcess.start() - the code seems to stop running at this point, and does not run the following lines which exit the application in preparation for the AppUpdater to run.
I have added listeners for all of the possible events and error events that can be thrown, and added logging in each of them, but none of these are producing any output.
This issue only seems to affect installation executables (ones which windows warns will change settings on your computer). Calling java.exe -jar .... on the same computers in the same application works correctly.
I'm at a loss, so any help would be amazing!
After speaking to Adobe directly, I discovered that NativeProcess uses a windows API which is unable to elevate privileges which is why the installers wouldn't work. The workaround was to use File.openWithDefaultApplication which uses a different API that can elevate privileges, but this only works in a native-packaged AIR app (which was just fine for our app since it was already packaged in a native installer :))
adobe answer was http://kb2.adobe.com/cps/404/kb404888.html
but for real steps you should determine the application user privileges and determine UAC enabled, if yes - then warn end-user about it.
I'm expecting that you could do nothing with windows-thing from Adobe Air.

Is it possible to debug IIS without affecting all users of the service?

This may seem like a silly question, but we are having an issue debugging IIS in a shared test environment and I'm hoping that someone out there can give us an answer.
We have a Windows Server 2003 that is running IIS 6 and sharepoint 2007. We are debugging locally on the server with visual studio 2008.
When someone attaches the debugger and steps through the code, we find that all users are affected. In essence the web server stops handling all requests from all users.
Our question is whether this is a typical situation and is to be expected? Or is there some configuration that we can change that would allow the one user's session to be debugged but leave the other's unaffected.
Kev's on the right track. You need to make sure that the project you want to debug separate from the others is in its own application pool. This will isolate it to its own process and allow that process to be stopped/debugged without affecting the other applications which can remain in a different pool.
Setup
Start -> Run -> inetmgr
Right Click on Application Pools
Click New -> Application Pool
Name the new pool
Right Click on the application you want to isolate
Click Properties
Click on the Home Directory tab
In the application pool drop-down list select your new pool
Click OK
If there are any requests queued in the old process, they may take a few minutes to terminate before all requests are being diverted to the new process.
Debugging
To figure out which instance of w3wp.exe you need to attach the debugger to:
Start -> Run -> cmd
Type iisapp
You may be prompted to register CScript, if so click yes and run it again
The only gotcha you may still find is that if multiple applications are using the aspnet_state service you may run into blocking issues if you need to debug that process as well.
Links
MSDN
Developer.com
"When someone attaches the debugger
and steps through the code, we find
that all users are affected. In
essence the web server stops handling
all requests from all users."
This is normal, once you attach a debugger to a process such as inetinfo.exe or w3wp.exe and set a break point, every request/thread will be blocked until you allow the debugger to continue, until the next break-point.
I've never found a way around it. Is there some reason you can't debug on each developer's workstation?
Set up a parallel project on the server and try using that. You could use debug.mydomain.com and then just use that for testing. The only reason that I personally can think of to debug on your live servers is if there is a significant difference in the functioning of your app due to either hardware or software configuration.
Ideally you want to have a separate server/instance of your system in as similar an environment as possible so that you don't have to debug on your live machine. Also you might want to consider writing all errors to the event log or at least checking the log since asp.net usually get logged there. This way you can see where your errors are and use that to help you solve your problem in the development environment.
I believe in visual studio you can set the debugger to break only the process being debugged, and not all the processes. Depending on how your system is set up, YMMV with this.
It can't be changed AFAIK. But that's a normal practice to set up separate web-node or web-application for development/debugging purposes. If that's necessary to know exact values of some vars in certain situations you can always use debug logging.

Resources