I'm just wondering and I've been thinking of this, how to lock certain folder(s) by programming in VB .NET like to prevent guests using certain user by locking the folder(s) with a password or stuff like that. Anyone got some idea?
Printable View
I'm just wondering and I've been thinking of this, how to lock certain folder(s) by programming in VB .NET like to prevent guests using certain user by locking the folder(s) with a password or stuff like that. Anyone got some idea?
How exactly do you mean "lock"? How will the user view your folder (I assume you mean file directory?) - will they be sitting at the local computer, looking at it from across a network, browsing it via http or what?
If you are interested in manipulating file security e.g. right-click on file and click the Properties context menu, then the Security tab - you can do this in a couple of ways. One, you can use Windows Management Interface to call the ChangeSecurityPermissions method:
ms-help://MS.VSCC/MS.MSDNVS/wmisdk/r_32os2_7uk9.htm
^^ part of the platform SDK docs ^^
Two, you could invoke the SetFileSecurity system API functions :
ms-help://MS.VSCC/MS.MSDNVS/security/acctrlow_9kvt.htm
^^ also part of platform SDK docs ^^
Option one is probably a lot simpler. Try searching the forum a bit:
http://www.vbforums.com/showthread.p...&highlight=wmi
yeah i mean file directories. any file directories. maybe it's just a folder on the desktop (local drive, not internet or networkin or something complex)
and well, do you know sometimes you need to enter the password when you wanna access a folder located on Network Neighbor Place? What I mean is just like that. You need to enter password for a folder before you can access it!
yeah btw, o very quickly read over that thread, I just want it to work on ONE computer without networking. and i wonder how you can do it in .net 2003 too
thanks for help again :)
cheers
Writing something that will prompt the user for a password is actually going to be quite a bit more complicated than just denying access to everyone except those allowed. What operating system are you talking about? If you are using Windows 95, 98 or Me then this is very difficult, because those operating systems do not support file security.
If you are using Windows NT, 2k, or XP then you can use the methods I mentioned earlier, and probably you can just use the sample app in the forum thread I pointed you to.
As far as using .NET to secure files or directories - the .NET framework doesn't have any function for tasks like this, things that deal closely with the operating system like file security or user accounts. You have to work through Windows Management Interface or the API.
I use win server 2003
i will give it a try then reply! :) thanks for help again!
yeah, that sample is written in vb 6?
that sample doens't work with vs .net 2003! :(
Yeah, looks like the project converter won't upgrade it (I have VS.NET 2002). Looks like you get to roll up your sleeves and apply some elbow grease:
ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconplatforminvokeexamples.htm
^^ examples of platform invoke ^^
Apply the above to translating the API declarations. I personally hate working with the API and thus am not terribly motivated to do it for you. Good luck!
Actually you probably want to look at this also:
http://www.mvps.org/vbnet/index.html?code/wmi/
thanks a lot. i will give it a try!
Here is another MSDN article that is more .NET oriented (C# though)
http://msdn.microsoft.com/msdnmag/is...n/default.aspx
Out of stubborn-ness I've been trying to figure out the syntax for a WMI method call without going through the Scripting API - and I can't. I'm ticked that this is so poorly documented. Lots of samples of how to run queries, nothing on calling methods in classes (although I've figured out how to list the methods themselves).
See, that returns a list of the methods, but I can't figure out the syntax for actually calling the method. Sorry!Code:Dim mgCls As New ManagementClass("Win32_Directory")
Dim mCol As MethodDataCollection = mgCls.Methods
Dim m As MethodData
ListBox1.Items.Clear()
For Each m In mCol
ListBox1.Items.Add(m.Name)
Next
:s
My friend sent a program that does exactly what I want and that program was written in vb 5! How is it possible to do so in vb5 if we can't do it in vb .net?
Btw, I am a newbie to .net so I dunno too much of it yet!
Anything you could do in VB5 can be done in VB. NET....
Obviously, this VB5 program used API calls.... and that's all you need to do, call Win32API's from .Net....
so simply get the source and port it over...
GRR!!
http://www.microsoft.com/downloads/d...8-6E22115FFAF0
"Management Data allows the developer to browse and modify WMI data as well as invoke methods."
Damn thing! WORK DAMMIT!
Aha, VICTORY! Or at least a little progress. Funny, for all I thought that WMI would be the "easy" way to get it done it sure isn't turning out to be...
edit: Hmm, even though the extensions are there, to actually get ChangeSecurityPermissions to work you still have to do some amount of API work - ChangeSecurityPermissions expects a SECURITY_DESCRIPTOR structure that has to be declared, initialized and properly set before it will actually do anything. That's enough for me! *gag*
ms-help://MS.VSCC/MS.MSDNVS/security/accctrl_6i5u.htm
Why won't they make this at least a little bit less painful??
Apparently that's not true. .NET has a class called InstrumentedAttribute that exposes a property called SecurityDescriptor that seems to be what ChangeSecuritySettings is looking for.
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemmanagementinstrumentationinstrumentedattributeclasssecuritydescriptortopic.htm
(whine)
Yea... plz stop whining and write us an easy to use class or component already...
Well I really wanted to figure out how to do it with WMI, because other things are very easy to do using it, but in this case it looks like the WMI file security documentation isn't good enough. The API is simpler because of the many existing examples in VB6 and Platform Invoke under .NET. Sorry.