944,025 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1942
  • C RSS
Jul 3rd, 2005
0

locking folder

Expand Post »
hello, :eek:
hey guys do anyone know
code for locking folder on 98 & xp
help me pls :o
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gluber is offline Offline
2 posts
since Jun 2005
Jul 3rd, 2005
0

Re: locking folder

Locked how? You can set it to be read-only and hidden using SetFileAttributes. That's a quick and easy way to prevent simple viewing of and writing to the directory:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4.  
  5. void werror ( void )
  6. {
  7. char msg[BUFSIZ];
  8. DWORD err = GetLastError();
  9.  
  10. FormatMessage ( FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
  11. MAKELANGID ( LANG_NEUTRAL, SUBLANG_DEFAULT ), msg, BUFSIZ, NULL );
  12.  
  13. fprintf ( stderr, "%s", msg );
  14. exit ( EXIT_FAILURE );
  15. }
  16.  
  17. int main ( int argc, char *argv[] )
  18. {
  19. BOOL rc;
  20.  
  21. if ( argc < 2 ) {
  22. fprintf ( stderr, "usage: $prog <file>\n" );
  23. exit ( EXIT_FAILURE );
  24. }
  25.  
  26. rc = SetFileAttributes ( argv[1],
  27. FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY );
  28.  
  29. if ( rc == 0 )
  30. werror();
  31.  
  32. return EXIT_SUCCESS;
  33. }
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: changing loops (for to while) and (recursive to for)
Next Thread in C Forum Timeline: Why this program won't sort the right way?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC