Different processes are using same xml file - c++

I wrote mfc c++ console application. This Application is using "a dll" and this dll use one "xml file" for store some datas.
I need multiple process for my design and also I can start multiple process from my application at the start time with "Windows Service Application".They are running as a "System Process".They work nice.
Normally if my application runs as a user process,XML File is created in same directory with process. But If it runs as System process, XML File is created in "C:\Windows\SysWOW64" folder by dll. So all processes are using same xml file.
Problem is Dll wasn't written by me so i cant change anything on it. Can i do something for this?
My OS is "Windows Server 2008 R2"
thnx in advance

During installation of service, you can set command line parameter for example: -directory c:\MyAppFolder. In your application get this parameter and change working directory by SetCurrentDirectory method. Dll you are calling creates xml file in working directory, which will be c:\MyAppFolder. If you create more services make sure each of them has unique directory.

Related

Get the config folder of a third-party Click-Once application

Currently I am messing around with a Click-Once WPF application. That application is some third-party application that was not developed by me. I also do not have access to its sources.
It is run on a Windows server periodically and automatically (using a self made launcher written in standard C++) by executing the corresponding *.appref-ms link that was placed in the start menu path on installation of the application. This works fine.
Due to periodically arising problems with that application my launcher needs to wipe all configuration files before starting it so I get a well defined run at all times. Those files are placed in one of the application's folders. That config path for its settings reads like this (I found it by searching the AppData tree manually):
C:\Users\<UserName>\AppData\Local\Apps\2.0\Data\WM4WPKCW.P5Z\67QVXD6C.0NT\<app>_f6187a2321850a68_0003.0004_1a67f9f1633c43fc\Data\AppFiles\
Please note that this config path is pretty different from the application path (which uses differently named folders):
C:\Users\<User>\AppData\Local\Apps\2.0\5HN2CKMO.MPL\YOL20MYR.O8L\<app>_f6187a2321850a68_0003.0004_f6ab8c93b3a43b7c\
Since this config path changes on each update of the Click-Once application I need to find it by code (preferably C++) automatically. Unfortunately I could not figure out a way to do this.
How can I make my launcher find the config path of the Click-Once application based on its *.appref-ms file?
From Raghavendra Prabhu’s blog entry “Client Settings FAQ”:
” If you want to get to the path programmatically, you can do it using the Configuration Management API (you need to add a reference to System.Configuration.dll). For example, here is how you can get the local user.config file path:
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
Console.WriteLine("Local user config path: {0}", config.FilePath);
The code is C# (evidently), but shouldn't be that hard to translate to C++/CLI.
Raghavendra Prabhu further writes:
” If you need to store the settings in a different location for some reason, the recommended way is to write your own SettingsProvider. This is fairly simple to implement and you can find samples in the .NET 2.0 SDK that show how to do this. Keep in mind however that you may run into the same isolation issues mentioned above .
Disclaimer: I have not tested any of this.

Processing.exe Doesn't Respond to System() (c++)

I exported my Processing project, which renders as P3D, successfully. The .exe file works, even from the command line. I need to run this executable from a c++ program. When I call
system("Project_name.exe");
on it, it doesn't open up the file. I checked the path by opening other types of files like .txt successfully. I also tried it with system("start Project_name.exe")and it gives the same input.
Is it because its not reading java with the app properly? The java folder is also in the same directory. I am using VS 13 Pro. Please help!
Note: I understand system calls are not the best approach. I also used CreateProcess but was not successful. I think the file is opened but the frame and contents doesn't display.
Thank you
System command works fine in case of interactive applications, starting notepad works fine.
Please ensure your application and dependencies are picked up from the right path, You may try to set path environment variable within c++ application.
If you are able to run this application from command line, you may write a batch file to invoke your application and invoke this batch file from c++ application using system command

Why would a call to LoadLibrary fail with 'The specified module could not be found' after working the first time

I have an application that runs as a WCF webservice on IIS7. It calls a COM control and this control then loads another dll with data. This application has been in use for quite a while and normally works fine, but recently I ran into a problem on one machine where the LoadLibrary call to load the data dll fails. However, the call doesn't always fail, it will work for the first call after the IIS service is restarted, and then fails after that.
The data dll exists in the same directory as the COM control, and the current directory is set to this directory. I've checked and the current directory does not get set to another directory, it stays the same for both calls. The separate calls are separate calls to the webservice and in between them the com control gets unloaded, as does the data dll.
The data dll loads fine if I place it in the system directory or use the full path to the dll in the com directory, so I can work around this, but I'm just wondering why it would happen. When I call GetLastError after it fails to load the module, as I mentioned it just gives me 'The specified module could not be found' error.
The MSDN description for LoadLIbrary says that the current directory should be searched and all the other installations where this has worked seems to suggest that it normally does. The machine that it's failing on is a Windows Server 2008 R2 machine, although the application has been run on this type of machine many times before.
Any ideas are welcome. Is there a way to get LoadLibrary to enumerate where it's looking?
Thanks,
Jordan
I haven't found a function that will enumerate all the DLL search paths, and it looks rather complicated: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586%28v=vs.85%29.aspx
The Windows behavior of searching the current working directory for libraries (in addition to the location of the .exe) is considered a potential security flaw. That article describes some ways to exclude the current directory within a process, including the SetDllDirectory function. I don't know how IIS works, but if you don't control the process, maybe someone else is tampering with the search settings? I think GetDllDirectory will tell you if that changed.
There is also a global registry setting that disables searching the working directory, but since your load isn't always failing I have to guess that's not the cause.

Launching exe from an application

I have to launch an exe from other application.There is code in the internet to do it.
I wanted to discuss how the Application get the path of the other exe to launch, Since path of the exe can be any.
Is Storing in the registry or config is the option??
What an application should do if the exe already running.
Please add possible problem one may face whiling a launching an exe from other application
I am using c++ on VS 2008.
You have two choices for launching EXE files: ShellExecuteEx(), and CreateProcess().
Each behaves a bit different, check them out on MSDN.
As for the varying path, the registry may be a good alternative.

How To Disable Shell Extension In FileOpen Dialog

I am talking about windows shell extensions.
I have a shell extension which could show the specific properties of my customized file type, say, *.filetype. And of course it will cause my shell extension dlls being loaded into the explorer.exe process. But now if I fire the FileOpen dialog in any application and check the file properties inside that dialog(notepad as an example), then these shell extension dlls would be loaded into notepad.exe process, which is the case I want to avoid.
So is it possible to disable a specific shell extension in FileOpen Dialog?
Thanks.
Create a shim dll which does nothing but load your real (big) shell extension dll.
The only job of that shim dll is to check whether the current process is "explorer.exe". If it is, the shim loads the real dll and forwards all calls there. If it's not, the shim doesn't load your real dll but simply returns E_NOTIMPL or something like that to all requests.