Closed Thread
Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Looping until a user presses a key?

  1. #11
    mholt is offline Newbie
    Join Date
    Jan 2008
    Posts
    27
    Rep Power
    0
    Well, I'm game for complex and learning this stuff as long as it's easy to use in the end.

    I really don't want you to feel as if you have to continue helping me with this, you've far exceeded what I expected as far as help goes. Take a break (unless you really want to, I mean, I won't stop ya) I have another semester starting up tomorrow, but I'll still be working on it. Again, thanks for all your help!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #12
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    You're welcome. Actually, I enjoy doing this--I'll take any chance to learn. Are you up for learning some Assembly language? We might have to do that for this.

  4. #13
    mholt is offline Newbie
    Join Date
    Jan 2008
    Posts
    27
    Rep Power
    0
    Quote Originally Posted by dargueta View Post
    You're welcome. Actually, I enjoy doing this--I'll take any chance to learn. Are you up for learning some Assembly language? We might have to do that for this.
    Well, assembly language is taking it a little too far, I think... I am thinking right now of just handling one question at a time.

    Would you want to help me develop this, perchance? I haven't found another app lightweight and free... so eh, there might be possibilities. It might be easier to collaborate our ideas...

    Let me know; cause the first concept I want to tackle is the user-control thing, so that only the current logged-on user can have certain file permissions.

  5. #14
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    You've got me really interested in this now. Of course I'd be happy to collaborate! It's not every day I meet a fellow programmer with the same interests.

    A somewhat primitive way of tackling the user name issue is to use (once again) WinAPI to read the user name. If it's not yours, deny all access. I can't remember the function name offhand, but I'll check.

  6. #15
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    Found it--it's a really illogical name for the function:

    [HIGHLIGHT="C"]
    char userBuffer[64];
    //erase the buffer - not necessary if done once, but if done
    //multiple times then yes.
    memset(userBuffer,NULL,64);
    //read the user name into the buffer
    ReadUserName(&userBuffer,63);
    //check the value of the user name
    if(strcmp("MyUserName",userBuffer) != 0)
    printf("ACCESS DENIED.\n");
    [/HIGHLIGHT]
    Last edited by dargueta; 01-22-2008 at 08:03 PM. Reason: Clarified code w/ comment

  7. #16
    mholt is offline Newbie
    Join Date
    Jan 2008
    Posts
    27
    Rep Power
    0
    Hmm... that code doesn't compile in Dev-Cpp under Windows. However, I found this that works:

    Code:
    char userBuffer[64];
    DWORD nUserName = sizeof(userBuffer);
    GetUserName(userBuffer, &nUserName);
    cout << userBuffer << endl;
    This successfully prints my current, logged-on, Windows NT (in my case, Vista, but works for XP and 2000 too) system.

    Now the only problem would be to compare that to any user trying to do operations on the files...

    Btw: I sent you a PM.

  8. #17
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    It doesn't compile because memset() and strcmp() aren't defined, right? You need to include memory.h and string.h.

  9. #18
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59
    I found a way that you can get the owning user name of a process, so you could do the following:
    (1)Find all open handles to your file
    (2)Get the IDs for the processes that own those handles
    (3)Get the user names of those processes' owners
    (4)Check the names against your own
    (5)Use CancelIO() or something like that to invalidate the other handles.

    I found an article on how to do #3, but I don't understand it; maybe you could:
    Get Process User Name
    It's in C#, of which I have no knowledge.

    Here's something about #1...so it is possible, the question is how.
    Getting open handles on a particular file
    Last edited by dargueta; 01-23-2008 at 07:37 PM.

  10. #19
    mholt is offline Newbie
    Join Date
    Jan 2008
    Posts
    27
    Rep Power
    0
    Quote Originally Posted by dargueta View Post
    It doesn't compile because memset() and strcmp() aren't defined, right? You need to include memory.h and string.h.
    Actually ReadUserName was undefined. But that's okay, got another function to work.

    I'll look more into CancelIO(). That Handle thing is a downloadable app for system admins.

    We can continue this via IM/email.

    Toodles

Closed Thread
Page 2 of 2 FirstFirst 12

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. need help with some looping
    By BRUTAL in forum Python
    Replies: 2
    Last Post: 01-24-2011, 02:38 PM
  2. need looping help
    By BRUTAL in forum Python
    Replies: 2
    Last Post: 01-22-2011, 07:57 AM
  3. Executing windows button presses
    By xXAlphaXx in forum C and C++
    Replies: 7
    Last Post: 12-24-2010, 03:57 PM
  4. help with looping
    By Root23 in forum Python
    Replies: 7
    Last Post: 06-10-2010, 08:08 PM
  5. Program that presses a button
    By qscesz in forum Visual Basic Programming
    Replies: 3
    Last Post: 04-15-2009, 07:24 AM

Tags for this Thread

Bookmarks

Posting Permissions

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