Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Xcacls.vbs With Gui Innerface (completed!)


  • Please log in to reply
No replies to this topic

#1 Ben Sherrill

Ben Sherrill

    Seeker

  • New Members
  • 10 posts

Posted 10 April 2006 - 03:58 PM

The past couple of days I have been trying to script a GUI related innerface with the XCACLS.VBS for my company so that we could have a quick and easy way to run XCACLS instead of having to try and look up all the switches that are used in it. So I created this little program. You could modify it the way you want, however there are consistency checks in it to make sure that the switch inputs are done correctly. Below is the script and I have attached both the XCACLS and the AU3 script for it. I will answer any questions on it, and all comments are welcomed. If do use this script just remember that I have added in

\\Server\Directory

in a couple of places you will need to change these according to where your files are saved. Otherwise you might have trouble.

This was my first time to write in GUI innerfacing. I feel like a scholar now. :think:

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Author: Ben Sherrill <ben.sherrill@albemarle.com
;
; Script Function:exit

; Changing Group and user permissions using XCACLS
;
; ----------------------------------------------------------------------------
#include "GUIConstants.au3"
#include <file.au3>
#include <Process.au3>
opt("WinTitleMatchMode", 2)

;Message about the program that will be used
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning
MsgBox(48, "Change File Permissions", "The following will change permissions for a Group of users or a Specific user using Xcacls.vbs. To learn more about Xcacls.vbs and its command line options, please see http://support.microsoft.com/?id=825751 'How to use Xcacls.vbs to modify NTFS permissions'")

;Checks to make sure that XCACLS.VBS exists in specified area
If FileExists("xcacls.vbs") Then
Else
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning
MsgBox(48, "File Not Found", "The file Xcacls.vbs was not found! Please make sure that this file is in the same directory as the File Permissions.exe file. Program will now close.")
Exit
EndIf


;Creates a GUI innerface for determining whether or not you want to change permissions on a File or on a Directory.
GUICreate("File Location", 275, 150)
$label1 = GUICtrlCreateLabel("Choose either a File or a Directory.", 10, 10)
$labelfile = GUICtrlCreateLabel("To Choose a file click this file", 10, 35)
$labelfolder = GUICtrlCreateLabel("What file do you want to change?", 10, 75)
$okbutton = GUICtrlCreateButton("OK", 10, 115, 45, 20)
$cancel = GUICtrlCreateButton("Cancel", 70, 115, 45, 20)
$browse = GUICtrlCreateButton("File", 200, 50, 45, 20)
$browse2 = GUICtrlCreateButton("Directory", 200, 90, 48, 20)

;Create input Box
$input = GUICtrlCreateInput("", 10, 50, 170, 20)
$input1 = GUICtrlCreateInput("", 10, 90, 170, 20)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
; Show GUI, and wait for OK to be pressed
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $okbutton
ExitLoop
Case $msg = $cancel
ExitLoop
Case $msg = $browse
$sFileLocation = FileOpenDialog("Select File or Folder", " ", "All (*.*)", 2)
GUICtrlSetData($input, $sFileLocation)
Case $msg = $browse2
$sFileLocation = FileSelectFolder("Select File or Folder", " ", "All (*.*)", 2)
GUICtrlSetData($input1, $sFileLocation)
EndSelect
WEnd
GUIDelete()

;Lets the user know of the Directory/File they have Choosen to change the permissions to.
MsgBox(4096, "Selection", "You have choosen " & $sFileLocation & " to change permissions on.")


;Ask for user/group to grant/revoke/deny rights to.
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No
If Not IsDeclared("sgroupuser") Then Dim $sgroupuser
$sgroupuser = InputBox("Group or User", "Please type in the Group or User account that you would like to give access to the file named " & @CRLF & @CRLF & $sFileLocation, "alb\cat_admins", " ", "300", "200", "-1", "-1")
Select
Case @error = 0 ;OK - The string returned is valid

Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open

EndSelect


