Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. :: Sean Reilly
  2. :: Student Number = 040884276
  3. :: Submitted Wednesday 26th July 2017
  4.  
  5. @echo off
  6. ECHO "Welcome to CST8202 Lab 10 Script - Deletion Version"
  7. ECHO "This script deletes user group and folders based on file input"
  8. ECHO "There will be a prompt to skip deleting user's folders and also groups"
  9. PAUSE
  10.  
  11. :PROMPT:
  12.  
  13. :: Prompt for a variable to set the name of the text file to be used
  14. ECHO "please enter the name of the text file to be used, do not include the file extension"
  15. ECHO "this file should be a source of employee names, employee ids, and groups called "Hires" "
  16. SET /P reil0041-usrfile=
  17. :: Now redefining the variable %reil0041-usrfile% to contain the absolute path
  18. :: This absolute path will lead to the specified text file in C:
  19. SET reil0041-usrfile=C:\Scripts\17S\reil0041\%reil0041-usrfile%.txt
  20.  
  21. :CHOIX:
  22.  
  23. :: Now providing the option to skip deleting the users's folder as well as groups
  24. :: Simple prompt for 1 of 2 paths, incorrect entry will re-run the prompt
  25. ECHO "please specify skipping or deleteting the users's folder"
  26. ECHO "please enter (skip or delete)
  27. SET /P choix=
  28. IF (%choix% == skip ) {
  29. ECHO "You selected to skip deletion of the folders and groups"
  30. PAUSE
  31. GOTO :SKIP:
  32. }
  33. IF (%choice% == delete ) {
  34. ECHO "You selected to run the delete script
  35. PAUSE
  36. GOTO :GROUP_EXTRACT_AND_DELETE:
  37. }
  38. :: Else case simple loop back to the beginning of this section
  39. ELSE {
  40.  
  41. CLS
  42. GOTO :CHOIX:
  43. }
  44.  
  45.  
  46.  
  47. :GROUP_EXTRACT_AND_DELETE:
  48.  
  49. :: Now looking to extract the list of group names one at a time from the text file
  50. :: Duplicate checking will be on a group by group basis
  51. :: Before Deleting a given group we will make sure that it exists
  52.  
  53.  
  54. FOR /F "tokens=3 skip=4" %%G IN (%reil0041-usrfile%) DO NET LOCALGROUP | FIND "%%G" >NUL && NET LOCALGROUP /REMOVE
  55.  
  56. :USER_FOLDER_EXTRACT_AND_DELETE:
  57.  
  58. :: Now looking to extract and delete user folders (which are named from the employee id)
  59.  
  60. FOR /F "tokens=2 skip=4" %%C IN (%reil0041-usrfile%) DO RMDIR C:\%%C
  61.  
  62. :USER_EXTRACT_AND_DELETE:
  63.  
  64. :SKIP:
  65.  
  66. :: Now looking to delete the User profiles
  67. :: Now looking extract the list of users one at a time from the text file and remove them
  68. :: There will be a check to make sure that the user exists before attempting to remove them
  69.  
  70. FOR /F "tokens=1 skip=4" %%U IN (%reil0041-usrfile%) DO NET USERS | FIND "%%U" >NUL && NET USER /REMOVE %%U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement