Hi Dw

I'm working with permissions in my program I want it to protect the chosen file by permissions and now what I want is how can I make these permissions unchanged by a user? Or if not possible because I don't want even the administrator to change these permission for the security of the file or contents it will be holding, or maybe after I protected the file with the permission and it a user or a program want to modify or open the folder the system not just only my program request an access password which will be served on a file if the password does not match the application password then the user or that particular program that try to open or modify this file will be blocked from performing that task. Any one know how can I solve this problem?

What type of Permission you want to access?
Do you want to run as admin only?
if admin change the permission from admin to all user then too you want to run as admin?

Then yes you can do some coding like this:

Imports System.Security.Principal
...    
Dim identity = WindowsIdentity.GetCurrent()
Dim principal = new WindowsPrincipal(identity)
Dim isElevated as Boolean = principal.IsInRole(WindowsBuiltInRole.Administrator)

if isElevated = True then
   msgbox("I am Admin")
else
   msgbox("Please try as Admin")
   me.close
End if

OR you can aslo do this:

Private Shared Function GetCurrentPrivileges() As Privileges
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
   MsgBox("I have admin privileges")
Else
   MsgBox("Please run as Admin")
   me.close
End If

I don't understand your question but you can do this if I am correct from what you mean...

if your question is something else then can you please elaborate it...

Thanks but what I want or meant is that I'm creating a program in VB.NET that creates a file (Directory folder) and I made it protect the file or folder from being opened or accessed right. Now when I debugged the program indeed it created a file and then I go to it manually to test if it will be opened and I tried opening it and because I've protected the file with permissions it then gave me a message stating that I don't have permissions t open this file right. Now I tested it to see if a user can manually change the access permissions and I right clicked the file and go to properties and clicked security tab and clicked Advanced button and on the opened panel under Permissions entries I selected the account or user that has Deny under type and clicked the button Change Permissions... And I also select the user that has a Deny under Type on the opened panel and clicked the button Edit... Than the panel Titled Permission Entry for mytestfiled because I've protected this file with permissions the Deny Permission is the one being ticked here so I chosen Allow and it then ticked it and I click Ok and on the shown panel I clicked Appy and Ok and also on the other panel I clicked Ok and the same with the last panel that I've opened I Clicked Ok and I try to open the file again that was protected by permission and now I can access it, so my point is how can I prevent this from being done because I don't want a user to do what I just did on this file it, I think the best thing is to protect the file with a password so that when a user try to open it the password prompt will show and if the user enter invalid password then he/she will not access this file but if the password entered is correct then the file can be accessed. LEt me just explain how I protect the file, first of all I created the file manually on my drive then debugged my program and on the program I have a button to browse to the folder that I want to protect then the path to the file is entered to a textbox and I also have 2 Buttons one for protecting the selected file and the other for unprotecting the file, well I won't go with the code for browsing will just go with how I protect the file and here is the code I used:
Dim pFile As FileSystemSecurity = File.GetAccessControl(txtFile.Text, AttributeTargets)
pFile.AddAccessRule(New FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Deny))
File.SetAccessControl(txtFile.Text, pFile)

And that is how I protect the file. So what I want at least hide the file after protecting it if that is possible but I also must be able to locate it because there is another program that I will create that will be using this file but that program will provide the file with the permissions so that it can be granted access, or if this is possible to just grant my programs only to have access to this file and make changes to it, modify it etc but NOT THE USER no matter who is the user by can't be given permissions to change the file permissions at all not even an administrator the reason for this is that I want this file to be secured so because it will be containing confidential and critical files inside which when a user want to open he has to execute my program and view it from there only but not access it direct because the i want to hide the file or protect it from being opened by a human being or any other programs other then my program.
Sorry for not formating the codes I'm using a Mobile Phone at the moment my Laptop can't connect to the Internet due to missing Drivers.

Thank you I hope I didn't confused you.

Dude, i am confused, so i just gave attendance to top lines...
and what i get is:
I am not sure but what you are saying is: You don't want the access to the folder for any user, ok?
I can do this...
But now some more you is: While user try to open the folder pop up with msg...
Oops, I don't have Any Idea for this...
(I haven't read your Full article, i just follow up with the top- line)

i hope this Help You.
I am telling you to use Folder locker (created in vb.net)
So i have created Folder Locker in vb for you. (you can use folder locaker code here)
Project File

If your question is unsolved still now then Try to show me your codes with the Images. so I may Help you

commented: huh, your Locker help me to keep my data persnal +0

because of the big paragraphs I get confused as I couldn't understand it much more.
then too, I think you want to create a txt file which can not be access from the user ? so this mean you like to create encrypted txt file.
untill I know you could not do this. (not sure)
but you can encrypt with folder Locker That I mention in the above comment.
you can place the text file location as default location in folder Locker
so when you click edit at the moment the file will be unlock and then again the txt file will be released. but after it so you are clicking protect (works as lock Folder) then this will lock the file so it will not be open...

The Unprotect (unlock Folder) code must be at Form_Load() events so that as soon as you open the file this will unlock the folder and the Txt file will be edited

The Protect (lock Folder) code must be at the Form closing events so that whenever you close the program Folder will be lock, and txt file will be encrypted at that momnet

[note: by unlocking the folder twice may lead to some problem, so you must type the code where procedure could not be copied]

Is your question seems correct to me?
if not then
Share your doubt in short and example
else
if I helped = true then
upvote me() = true
else : Problem?
End If

Wow thanks dude with that program that was what I want that the permissions can not be changed so now I have four questions regarding your program to meet my intentions,

1) I noticed that while the folder is locked it can be deletedm My first question is that how can I make it undeletable.

2) How can I read the contents inside without unlocking it.( I know this will sound confusing so at the moment just ignore this I will explain later what I mean by this)

3) The contents inside the file, If I burn the folder while protected to the Disc like DVD or CD can I be able to unlock it later or perhaps copy it from the disc while it is protected to my computer and the unLock the file to view the contents let me say I got Two computer the 1st computer is the computer that I burn the locked file to the disc with and the second computer is the computer that I want to copy or open the protected file at so that I can view the files inside the protected file I know that on the second computer I have to also have the program to unlock the file so let say I already have it running on that computer.

4) How to make the protected file uncopied?

Thank you again.

Ok,
so i am correct from what you mean and i like as i helped you out...
Now you get with the new question. from it now let me answer those questions

1.) I never find such program/file that can't be deleted. (This only happens if the file is in use or i don't know there is any change in registry)

2.) You can not read the file without unlocking (i never try it so) {you can just try it so...)

3.) this is not possible. (CD is not writable)
Reason:

  • If CD/DVD is writable then it will work else not because you are not having any permission to edit in the cd/dvd
  • this is working with USB

4.) I am also trying this for 3-4 months...
but yet don't get anything...

I will try to get some details about this...
as soon as i get the details I will PM you or post it on my website with mail you

I hope your question is solved,
so please give upvote with comment thank you and mark question as solved.
else what more things you want except this?

Thank you I will vote up with a computer because at the moment I'm using a mobile phone to post threads and there are lots of options which are not visible on this forum such as voting up (it is visible but when I clicked at it, it do nothing I think the problem is with the browser that I'm using on this phone) and the code format panel is totally invisible on my mobile phone.
Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.