Access to system directories using C#
I have a program which contains a local database
It works fine when im running it from a non-system Directory , but when im running it from a system directory like program files directory i cant access to my database
Im using c# wpf . Have no idea how to access my database :/
tho im using an Entity Data Model which works with that database in application directory (which is going to be in program files Directory Like Every other application i install e.g Adobe applications MS Office etc .. ) how do they have access to their datas in program files directory without getting any permission from user ?!!! :((
c# database file access
add a comment |
I have a program which contains a local database
It works fine when im running it from a non-system Directory , but when im running it from a system directory like program files directory i cant access to my database
Im using c# wpf . Have no idea how to access my database :/
tho im using an Entity Data Model which works with that database in application directory (which is going to be in program files Directory Like Every other application i install e.g Adobe applications MS Office etc .. ) how do they have access to their datas in program files directory without getting any permission from user ?!!! :((
c# database file access
1
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
3
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06
add a comment |
I have a program which contains a local database
It works fine when im running it from a non-system Directory , but when im running it from a system directory like program files directory i cant access to my database
Im using c# wpf . Have no idea how to access my database :/
tho im using an Entity Data Model which works with that database in application directory (which is going to be in program files Directory Like Every other application i install e.g Adobe applications MS Office etc .. ) how do they have access to their datas in program files directory without getting any permission from user ?!!! :((
c# database file access
I have a program which contains a local database
It works fine when im running it from a non-system Directory , but when im running it from a system directory like program files directory i cant access to my database
Im using c# wpf . Have no idea how to access my database :/
tho im using an Entity Data Model which works with that database in application directory (which is going to be in program files Directory Like Every other application i install e.g Adobe applications MS Office etc .. ) how do they have access to their datas in program files directory without getting any permission from user ?!!! :((
c# database file access
c# database file access
edited Jan 2 at 18:12
Mahdi.KH
asked Jan 2 at 13:32
Mahdi.KHMahdi.KH
34
34
1
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
3
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06
add a comment |
1
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
3
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06
1
1
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
3
3
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06
add a comment |
4 Answers
4
active
oldest
votes
You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.
E.g.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourApplication"
This is also what e.g. Adobe Flash or MS Office are using.
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
|
show 1 more comment
I am posting this as a answear because I cannot comment yet, however I would check the following:
- Permissions, if the program is run by a different user, that could lead to problems
- Paths, make sure that they are not relative
But without the code, it's hard to tell
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
add a comment |
Without error-messages it's hard to guess what your problem is.
My guess: You need administrator-privilegues to write to C:Program Files
.
Data which is changed by your program (Files oder DBs) should not be contained in this directory!
This is a security-mechanism to protect your programs (all not only which you did create) from being changed by other users.
add a comment |
EDIT : Here the code to use app data folder
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetDB();
}
void GetDB1()
{
var DBFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DB1");
var con = new System.Data.SQLite.SQLiteConnection($"Data Source={DBFile}.sqlite;Version=3;");
con.Open();
string sql = "Select 1 as col1";
var command = new System.Data.SQLite.SQLiteCommand(sql, con);
var reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("col1: " + reader["col1"]);
}
}
simply on window check your folder permissions like in pictures
more details
1. Software
software is a collection of data or computer instructions that tell the computer how to work
for simplicity there are two main types
operating system software
Application software
2. operating system software
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs.
3. Directory structure
In computing, a directory structure is the way an operating system's file system and its files are displayed to the user. Files are typically displayed in a hierarchical tree structure.
4. Windows 10 [username]AppData
This folder stores per-user application data and settings. The folder contains three subfolders: Roaming, Local, and LocalLow. Roaming is for networked based logins for roaming profiles. Data saved in Roaming will synchronize to the computer when the user logs into that. Local and LocalLow does not sync up with networked computer
5. Guidelines : Store and retrieve settings and other app data
App data is mutable data that is specific to a particular app. It includes runtime state, user preferences, and other settings.
App data is different from user data, data that the user creates and manages when using an app. User data includes document or media files, email or communication transcripts, or database records holding content created by the user. User data may be useful or meaningful to more than one app.
Often, this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
-Important note about app data: The lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence. Don't use app data to store user data or anything that users might perceive as valuable and irreplaceable. We recommend that the user's libraries and Microsoft OneDrive be used to store this sort of information. App data is ideal for storing app-specific user preferences, settings, and favorites.
6.Access control
Access control refers to security features that control who can access files (resources) in the operating system (OS).
7.what is the relationship between operating system and application software
All Applications call access control functions on the operating system (OS) to access specific resources or control access to resources provided by the application.
So your App Need you as a user who has a control over the operation system to ask the operation system for Folder permission
So you need C# code + OS permission
8. How To apply this concepts
- 8.1. Run as administrator because they have accesses
- 8.2. Check the folder that the App is in
- 8.3. Add permission To the Folder for the current user
8.1. Run as administrator because they have accesses
8.1.1 How
8.1.2 Why
8.1.3 Why NoT
Why you shouldn’t run as admin… – Aaron Margosis' Non-Admin, App-Compat and Sysinternals WebLog
If the exploit happens to be written so that it requires admin privileges (as many do), just running as User stops it dead. But if you’re running as admin, an exploit can:
- install kernel-mode rootkits and/or keyloggers (which can be close to impossible to detect)
- install and start services
- install ActiveX controls, including IE and shell add-ins (common with spyware and adware)
- access data belonging to other users
- cause code to run whenever anybody else logs on (including capturing passwords entered into the Ctrl-Alt-Del logon dialog)
- replace OS and other program files with trojan horses
- access LSA Secrets, including other sensitive account information, possibly including account info for domain accounts
- disable/uninstall anti-virus
- cover its tracks in the event log
- render your machine unbootable
- if your account is an administrator on other computers on the network, the malware gains admin control over those computers as well
- and lots more
8.2. Check the folder that the App is in
8.3. Add permission To the Folder for the current user
Ref.
- https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data
- https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-control
- https://en.wikipedia.org/wiki/Software
- https://en.wikipedia.org/wiki/Directory_structure
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
|
show 2 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007302%2faccess-to-system-directories-using-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.
E.g.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourApplication"
This is also what e.g. Adobe Flash or MS Office are using.
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
|
show 1 more comment
You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.
E.g.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourApplication"
This is also what e.g. Adobe Flash or MS Office are using.
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
|
show 1 more comment
You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.
E.g.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourApplication"
This is also what e.g. Adobe Flash or MS Office are using.
You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.
E.g.
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\YourApplication"
This is also what e.g. Adobe Flash or MS Office are using.
answered Jan 2 at 18:36
CompufreakCompufreak
2,12711130
2,12711130
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
|
show 1 more comment
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
thanks but how can i create an entity model which works with my database in a different folder than my program folder ? currently i have an EDM which is working with my database placed in my program folder how can i change its Connection string ?! is it possible in Run-Time ?
– Mahdi.KH
Jan 2 at 18:41
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
or how can i Copy my database in that special folder when i have no access to copy it ... is it possible to place it there when installing the program on client machine ? i'm using InstallShield to deploy my program
– Mahdi.KH
Jan 2 at 18:44
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
It depends on the type of database you are using, you should read up on how to configure the connection string for your version of the entity framework, probably like mentioned here.
– Compufreak
Jan 2 at 18:47
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
Yeah that's what im looking for . But one last thing is that can i use a dynamic connection string instead of a static one in app.config ? Bcz i dont know whats the name of user to use the applicationData folder on client machine in xaml file ! Maybe binding or sth ...? Im using a local sql db file (mdf) btw
– Mahdi.KH
Jan 2 at 19:07
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
I usually only use EFCore, not EF so I don't know, sorry - this sounds like you should ask it in another question as it's not really related to your initial issue.
– Compufreak
Jan 2 at 19:09
|
show 1 more comment
I am posting this as a answear because I cannot comment yet, however I would check the following:
- Permissions, if the program is run by a different user, that could lead to problems
- Paths, make sure that they are not relative
But without the code, it's hard to tell
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
add a comment |
I am posting this as a answear because I cannot comment yet, however I would check the following:
- Permissions, if the program is run by a different user, that could lead to problems
- Paths, make sure that they are not relative
But without the code, it's hard to tell
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
add a comment |
I am posting this as a answear because I cannot comment yet, however I would check the following:
- Permissions, if the program is run by a different user, that could lead to problems
- Paths, make sure that they are not relative
But without the code, it's hard to tell
I am posting this as a answear because I cannot comment yet, however I would check the following:
- Permissions, if the program is run by a different user, that could lead to problems
- Paths, make sure that they are not relative
But without the code, it's hard to tell
answered Jan 2 at 13:36
thejackthejack
436
436
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
add a comment |
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
thanks bruh but how can i find out that this user is an administrator ? or a different user ? or how can i find out that they're running my program as administrator ?
– Mahdi.KH
Jan 2 at 18:23
add a comment |
Without error-messages it's hard to guess what your problem is.
My guess: You need administrator-privilegues to write to C:Program Files
.
Data which is changed by your program (Files oder DBs) should not be contained in this directory!
This is a security-mechanism to protect your programs (all not only which you did create) from being changed by other users.
add a comment |
Without error-messages it's hard to guess what your problem is.
My guess: You need administrator-privilegues to write to C:Program Files
.
Data which is changed by your program (Files oder DBs) should not be contained in this directory!
This is a security-mechanism to protect your programs (all not only which you did create) from being changed by other users.
add a comment |
Without error-messages it's hard to guess what your problem is.
My guess: You need administrator-privilegues to write to C:Program Files
.
Data which is changed by your program (Files oder DBs) should not be contained in this directory!
This is a security-mechanism to protect your programs (all not only which you did create) from being changed by other users.
Without error-messages it's hard to guess what your problem is.
My guess: You need administrator-privilegues to write to C:Program Files
.
Data which is changed by your program (Files oder DBs) should not be contained in this directory!
This is a security-mechanism to protect your programs (all not only which you did create) from being changed by other users.
edited Jan 2 at 14:02
answered Jan 2 at 13:38
karakara
1,76331124
1,76331124
add a comment |
add a comment |
EDIT : Here the code to use app data folder
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetDB();
}
void GetDB1()
{
var DBFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DB1");
var con = new System.Data.SQLite.SQLiteConnection($"Data Source={DBFile}.sqlite;Version=3;");
con.Open();
string sql = "Select 1 as col1";
var command = new System.Data.SQLite.SQLiteCommand(sql, con);
var reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("col1: " + reader["col1"]);
}
}
simply on window check your folder permissions like in pictures
more details
1. Software
software is a collection of data or computer instructions that tell the computer how to work
for simplicity there are two main types
operating system software
Application software
2. operating system software
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs.
3. Directory structure
In computing, a directory structure is the way an operating system's file system and its files are displayed to the user. Files are typically displayed in a hierarchical tree structure.
4. Windows 10 [username]AppData
This folder stores per-user application data and settings. The folder contains three subfolders: Roaming, Local, and LocalLow. Roaming is for networked based logins for roaming profiles. Data saved in Roaming will synchronize to the computer when the user logs into that. Local and LocalLow does not sync up with networked computer
5. Guidelines : Store and retrieve settings and other app data
App data is mutable data that is specific to a particular app. It includes runtime state, user preferences, and other settings.
App data is different from user data, data that the user creates and manages when using an app. User data includes document or media files, email or communication transcripts, or database records holding content created by the user. User data may be useful or meaningful to more than one app.
Often, this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
-Important note about app data: The lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence. Don't use app data to store user data or anything that users might perceive as valuable and irreplaceable. We recommend that the user's libraries and Microsoft OneDrive be used to store this sort of information. App data is ideal for storing app-specific user preferences, settings, and favorites.
6.Access control
Access control refers to security features that control who can access files (resources) in the operating system (OS).
7.what is the relationship between operating system and application software
All Applications call access control functions on the operating system (OS) to access specific resources or control access to resources provided by the application.
So your App Need you as a user who has a control over the operation system to ask the operation system for Folder permission
So you need C# code + OS permission
8. How To apply this concepts
- 8.1. Run as administrator because they have accesses
- 8.2. Check the folder that the App is in
- 8.3. Add permission To the Folder for the current user
8.1. Run as administrator because they have accesses
8.1.1 How
8.1.2 Why
8.1.3 Why NoT
Why you shouldn’t run as admin… – Aaron Margosis' Non-Admin, App-Compat and Sysinternals WebLog
If the exploit happens to be written so that it requires admin privileges (as many do), just running as User stops it dead. But if you’re running as admin, an exploit can:
- install kernel-mode rootkits and/or keyloggers (which can be close to impossible to detect)
- install and start services
- install ActiveX controls, including IE and shell add-ins (common with spyware and adware)
- access data belonging to other users
- cause code to run whenever anybody else logs on (including capturing passwords entered into the Ctrl-Alt-Del logon dialog)
- replace OS and other program files with trojan horses
- access LSA Secrets, including other sensitive account information, possibly including account info for domain accounts
- disable/uninstall anti-virus
- cover its tracks in the event log
- render your machine unbootable
- if your account is an administrator on other computers on the network, the malware gains admin control over those computers as well
- and lots more
8.2. Check the folder that the App is in
8.3. Add permission To the Folder for the current user
Ref.
- https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data
- https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-control
- https://en.wikipedia.org/wiki/Software
- https://en.wikipedia.org/wiki/Directory_structure
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
|
show 2 more comments
EDIT : Here the code to use app data folder
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetDB();
}
void GetDB1()
{
var DBFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DB1");
var con = new System.Data.SQLite.SQLiteConnection($"Data Source={DBFile}.sqlite;Version=3;");
con.Open();
string sql = "Select 1 as col1";
var command = new System.Data.SQLite.SQLiteCommand(sql, con);
var reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("col1: " + reader["col1"]);
}
}
simply on window check your folder permissions like in pictures
more details
1. Software
software is a collection of data or computer instructions that tell the computer how to work
for simplicity there are two main types
operating system software
Application software
2. operating system software
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs.
3. Directory structure
In computing, a directory structure is the way an operating system's file system and its files are displayed to the user. Files are typically displayed in a hierarchical tree structure.
4. Windows 10 [username]AppData
This folder stores per-user application data and settings. The folder contains three subfolders: Roaming, Local, and LocalLow. Roaming is for networked based logins for roaming profiles. Data saved in Roaming will synchronize to the computer when the user logs into that. Local and LocalLow does not sync up with networked computer
5. Guidelines : Store and retrieve settings and other app data
App data is mutable data that is specific to a particular app. It includes runtime state, user preferences, and other settings.
App data is different from user data, data that the user creates and manages when using an app. User data includes document or media files, email or communication transcripts, or database records holding content created by the user. User data may be useful or meaningful to more than one app.
Often, this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
-Important note about app data: The lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence. Don't use app data to store user data or anything that users might perceive as valuable and irreplaceable. We recommend that the user's libraries and Microsoft OneDrive be used to store this sort of information. App data is ideal for storing app-specific user preferences, settings, and favorites.
6.Access control
Access control refers to security features that control who can access files (resources) in the operating system (OS).
7.what is the relationship between operating system and application software
All Applications call access control functions on the operating system (OS) to access specific resources or control access to resources provided by the application.
So your App Need you as a user who has a control over the operation system to ask the operation system for Folder permission
So you need C# code + OS permission
8. How To apply this concepts
- 8.1. Run as administrator because they have accesses
- 8.2. Check the folder that the App is in
- 8.3. Add permission To the Folder for the current user
8.1. Run as administrator because they have accesses
8.1.1 How
8.1.2 Why
8.1.3 Why NoT
Why you shouldn’t run as admin… – Aaron Margosis' Non-Admin, App-Compat and Sysinternals WebLog
If the exploit happens to be written so that it requires admin privileges (as many do), just running as User stops it dead. But if you’re running as admin, an exploit can:
- install kernel-mode rootkits and/or keyloggers (which can be close to impossible to detect)
- install and start services
- install ActiveX controls, including IE and shell add-ins (common with spyware and adware)
- access data belonging to other users
- cause code to run whenever anybody else logs on (including capturing passwords entered into the Ctrl-Alt-Del logon dialog)
- replace OS and other program files with trojan horses
- access LSA Secrets, including other sensitive account information, possibly including account info for domain accounts
- disable/uninstall anti-virus
- cover its tracks in the event log
- render your machine unbootable
- if your account is an administrator on other computers on the network, the malware gains admin control over those computers as well
- and lots more
8.2. Check the folder that the App is in
8.3. Add permission To the Folder for the current user
Ref.
- https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data
- https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-control
- https://en.wikipedia.org/wiki/Software
- https://en.wikipedia.org/wiki/Directory_structure
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
|
show 2 more comments
EDIT : Here the code to use app data folder
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetDB();
}
void GetDB1()
{
var DBFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DB1");
var con = new System.Data.SQLite.SQLiteConnection($"Data Source={DBFile}.sqlite;Version=3;");
con.Open();
string sql = "Select 1 as col1";
var command = new System.Data.SQLite.SQLiteCommand(sql, con);
var reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("col1: " + reader["col1"]);
}
}
simply on window check your folder permissions like in pictures
more details
1. Software
software is a collection of data or computer instructions that tell the computer how to work
for simplicity there are two main types
operating system software
Application software
2. operating system software
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs.
3. Directory structure
In computing, a directory structure is the way an operating system's file system and its files are displayed to the user. Files are typically displayed in a hierarchical tree structure.
4. Windows 10 [username]AppData
This folder stores per-user application data and settings. The folder contains three subfolders: Roaming, Local, and LocalLow. Roaming is for networked based logins for roaming profiles. Data saved in Roaming will synchronize to the computer when the user logs into that. Local and LocalLow does not sync up with networked computer
5. Guidelines : Store and retrieve settings and other app data
App data is mutable data that is specific to a particular app. It includes runtime state, user preferences, and other settings.
App data is different from user data, data that the user creates and manages when using an app. User data includes document or media files, email or communication transcripts, or database records holding content created by the user. User data may be useful or meaningful to more than one app.
Often, this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
-Important note about app data: The lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence. Don't use app data to store user data or anything that users might perceive as valuable and irreplaceable. We recommend that the user's libraries and Microsoft OneDrive be used to store this sort of information. App data is ideal for storing app-specific user preferences, settings, and favorites.
6.Access control
Access control refers to security features that control who can access files (resources) in the operating system (OS).
7.what is the relationship between operating system and application software
All Applications call access control functions on the operating system (OS) to access specific resources or control access to resources provided by the application.
So your App Need you as a user who has a control over the operation system to ask the operation system for Folder permission
So you need C# code + OS permission
8. How To apply this concepts
- 8.1. Run as administrator because they have accesses
- 8.2. Check the folder that the App is in
- 8.3. Add permission To the Folder for the current user
8.1. Run as administrator because they have accesses
8.1.1 How
8.1.2 Why
8.1.3 Why NoT
Why you shouldn’t run as admin… – Aaron Margosis' Non-Admin, App-Compat and Sysinternals WebLog
If the exploit happens to be written so that it requires admin privileges (as many do), just running as User stops it dead. But if you’re running as admin, an exploit can:
- install kernel-mode rootkits and/or keyloggers (which can be close to impossible to detect)
- install and start services
- install ActiveX controls, including IE and shell add-ins (common with spyware and adware)
- access data belonging to other users
- cause code to run whenever anybody else logs on (including capturing passwords entered into the Ctrl-Alt-Del logon dialog)
- replace OS and other program files with trojan horses
- access LSA Secrets, including other sensitive account information, possibly including account info for domain accounts
- disable/uninstall anti-virus
- cover its tracks in the event log
- render your machine unbootable
- if your account is an administrator on other computers on the network, the malware gains admin control over those computers as well
- and lots more
8.2. Check the folder that the App is in
8.3. Add permission To the Folder for the current user
Ref.
- https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data
- https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-control
- https://en.wikipedia.org/wiki/Software
- https://en.wikipedia.org/wiki/Directory_structure
EDIT : Here the code to use app data folder
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
GetDB();
}
void GetDB1()
{
var DBFile = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DB1");
var con = new System.Data.SQLite.SQLiteConnection($"Data Source={DBFile}.sqlite;Version=3;");
con.Open();
string sql = "Select 1 as col1";
var command = new System.Data.SQLite.SQLiteCommand(sql, con);
var reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("col1: " + reader["col1"]);
}
}
simply on window check your folder permissions like in pictures
more details
1. Software
software is a collection of data or computer instructions that tell the computer how to work
for simplicity there are two main types
operating system software
Application software
2. operating system software
An operating system (OS) is system software that manages computer hardware and software resources and provides common services for computer programs.
3. Directory structure
In computing, a directory structure is the way an operating system's file system and its files are displayed to the user. Files are typically displayed in a hierarchical tree structure.
4. Windows 10 [username]AppData
This folder stores per-user application data and settings. The folder contains three subfolders: Roaming, Local, and LocalLow. Roaming is for networked based logins for roaming profiles. Data saved in Roaming will synchronize to the computer when the user logs into that. Local and LocalLow does not sync up with networked computer
5. Guidelines : Store and retrieve settings and other app data
App data is mutable data that is specific to a particular app. It includes runtime state, user preferences, and other settings.
App data is different from user data, data that the user creates and manages when using an app. User data includes document or media files, email or communication transcripts, or database records holding content created by the user. User data may be useful or meaningful to more than one app.
Often, this is data that the user wants to manipulate or transmit as an entity independent of the app itself, such as a document.
-Important note about app data: The lifetime of the app data is tied to the lifetime of the app. If the app is removed, all of the app data will be lost as a consequence. Don't use app data to store user data or anything that users might perceive as valuable and irreplaceable. We recommend that the user's libraries and Microsoft OneDrive be used to store this sort of information. App data is ideal for storing app-specific user preferences, settings, and favorites.
6.Access control
Access control refers to security features that control who can access files (resources) in the operating system (OS).
7.what is the relationship between operating system and application software
All Applications call access control functions on the operating system (OS) to access specific resources or control access to resources provided by the application.
So your App Need you as a user who has a control over the operation system to ask the operation system for Folder permission
So you need C# code + OS permission
8. How To apply this concepts
- 8.1. Run as administrator because they have accesses
- 8.2. Check the folder that the App is in
- 8.3. Add permission To the Folder for the current user
8.1. Run as administrator because they have accesses
8.1.1 How
8.1.2 Why
8.1.3 Why NoT
Why you shouldn’t run as admin… – Aaron Margosis' Non-Admin, App-Compat and Sysinternals WebLog
If the exploit happens to be written so that it requires admin privileges (as many do), just running as User stops it dead. But if you’re running as admin, an exploit can:
- install kernel-mode rootkits and/or keyloggers (which can be close to impossible to detect)
- install and start services
- install ActiveX controls, including IE and shell add-ins (common with spyware and adware)
- access data belonging to other users
- cause code to run whenever anybody else logs on (including capturing passwords entered into the Ctrl-Alt-Del logon dialog)
- replace OS and other program files with trojan horses
- access LSA Secrets, including other sensitive account information, possibly including account info for domain accounts
- disable/uninstall anti-virus
- cover its tracks in the event log
- render your machine unbootable
- if your account is an administrator on other computers on the network, the malware gains admin control over those computers as well
- and lots more
8.2. Check the folder that the App is in
8.3. Add permission To the Folder for the current user
Ref.
- https://docs.microsoft.com/en-us/windows/uwp/design/app-settings/store-and-retrieve-app-data
- https://docs.microsoft.com/en-us/windows/desktop/SecAuthZ/access-control
- https://en.wikipedia.org/wiki/Software
- https://en.wikipedia.org/wiki/Directory_structure
edited Jan 2 at 19:18
answered Jan 2 at 14:25
Mohamed ElrashidMohamed Elrashid
1,9401922
1,9401922
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
|
show 2 more comments
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Wow, this is afford!
– nilsK
Jan 2 at 15:06
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
Dude ! wow ... thanks for your answer but i cant force user to do all those stuff ! i need my program to work just like any other application we install on our machine and they work fine without getting any permission from user or make user to do these ! i need my program to just get access itself or at least asks user one time for permission . thanks again man
– Mahdi.KH
Jan 2 at 18:19
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@Mahdi.KH how are you deploying the app ? MS SETUP , Onclicke or jsut copying the files via usb ?
– Mohamed Elrashid
Jan 2 at 18:22
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@MohamedElrashid im using installShield -> Basic MSI Project
– Mahdi.KH
Jan 2 at 18:29
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
@Mahdi.KH check the code for sql or do you use Entity Framework
– Mohamed Elrashid
Jan 2 at 19:21
|
show 2 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54007302%2faccess-to-system-directories-using-c-sharp%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Run the program/Visual studio as an administrator?
– Compufreak
Jan 2 at 13:36
3
You shouldn't store data in the program files folder. Use something like: Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) and store the data there.
– Kevin
Jan 2 at 13:37
@Compufreak i cant force each User to run the program as administrator bruh the problem is that i want the program grant that access itself or at least ask the user only once to grant it manually
– Mahdi.KH
Jan 2 at 18:04
@Kevin yeah sure that'll do the trick but i'm using an Entity data model which works with the database which is in application directory :(( ... im using stored procedures dude
– Mahdi.KH
Jan 2 at 18:06