UAC problems while creating directories and text files in Windows 7 - c#

I have a program that needs to create a text log. In XP, everything worked just fine, but when I tested it on Windows 7 - and was later Upgraded to Windows 7 for my Dev Computer - I get an error that "Access to the path 'C:\Program Files (x86)\Ludlum Measurements, Inc\LMI Universal Software\UniversalLog\' is denied". I get the a similar error if I have the installer create the folder and then try to create a text file in the folder.
I know this has something to do with permissions, but what should I give permission and how?
The programs that use the logging function?
The folder that the logs go into?
The folder the programs are in?
And how would this fix work under XP, Vista, Server 2005, and Server 2008 and as service (Part of the program runs as a Windows form, and part as a service)?
-Edit-
Emphasis added.
To reiterate: How will this work when installed and ran on an XP? A Server 2003? A Server 2008? Will this cause any problems for them?
And a new question: Can my program access files from the ApplicationData file? I just remembered the entire problem stemmed from me trying to create a config file that holds connection information for to an SQL database. Hitting your head against a brick wall for a day tends to make you forget why you started doing it in the first place. And again, this originally worked in XP, Server 2005, and Server 2008.

You should use Environment.GetFolderPath and pick a Environment.SpecialFolder folder that has write permissions when the UAC is on and write your log files there.
By default under UAC you donot have permissions to write to C:\Program Files or its subfolders.
Environment.ApplicationData is usually a good choice, it will be writable by default on XP , Vista , Server 2005 and Server 2008 unless the admin has locked stuff down too much
Teach Your Apps To Play Nicely With Windows Vista User Account Control is a good resource on how to write an application that behaves nicely under UAC

You shouldn't write anything to the Program Files directory after installation unless you are actually patching your application. Day-to-day usage of files should go into the application data folder (LocalApplicationData for non-roaming data and ApplicationData for roaming data).
string path = Environment.GetFolderPath(
EnvironmentFolders.SpecialFolders.LocalApplicationData)
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

Related

database in install folder cannot be accessed in win 10 anymore

I have a WPF application including a SQLite Database.
Everything worked file as long as the computer was Win 7.
Since the PC is Win 10 I cannot write the database anymore because it is installed in C:\Program Files (x86)\ProgramName.
If I understood that right I need admin rights to write to the database in this folder. But if the program is started as administrator Drag&Drop is forbidden which I also need.
The first Idea would be to copy the database to C:\Users\\AppData\Local. There I have write access even without admin rights. But the use case of this database is that different Users on the same PC can enter this database. Thats not possible anymore if the db is installed in a personal folder.
Do you have any suggestions?

C# console app - Access to the path is denied

When I run a console app in Visual Studio and open files on my workstation everything runs fine. When I run the same app in Visual Studio and open files on a network share I get an "Access to the path 'xxx' is denied".
I have access to the files in both locations. Does the console app not run as "me"?
As an admin you indeed have access to almost everything on the system. Applications and normal users do not however, especially over a network. This is a security feature of most modern operating systems.
For the sake of example, suppose you wanted to access a file in C:/Users/Vance/ (on the target machine). You can't access that or anything else remotely except C:/Users/Public/, until the necessary permissions are set.
See this to learn how to share folders over your local network.
Im not running the exe directly.
The networked machine still needs permission to execute programs remotely on the target machine.
If it's still not working after setting the correct permissions, your firewall is probably blocking the network traffic. In this case you'll need to add a rule to allow it through.

Is there any way to access c# code or project files in Microsoft visual 2012 using Windows 7 Safe Mode?

two days ago my laptop fall off from table. I've window 7 installed. My windows is not starting in standard mode I can only get access via safe mode. I was doing a c# project in Microsoft visual 2012 and it was almost completed My problem is that I cannot see project files using safe mode. Is there anyway to access the source code or project so that I can send it to other laptop?
I want to copy my code so that I can complete my project in other system?
First, right click on the folder that you want to get files from. Go to security tab, and make sure the admin account you are using has full rights to the folder. They may be not appearing because there is some weird permission things happening.
You may be able to connect to a USB or External HD while in Safe Mode, and then just copy of the files over and put them on another computer with VS 2012. If not, try Safe Mode with Networking and then try to upload to Dropbox/Onedrive.
In desperate times, you can always buy a HD mount device, pull out the HD from the computer, mount with HD mounter on another computer, and copy files over.

Why can't I retrieve data from an mdb file in Windows 7 64-bit?

I recently bought a software that uses an mdb file for data storage. I don't like the software's reporting and statement generation that much so I decided to write my own reporting program using VS 2008's C#.
So my program accesses the mdb file that comes with the software I just bought. My dev environment is Windows XP. My deployment environment is Windows 7 64-bit. In my dev machine, I can retrieve records from the mdb file just fine but when I deploy the program to a Windows 7 64-bit machine, it cannot read the records from the mdb file. No errors are thrown, it just can't get that data.
I also tried installing VS 2012 on the deployment machine (Win 7 64-bit) and imported my VS2008 project there. Same issues, can't get records from that mdb file (again, no errors are thrown).
Please help?
edit 1: I just tried backing up the mdb using the purchased software backup utility. I can retrieve records from that backed up mdb. I wonder if the software is trying to modify my access to the mdb file.
edit 2: I don't think the software is trying to modify my access to the mdb file because when deployed to my xp machine, I can access the mdb file just fine.
edit 3: I'm beginning to suspect this is a file security feature within Windows 7.
edit 4: If I copy the mdb file and access that copied mdb file, it returns 0 rows. If I back it up using the software's backup utility, it returns the exact rows I expect.
The problem is that you're running up against security features of Windows.
Programs are no longer allowed to change files under the program files directories, unless they run with elevated access.
What happens is that a feature called Virtual Store kicks in and creates private (for your user) copies of the file somewhere else, under your user profile.
Most likely the software has created an empty database file under the user profile, and is accessing that instead.
You can not place writable files in the program files any more, the program needs to be either redesigned or installed somewhere else, like under the user profile where it would have write access.
Set your target platform to "x86" instead of "Any cpu" to be sure that you are running it 32-bit.

Setup Project and Access Permission

I created a setup project in VS2008. This setup copy some folders/files to the program files folder. Also, it adds some windows environment variables.
During the instalation, I am requested to confirm something in a UAC dialog.
This works fine, and all files are copied.
The problem begins when my program is running and I have to modify the a file´s content.
An exception is thrown, saying that I have no permission. Also, if I try to do the same operation in Windows Explorer => same problem.
My question is:
If I have the permission to install my software in program files folder, shouldn´t I be able to write in this folder as well?
Well, it seems that this is a general permission problem. By default normal users (and applications) cannot write to %PROGRAMFILES%. There are folders specially provided for application data storage such as ApplicationData
The reason the setup does install into program files is because this default behaviour of the Windows Installer. Check this link for more info on the Windows Installer and clickonce setup

Categories

Resources