;Displays and asks the user what type of options they would like to use. Grant Rights Deny Rights Revoke Rights Inherit Rights
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No
If Not IsDeclared("sFileLocation") Then Dim $options1
$options1 = InputBox("Program Options", "Please type which ever options you would like using spaces between each one." & @CRLF & @CRLF & "/e Edit ACL instead of replacing it." & @CRLF & @CRLF & "/g Grant security permissions." & @CRLF & @CRLF & "/r Revoke security permissions." & @CRLF & @CRLF & "/d Deny security permissions." & @CRLF & @CRLF & "/i (Enable/Copy/Remove) Inheritance flag. Enbale will turn on. Copy will turn off the flag and copy the inherited ACL's. Remove will turn off the flag and will not copy inherited ACL's.", "/e /g", " ", "450", "300", "-1", "-1")
Select
Case @error = 0 ;OK - The string returned is valid

Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open

EndSelect

;Runs and checks on the rights input in by the user to make sure that they have been done correctly.
;If not Pops up an error message stating that if the script is run in its current condition that it may not create the correct rights.
Select
Case $options1 = "/e"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will not Grant or Revoke rights to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " Please exit the program and make sure to choose /g /r or /d to change rights.")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /g"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit and Grant rights to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /g /i enable"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Grant and Enable Inherited permissions to " & $sFileLocation & " " & @CRLF & "for " & $sgroupuser & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /g /i copy"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Grant and Copy Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /g /i remove"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Grant and Remove Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /r"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit and revoke rights to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /r /i enable"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Revoke and Enable Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /r /i copy"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Revoke and Copy Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /r /i remove"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Revoke and Remove Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect


Case $options1 = "/e /d"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit and Deny rights to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /d /i enable"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Deny and Enable Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /d /i copy"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Deny and Copy Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /d /i remove"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Deny and Remove Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /i enable"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, Enable Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /i copy"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, and Copy Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options1 = "/e /i remove"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your Editing Options", "Your options are" & @CRLF & $options1 & @CRLF & "using these options will Edit, and Remove Inherited permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case Else

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Critical
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(17, "Possible Error", "The Program was unable to determine the options you have chosen for the specified path. When the script runs, it may create errors and not set the permissions correctly. You may want to exit and start over making sure the parameters are correct. To COntinue Press Ok to exit press Cancel.")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
EndSelect


; Options #2 for deciding what the first options will act upon. Just a file? Just a folder? Subfolders? Traverse folders?
; InputBox features: Title=Yes, Prompt=Yes, Default Text=No
If Not IsDeclared("sFileLocation") Then Dim $options2
$options2 = InputBox("Program Options", "Please type which ever options you would like using spaces between each one." & @CRLF & @CRLF & ":f This will change all file Permissions. IMPORTANT: When revoking rights, the : must be changed to a / with a space before it. If this not done, revoking rights will not work!" & @CRLF & @CRLF & "/s This will change all subfolders under the inputted directory but will NOT traverse subdirectories unless /t is also present. If filename is a directory, and /s is not used, nosubdirectories will be touched." & @CRLF & @CRLF & "/t Traverses each subdirectory" & @CRLF & @CRLF & "The default is for all subfolders and files with in the folders and subfolders.", ":f /s /t", " ", "450", "300", "-1", "-1")
Select
Case @error = 0 ;OK - The string returned is valid

Case @error = 1 ;The Cancel button was pushed
Exit
Case @error = 3 ;The InputBox failed to open

EndSelect


; Options #2 for deciding what the first options will act upon. Just a file? Just a folder? Subfolders? Traverse folders?
; Creates an error message if the user input is not known, and states that the script may not run correctly!
Select
Case $options2 = ":f"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit only specific FILE permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
Case $options2 = " /f"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit only specific FILE permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
Case $options2 = ":f /s"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit FILE and Subdirectory permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
Case $options2 = " /f /s"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit FILE and Subdirectory permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
Case $options2 = ":f /s /t"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit FILE, Subdirectory permissions and will Traverse each subdirectory to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options2 = " /f /s /t"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit FILE, Subdirectory permissions and will Traverse each subdirectory to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
Case $options2 = " /s"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit only Subdirectory permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect

