Jump to content

Directory and quota creation


skysel
 Share

Recommended Posts

Hi to all :mellow:

I've created script to create folders and quotas on our fileserver. I would like to know, how to modify script in a way, that it would read usernames from a file, then do specified things for all those usernames? I've been fooling around with _FileReadToArray but I just can't understand how to use an array (call me stupid)...

below is the script:

#include <GUIConstants.au3>


DIM $USER
$USER = InputBox("User", "Vpii uporabniko ime:")

$intWindowWidth = round(200, 0)
$intWindowHeight = round(130, 0)    
$objWindow = GUICreate("Directories", $intWindowWidth, $intWindowHeight)

GUISetState()

$Personal = GUICtrlCreateCheckbox("Personal", 30, 20, 120, 25)  
$RoamingAndPersonal = GUICtrlCreateCheckbox("Roaming + Personal", 30, 60, 120, 25)  
$Roaming = GUICtrlCreateCheckbox("Roaming", 30, 100, 120, 25)

GuiSetState()


While 1
$Msg = GUIGetMsg()
Switch $msg 

Case $Personal
    DirCreate('E:\Personal\' & $USER)
    If FileExists('E:\Personal\' & $USER) Then
    ProgressOn("Progress Meter", "", "0 percent")
    RunWait("CACLS E:\Personal\" & $USER & " /E /T /C /G " & $USER & ':C', '', @sw_hide)
    RunWait("cacls.exe E:\Personal\" & $USER & " /E /R 'CREATOR OWNER'", '', @sw_hide)
    RunWait('dirquota.exe quota add /path:"E:\Personal\"' & $USER & ' /sourcetemplate:"500MB Limit - Personal"', '',@SW_HIDE)
    ProgressSet( Round(1 / 1 * 100, 0), Round(1 / 1 * 100, 0) & " percent")
    ProgressSet(100, "Done", "Complete")
    Sleep(2000)
    ProgressOff()

Else
    MsgBox(0,"Napaka","Direktorij ne obstaja!")
    Exit
EndIf
    
Case $RoamingAndPersonal
    DirCreate('E:\Personal\' & $USER)
    DirCreate('E:\Profiles\' & $USER)
    If FileExists('E:\Personal\' & $USER) And FileExists('E:\Profiles' & $USER) Then
    ProgressOn("Progress Meter", "", "0 percent")
    RunWait("CACLS E:\Profiles\" & $USER & " /E /T /C /G " & $USER & ':F', '', @sw_hide)
    RunWait("cacls.exe E:\Profiles\" & $USER & " /E /R 'CREATOR OWNER'", '', @sw_hide)
    RunWait("CACLS E:\Personal\" & $USER & " /E /T /C /G " & $USER & ':C', '', @sw_hide)    
    RunWait("cacls.exe E:\Personal\" & $USER & " /E /R 'CREATOR OWNER'", '', @sw_hide)
    RunWait('dirquota.exe quota add /path:"E:\Personal\"' & $USER & ' /sourcetemplate:"500MB Limit - Personal"', '',@SW_HIDE)
    RunWait('dirquota.exe quota add /path:"E:\Profiles\"' & $USER & ' /sourcetemplate:"300 MB - Profiles"', '',@SW_HIDE)
    ProgressSet( Round(1 / 1 * 100, 0), Round(1 / 1 * 100, 0) & " percent")
    ProgressSet(100, "Done", "Complete")
    Sleep(2000)
    ProgressOff()

Else
    MsgBox(0,"Napaka","Direktorij ne obstaja!")
    Exit
EndIf
    
Case $Roaming
    DirCreate('E:\Profiles\' & $USER)
    If FileExists('E:\Personal\' & $USER) Then
    ProgressOn("Progress Meter", "", "0 percent")
    RunWait("CACLS E:\Profiles\" & $USER & " /E /T /C /G " & $USER & ':F', '', @sw_hide)
    RunWait("cacls.exe E:\Profiles\" & $USER & " /E /R 'CREATOR OWNER'", '', @sw_hide)
    RunWait('dirquota.exe quota add /path:"E:\Profiles\"' & $USER & ' /sourcetemplate:"300 MB - Profiles"', '',@SW_HIDE)
    ProgressSet( Round(1 / 1 * 100, 0), Round(1 / 1 * 100, 0) & " percent")
    ProgressSet(100, "Done", "Complete")
    Sleep(2000)
    ProgressOff()

Else
    MsgBox(0,"Napaka","Direktorij ne obstaja!")
    Exit
EndIf   

Case $GUI_EVENT_CLOSE
Exit

EndSwitch
WEnd
Link to comment
Share on other sites

I've created script to create folders and quotas on our fileserver. I would like to know, how to modify script in a way, that it would read usernames from a file, then do specified things for all those usernames? I've been fooling around with _FileReadToArray but I just can't understand how to use an array (call me stupid)...

Add this:

#include <File.au3>
Dim $usernames
_FileReadToArray([your file], $usernames)

For $i = 1 to $usernames[0] ;zeroth element contains number of records
    ;do those specified things you are supposed to do
Next

Learning is a continuous process. Everyone learns from everyone. That's why we have the AutoIt Forums.

Edited by system24
[center]It's a question of mind over matter, if I don't mind, it doesn't matter.[/center]
Link to comment
Share on other sites

I was there at one point, once arrays click it all opens up. for filereadtoarray you would do something like

$files = _filereadtoarray(C:\something)

this will return

$files[0] = # of files found

$files[1] = first file

$files[2] = second files

and so on

so just to experiment, after your file read to array put this in

for $i = 1 to $files[0]

msgbox(0,"","$files[$i],3)

next

This will make a message box with the file name that will close in 3 seconds and open another message box with the next file name. That should help you get an idea of how they work and how to use them.

Giggity

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...