Get Windows common path running Ubuntu subsystem - c#

I am developing an application .NET Core (dotnet) in C# that must run on Windows 10, Linux AND in the Linux subsystem that can be installed in Windows 10.
The problem is that the application must stored files in a common location to let other application use they. That is, others applications (that are clients) must resolved the same path as this application does. So, the same code must be added in all of the clients to know where the files are storage.
I searched a lot and I found this solution:
Console.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
This returns me on Windows:
C:\ProgramData
And on Linux:
/usr/share
I like this solution but the problem here is that when the program is running in a Linux subsystem, I want to use a path that can be acceded from applications running on Windows natively.
I know that Windows is mounted in /mnt/c/ in the Linux subsystem but y dont want to have hardcoded paths.
Is there any way to have programatically (running on Linux subsystem) a path in the Windows host? That is, if the program run on Linux natively the path that returns is /usr/share BUT if it is a subsystem, the path that returns is /mnt/c/ProgramData (or something like that).
Thanks!

Related

Specialfolder resolutions in differing versions of Windows

My project includes a template that is installed in the 32 bit Program Files directory. Accessing this template is relatively simple:
string templateLoc = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
+ #"\path.html";
This works as intended on my local system, including after building the WiX installer. However, on my client's system, it looks for the template in the System32 directory.
The only real difference between our systems is that I run Windows 7, and my client runs Windows 10. Is there a difference between these systems that affects Environment? Or, is there something wrong with my syntax?

run c sharp program without installing in client machine

I want to run an application in client machine without installing it in the client machine. the application file should be in my usb pen drive and when I go to customer pen is plug in client machine and run the application. The system is developed by c#. Please send any ideas.
Build it in .Net framework 2. Then you can run it in almost all the windows machine except windows 8. .Net framework 2 is disabled by default in windows 8. You can enable it and run your app. Framework 2 will be available when installing windows and can run by double clicking the exe
If you are just interested in running the C# program, there are various online C# compiler available. For eg:
http://www.compileonline.com/compile_csharp_online.php
http://ideone.com/
If it is an application in .exe, you should be able to run it in windows without installing anything, as Windows already contains a version of .Net by default.
If you just have the dlls, scripts etc, you are in deep trouble.
It sounds as if you're after a linker/merger/virtualizer. I don't have any experience with these tools but they are cited quite often:
Xenocode
Thinstall
ILmerge
Salamander
SkaterPro
Spoon Studio

"Unable to find a version of runtime to run this application" for 32bit app on 64bit Windows

I am developing a 32bit WinForm app (target: .NET 3.5). My client insists the app be installed into "Windows\System32\clientname" folder and autostarts on startup. Also, the app must be 32bit, so I can't use "Any CPU".
I am developing under Win7 x64 with VS2010 and all versions of .NET are installed. When I start the app I get the message "Unable to find a version of runtime to run this application".
On Win7 x86 it works without problem. It's not the app itself and I am 100% sure all the required frameworks are installed.
I know that on a x64 system this folder is not to be used for 32bit apps but as I said: client insists and won't budge.
Before I tell client definitively that it can't be done I want to explore all options. I googled of course and also searched this fine site but nothing helpful for my particular situation came up.
My app spawns another 32bit process located in the same folder. On x64 that didn't work either, of course, but I solved that by using "Wow64DisableWow64FsRedirection" and then copying it to another location to start it from there (which works fine).
I have done my homework but I just can't find a solution for starting the main app under x64 and in that particular folder.
Is there one?
In an attempt to solve this problem I created two folders on my Win7 x64 machine:
C:\Windows\System32\ClientName; and
C:\Windows\SysWOW64\ClientName
Next I created a simple x86 WinForms application targeting .NET 3.5. I found that if I copied the executable to C:\Windows\System32\ClientName I got exactly the same error message as you reported.
However, if I copied the executable to both directories, then I could start it from C:\Windows\System32\ClientName, and it worked just fine.
I did not try this, but I suspect that if you have a multi-assembly application, you only need to copy the *.exe file to C:\Windows\System32\ClientName. All of the other files (and the EXE) would then reside in the C:\Windows\SysWOW64\ClientName directory.
This is a bit of an untidy solution, I know, but then again your client's requirement is a bit unusual to start with.

"Required permissions cannot be acquired" while debugging standalone application

I'm trying to debug a native application that uses some C# components but I'm getting a "Required permissions cannot be acquired" error when trying to start the application.
Now I did search StackOverflow and the net in general but all answers that I could find were related to ASP Web applications but the one I'm trying to debug is a standalone one.
Additional background: I'm using WinDbg to debug code that runs in a remote machine via remote terminal (in fact by using TWO remote connections since the machine in question is not reachable from my machine directly thanks to some stupid router configuration). The binaries are located on my computer and I access them via the auto drive mapping that RT does for me.
Now I did have similar issues in the past and I'm pretty sure that the code would run if I copy all the binaries to the target machine and start them from a local drive but this is something that I want to avoid.
NOTE: The code is targeting version 2.0 of the .Net Framework. The target machine does not have the configuration tool for .Net 2 installed and I gave up trying to install and make it run by hand to try to see if there is some "trust" setting that I can set to mke the code run..
Problem turned out to be a firewall issue and related to the fact that I could not reach the target machine (where the program was running) directly from my PC (where the executable files where located). I was connecting indirectly through another PC to the target machine and this was causing problems with the .Net security checks, after changing the switch/firewall so that I could connect directly I had no more problems.

Running a C# exe file

Duplicate:
Why does my .NET application crash when run from a network drive?
Can someone help me? For a school project, I wrote a C# windows application in Visual Studio 2005. It works just fine, no problems. I want to be able to share this program with others in my department at work. So, I copied the exe file to a network drive. When we attempt to run the exe from the network, it fails with "name of progrm...has encountered a problem and needs to close". If I have the co-worker copy the exe file to their c:\ drive then attempt to run, it works. Why won't my program run from the network drive?
Susan
.NET by default does not allow applications to be run off a network drive. Either copy it to a local drive or alter the security settings for .NET.
This discussion should give you what you need.
Microsoft has finally realised that the default behavior of preventing applications from running off a network drive is wrong. From The .NET 3.5 SP1 download page:
"Additionally, managed applications that are opened from network shares have the same behavior as native applications by running with full trust."
This change is long overdue: there is virtually no security benefit in preventing managed applications running from a network share, since a hacker could just as easily use an unmanaged application.

Categories

Resources