Case $options2 = " /s /t"
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Info
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(65, "Your File Options", "Your options are" & @CRLF & $options2 & @CRLF & "using these options will Edit Subdirectory and Traverse the permissions to " & $sFileLocation & " " & "for " & $sgroupuser & @CRLF & " If this is not correct then press Exit and rerun the program!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect


;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=Critical
Case Else
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(17, "Possible Error", "The Program was unable to determine the options you have chosen for the specified path. When the script runs, it may create errors and not set the permissions correctly. You may want to exit and start over making sure the parameters are correct. To COntinue Press Ok to exit press Cancel.")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect
EndSelect

;Create a GUI innerface for Placement of user's LOG File
GUICreate("Log File", 250, 150)
GUICtrlCreateLabel("Where would you like your Log file placed.", 10, 10)
GUICtrlCreateLabel("Make sure the directory has NO Spaces.", 10, 25)
GUICtrlCreateLabel("Correct = C:\Sample_Directory ", 10, 50)
GUICtrlCreateLabel("Incorrect = C:\Sample Directory ", 10, 65)
$okbutton2 = GUICtrlCreateButton("OK", 10, 110, 45, 20)
$cancel2 = GUICtrlCreateButton("Cancel", 70, 110, 45, 20)
$browse2 = GUICtrlCreateButton("Browse", 165, 80, 45, 20)

;Create input Box
$input2 = GUICtrlCreateInput("", 10, 80, 140, 20)
GUICtrlSetState(-1, $GUI_ACCEPTFILES)
; Show GUI, and wait for OK to be pressed
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $okbutton2
ExitLoop
Case $msg = $cancel2
ExitLoop
Case $msg = $browse2
$logloc = FileSelectFolder("Select Folder", " ", "All (*.*)", 2)
GUICtrlSetData($input2, $logloc)
EndSelect
WEnd
GUIDelete()


;Displays a message to the user of how the script will be placed in the CMD window.
; Give the option to cancel the run.
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK and Cancel, Icon=None
If Not IsDeclared("iMsgBoxAnswer") Then Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(1, "Selected Options", "The following line of script will run for xcacls.vbs" & @CRLF & @CRLF & "xcacls.vbs " & $sFileLocation & " " & $options1 & " " & $sgroupuser & $options2 & @CRLF & @CRLF & "Your Log file will be created in " & $logloc & "\user_group.log" & @CRLF & " If this is incorrect please Canel and start over!")
Select
Case $iMsgBoxAnswer = 1 ;OK

Case $iMsgBoxAnswer = 2 ;Cancel
Exit
EndSelect


; Creates the batch file user_group_rights.bat in the same directory of which the script will use to run the program.
; I HAD TO MAKE THIS SECTION UNC TO GET IT TO RUN CORRECTLY!!!! YOU MAY NEED TO
$batch = FileOpen("\\Server\Directory\user_group_rights.bat", 2)
FileWrite($batch, "Cscript.exe /h:cscript" & @CRLF)
FileWrite($batch, "\\Server\Directory\xcacls.vbs ")
FileWrite($batch, $sFileLocation)
FileWrite($batch, " " & $options1 & " " & $sgroupuser & $options2 & " /l" & " " & $logloc & "\user_group.log" & @CRLF)
FileWrite($batch, "exit")
FileClose($batch)

;Runs the batch file.
If FileExists("\\Server\Directory\user_group_rights.bat") Then
Run("\\Server\Directory\user_group_rights.bat")
Else
MsgBox(4096, "No file", "File does not exist")
Exit
EndIf
;Wait until the CMD window is closed to continue XP,2003 Machines
If WinActive("C:\WINDOWS\system32\cmd.exe") Then
WinWaitClose("C:\WINDOWS\system32\cmd.exe")
EndIf
;Wait until the CMD window is closed to continue 2000, NT Machines
If WinActive("C:\WINNT\system32\cmd.exe") Then
WinWaitClose("C:\WINNT\system32\cmd.exe")
EndIf

;Once the CMD window is closed pop up a message stating the script has completed and to check the log file for Unsucsessful instances.
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
MsgBox(64, "Script Complete", "The script has completed please check the log file named user_group.log in the " & $logloc & " directory.")
Exit

Attached Files












0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users