Results 1 to 19 of 19

Thread: Lock folder(s) by programming

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63

    Question Lock folder(s) by programming

    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?

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63
    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!

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63

    btw...

    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

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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.

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63
    I use win server 2003
    i will give it a try then reply! thanks for help again!

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63

    er ... that sample ...

    yeah, that sample is written in vb 6?
    that sample doens't work with vs .net 2003!

  8. #8
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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!

  9. #9
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Actually you probably want to look at this also:
    http://www.mvps.org/vbnet/index.html?code/wmi/

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63
    thanks a lot. i will give it a try!

  11. #11
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Here is another MSDN article that is more .NET oriented (C# though)
    http://msdn.microsoft.com/msdnmag/is...n/default.aspx

  12. #12
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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).

    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
    See, that returns a list of the methods, but I can't figure out the syntax for actually calling the method. Sorry!

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2003
    Location
    CANADA
    Posts
    63

    :S

    :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!

  14. #14
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    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...

  15. #15
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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!

  16. #16
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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??
    Attached Images Attached Images  
    Last edited by Slow_Learner; Apr 28th, 2003 at 02:24 AM.

  17. #17
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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)

  18. #18
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Talking

    Yea... plz stop whining and write us an easy to use class or component already...

  19. #19
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width