Reading Files when application launch at startup - c++

I recently created a c++ program for windows that when is launched, it reads some files that store the user configurations, if it is the first time the program runs, it store the options the user set and create the files. When I am debugging it in visual studio it works as expected.
So I proceded to create a setup for installation, I used Inno Setup. My program requiered to start at launch so I use the following code, this is from the inno website http://www.jrsoftware.org/iskb.php?startwithwindows. My problem is that when the programs start at launch these files are not read or created, but if I close the program and I launch the program using the desktop Icon it reads and creates de files.
So my question is there something in the Inno script that allows it to read the files? could be a problem with the fstream class?, could there be a code solution
Thanks in advance.
I followed Michael advice and I used the APPDATA folder with Roaming subfolder, and now the program read the config files and run as expected, thanks for the help!!.

From above comments, you say you are storing the configuration files in the same folder as the .exe, and your application is able to create the files when run from Visual Studio, but not when installed to the "Program Files (x86)" folder or C:/ root.
It sounds like you are running into UAC (User Access Control) permissions issues. The "Program Files (x86)" folder at least, and I believe C:/ (root) as well, require administrator privileges to write. This was not the case with Windows XP and older; it is with modern versions. You may be running Visual Studio as administrator and not know it, and allowing administrator privileges when you install, but the application is not then run as administrator so it cannot write to those locations.
Try running your (installed) application as administrator (right-click the file and select "Run as administrator"). If it works, there you go: you either have to run it as administrator always if you want it to be able to store configuration files in the same directory as the .exe, or else (much better solution) store your configuration files in an appropriately-named subdirectory of %APPDATA%, which the user running your application will always be able to write to without administrator privileges.

Related

Windows service not showing up

I have a windows service project that I inherited and need to migrate it to a new server. I have made changes to some code, and so I created a new setup project in VS 2017. I added the .exe of the service to the set up package, and rebuilt both the service and the setup projects. When I run the .msi it seems to complete installation but when I look in the Windows Services list it's not there. What am I missing?
Any help is greatly appreciated. Thanks!
The installer probably didn't run the installutil.exe program.
You can do this manually by dropping to a command prompt then navigating to the location that the installer put the .exe file. From there run this:
installutil.exe myservice.exe
where myservice is the exe file you generated.
For more information:
https://learn.microsoft.com/en-us/dotnet/framework/tools/installutil-exe-installer-tool
Also, you might need to add the installutil.exe path. It's part of the .net framework and will be found in that install directory.

Run AHK script as admin on startup

I have four AHK scripts which run on startup, as they have shortcuts placed in my startup folder. How can I make them run as admin?
What I've tried:
I've tried changing their properties to be run as admin, but they just don't run (when I do that).
I've tried changing their shortcuts' properties to be run as admin, but they too just don't run (when I do that).
I've looked at this reddit post on the topic, but I don't know how to implement that code in the scripts.
I've tried creating a basic C++ application which runs them with system("start path\\to\\script"), but it wouldn't compile.
In case it matters, the scripts in question are ahk-active-screenshot, CtrlAlt_Switch.ahk, Kill.ahk, and a modified version of this search script.
You can allow the script to automate administrative programs without running as admin, here're the required steps:
When installing AHK, check the "Add 'Run with UI Access' to context menus" option.
After installation, find AutoHotkeyU64_UIA.exe on your disk.
Open the .ahk script's properties, change the "Open with" option to the AutoHotkeyU64_UIA.exe you just found.
Create a shortcut to this script.
Open %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in the file explorer.
Move that shortcut to this folder.
And you're done.
How does it work?
The "Add 'Run with UI Access' to context menus" option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs without running as admin.
Reference: Run with UI Access.
Find the UIA version of autohotkey on your machine. For me it is at C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe.
In your startup folder, create a new shortcut (probably one for each of the scripts you want) as follows (replacing paths as appropriate):
Target: "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" "D:\path\to\script.ahk"
Start in: "C:\Program Files\AutoHotkey"
This launches your script as an admin using the UIA version of AHK on startup.

How to create custom action to change file permission

I am working on a windows based c++ application. I have created the installer for this project using Visual Studio 2012. This project also has some configuration files, which are copied intothe installation folder(c:\program files\). When the application starts, one log file is also created in this installation directory.
Now the problem is when I install the application on a windows 7 system, which has admin rights, everything works fine. But, when I install this on a system, which does not have admin rights, that neither my application is able to read the config file present in the current directory, nor the log file gets generated.
How can I set/change the permission of this installation directory during the instllation, so that I can modify/read the config file and also log file gets created.
You need to decide if you want your application to have administrator privileges or not, because only an app with administrator privileges can modify/read the config file and create log file in a sub-directory of "Program Files".
If you are OK with this, then create an app that will open an UAC prompt when it is started, which request administrator privileges. To do this, open project property pages and go to "Linker->Manifest File", then set the value of "UAC execution level" to requireAdministrator. On the other hand, if you consider this to be an overkill, I suggest you change your app to create a directory in user folder. This folder will be used to store config file and log file. The most common approach is to create a folder in C:\Users\some_user\AppData\Local.
Please note that I would suggest the latter approach, there is no need to give an app administrator privileges just to keep config and log file in "Program Files". However, I am not familiar enough with your application, maybe an UAC prompt is a better solution. That is up to you to decide.

remote debugging windows 8.1 driver Visual studio 2013

I'm trying to set up remote debugging on Visual studio 2013.
I think I installed everything on my computer and the hyper-v machine too + updated.
So whats happening:
I open a microsoft UMDF driver sample. (I can build it without any errors).
I select Debugging tools for windows remote debugger.
Then a message box pops up named Deployment not configured.
I select I know what I'm doing continue debugging.
Then the Computer configuration wizard starts add new computer.
I select provision computer and automatically configure debuggers.
Then the configuration process configure my hyper-v machine fine.
Installs the necessary files restart the computer and log in with the name WDKRemoteUser.
Then I Click Finish then this error pop-up.
The required property 'DbgengRemoteCommand' is missing or empty. (OK)
So I need to fill up the package property pages->configuration properties->debugging->
Remote Command, Remote Command Arguments, Remote Working Directory, Remote Computer name manually?
And if I had to what should I write there or I miss something else?
You only need to specify the "Remote Working Directory" parameter and you can just give it the same path as your build directory and you should be good.

vs 2008 deployment project not working

I have a C++ console application that I want to deploy using a vs2008 setup project. When I create the setup project and add the output from my console app, the setup project detects that it needs MSVCP90.dll and MSVCR90.dll. When I build the project, those two dlls are included in the .msi file as expected.
When I download and launch the installer, everything goes as expected and the console app and the dlls are unpacked into the proper directory on the local machine.
When I try and run the app, I get the following error:
Error 1721. There is a problem with
this Windows Installer package. A
program required for this install to
complete could not be run. Contact
your support personnel or package
vendor.
I've tried compiling the app with /MT and /MD neither one works.
When I run a dependency walker against the app, it reports that it needs MSVCP90.dll and MSVCR90.dll as expected.
Finally, if I set the installer to require the Visual C++ runtime libraries, it downloads them and everything works fine.
Obviously, I would like to avoid downloading the CRT libraries.
Thanks for any help,
Jon
Check out this example on how to add the appropriate merge modules and deploy them to your target machine along with your setup.