Programmatically launch sfx archive on Windows 7 (using _execv)? (C++) - c++

My (MS Windows) application can update itself over the internet by download a self extracting archive and launching it via _execv (C++). Now while launching the sfx archive works fine on Windows XP, it doesn't on Windows 7. I guess it has to do with UAC, but even turning UAC off didn't cure this problem. The downloaded sfx archive has the same owner and full access rights as other executables on my computer I can run via _execv. What do I have to do to make this work?

Windows 7 is able to detect installers based on file name and file content and requires additional privilege to start such files. As far as I know Administrator has no such additional privilege. Try to use ShellExecuteEx with runas parameter. It should show you dialog with request for permission to start installer.

Related

How to install custom SNMP extension agent on Windows 10?

I have developed a custom snmp extension agent to work in conjunction with Windows Snmp service. I have implemented in C++ using the interface provided by snmp.h from Microsoft and I am creating a 64 bit dll to be used as extension agent.
To install this dll as extension agent I have added a registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SNMP\Parameters\ExtensionAgents as:
MyAgent REG_SZ SOFTWARE\MyAgent\CurrentVersion
And under HKEY_LOCAL_MACHINE\SOFTWARE\MyAgent\CurrentVersion, I have created another registry specifying the path of the dll as:
Pathname REG_EXPAND_SZ C:\Program Files\testing\MyAgent.dll
When I did this in the system event logs I keep getting that the The SNMP Service is ignoring extension agent dll C:\Program Files\testing\MyAgent.dll because it is missing or misconfigured.
The agent is a trapless agent. It exposes the SnmpExtensionInit and the SnmpExtensionQuery function from snmp.h. I don't know what is messed up. Do I need a 32 bit dll? All of the sources on internet are very old and refer to Windows NT. I need to configure it on newer operating systems like Windows 10 and Windows server 2016. Any suggestions would help.
Also there are similar questions on SO for same error but all of them are related to migration of a 32 bit dll. I am starting with 64 bit.
because the SNMP process is still 32-bit the key needs to be
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6232Node\MyAgent\CurrentVersion
but I am finding the SnmpExtensionInit is not called

How to run external win32 executable (and be able to update / modify it) in Windows UWP app on Windows 10 IOT core?

I have Windows UWP application which will run only on Windows 10 IOT core.
I am the owner of every machine on which it will ever run (so I can make any modification to machine)
The application need to download and run Win32 application.
Solution to run Win32 application is to use ProcessLauncher::RunToCompletionAsync.
Before I add exe to allow list:
reg.exe ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\EmbeddedMode\ProcessLauncher" /v AllowedExecutableFilesList /t REG_MULTI_SZ /d "c:\PATH TO FILE"
This works, Win32 application process is launched properly.
However, this executable is uploaded to Windows 10 IOT core device using Windows Device Portal. The problem rises, when Windows UWP application need to update this Win32 executable.
It works this way: Sometimes Windows UWP app downloads new executable from internet, cancels async task (turns off process) returned by RunToCompletionAsync, and saves new file to the same executable path (from allow list). The problem is that, the exe cannot run. It seems that exe can run when it is saved on machine using Windows Device Portal, but when UWP app saves this on machine itself, then it cannot run.
I came up with other solution, I made intermediary Win32 program, it works like this now:
Windows UWP app launcher launches Win32 intermediary program from path in allow list (this program is uploaded using Windows Device Portal once, and it never changes). Win32 intermediary program has functionality to download executable from internet and save it on disk, then it runs this executable using Win32 API CreateProcess. It works, exe is launched. However, the problem is that the new process cannot save any file to disk (Why?).
What is the solution? How can I download Win32 executable using Windows UWP app, and run it?

ShellExecute Fails if Run from Application Launched as Administrator

My C++ application uses ShellExecute to open a PDF file. I'm using Windows 10 Enterprise LTSC (version 1809, OS build 17763.615) to run my application. If my application is launched as Admin (right-click Run as administrator) then it fails to open the PDF file. However, if my application is launched without Admin rights (just double-clicking it) then Adobe (the default PDF reader) is launched successfully and the PDF is displayed correctly.
My application runs normally (with and without Run as admin) on Windows 7 and Windows 10 Pro. This issue just started happening now that we are trying to use Windows 10 Enterprise LTSC.
The actual code from my application is:
ShellExecute(NULL, NULL, full_path.toWideCharPointer(), NULL, NULL, SW_SHOWDEFAULT);
where full_path is for example equal to "C:\\Faxitron\\Docs\\Guide.pdf".
In both cases (admin or not), ShellExecute always returns 42 and GetLastError returns 0. Here is something interesting: when running my application as Admin, the Task Manager shows 2 processes of Adobe Acrobat Reader DC (32 bit) under my application, but the program Adobe is never launched/opened.
Not sure if this is relevant or not, but I'm using the latest version of Adobe Acrobat Reader DC (version 19.012.20034).
Finally, my application requires to be run as Admin (for other functionality to work properly). Is there a way to get ShellExecute to work when running application as administrator?
The reason why ShellExecute cannot launch the PDF viewer from an elevated process, in this case, is because Adobe Reader is preventing it via its Protected Mode. To solve this issue disable protected mode by doing the following:
Open Adobe Reader.
Choose Edit > Preferences...
In the Categories list on the left, select Security (Enhanced).
In the Sandbox Protections section, deselect Enable Protected Mode at startup
Click OK to save the changes.
Close Adobe Reader.
For more information about Protected Mode (and possible vulnerabilities) refer to this link from Adobe.com:
https://www.adobe.com/devnet-docs/acrobatetk/tools/AppSec/protectedmode.html

Start a RunOnce application with administrator privileges

I have a program which, when installed, gets added to the RunOnce registry in Windows, so that it runs for the first time after Windows gets rebooted post installation.
This application installs a couple of Windows .NETservices using SC Create string passed in _wsystem. Unfortunately it fails to install at least one service..
To eliminate all other conditions, I'd like this application to run as an elevated, privileged user.
This application is in C++. Should I add a manifest or something to achieve this?

Application Cannot Access Mapped Drive

When the application is executed with run as administrator it fails to find files on a mapped network drive using FindFirstFile. If the executable is run without run as administrator is works. The user is a local administrator on the PC. When FindFirstFile fails the error is 3, ERROR_PATH_NOT_FOUND. Is running as an administrator changing access rights or my access to the mapped drive?
I'm testing on a Windows 10 PC with a domain user that is a local administrator. Application was built using VS 2010 on the Windows 10 PC. Application is a native c++ app. I've turned off the firewall, still fails. Turned off Windows Defender, still fails. Recreated share and mapping, still fails. Ideas?
Network drives are mapped per-user. If you map a drive as your user, but run your application as Administrator, the network drive won't be mapped from the application's perspective. To get around this, you can map the drive as Administrator by opening an admin command prompt (right-click cmd -> run as Administrator) and run net use F: \\path\to\my\share.