bobbykohn Posted February 7, 2012 Share Posted February 7, 2012 I've wrote my first very simple program below, but for whatever reason I can't get the Final If statement (commented out) to work using the variables I set. I must be missing something very simple, but I figured someone could look at it very briefly and let me know. Thanks!!! $sizeCIS = DirGetSize("C:\Users\CIS", 0) $sizeDefault = DirGetSize("C:\Users\Default", 0) RunWait("cacls C:\Users\CIS /t /e /g Administrators:F") RunWait("cacls C:\Users\Default /t /e /g Administrators:F") If FileExists("C:\Users\Default") Then DirRemove("C:\Users\Default", 1) Sleep(500) DirCreate("C:\Users\Default") Sleep(500) DirCopy("C:\Users\CIS", "C:\Users\Default", 1) EndIf MsgBox(0, "Done", "Size(bytes):" & $sizeCIS & @CRLF & "Size(bytes):" & $sizeDefault) ;If $sizeCIS == $sizeDefault Then ; MsgBox(0, "Copy Completed", "CIS profile has copied successfully.") ; ElseIf MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") Then ;EndIf Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 I have heard that you should only use == comparing characters of a string. Is your comparison a string or numeric?, it looks like it might be numeric. I came to autoit from C++ myself so it is natural for me to use ==, but just one = is all it takes for comparison here and I have heard double = can cause problems. I'll start debugging your code on my end now. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 (edited) Oh geez, dirgetsize() returns an array use: If $sizeCIS[0] = $sizeDefault[0] Then Put your mouse over the DirGetSize function label in SciTE and press F1 or lookup "autoit dirgetsize" manually with the google. Edited February 7, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
bobbykohn Posted February 7, 2012 Author Share Posted February 7, 2012 Thanks, but when I use the array [0] it gives "Error subscript used with non-Array variable." I tried that before and I've read on the function, but can't find what I'm doing wrong. I don't have a programming background (obviously), but would like something like this just to do a repeated task at work. Thanks for the input!...Not sure what's going on still though. Link to comment Share on other sites More sharing options...
bobbykohn Posted February 7, 2012 Author Share Posted February 7, 2012 Also the variables are setting the correct numeric values that I am looking for so they're equal. I used = and == hoping that it was the issue, but neither seem to make a difference. Thanks Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 I'm sorry for not being thorough, in fact I skimmed too fast, your not using the parameter for the array so no array is returned. I apologize for my sloppy misguided response. What do you want the program to do? I have never used cacls before. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 (edited) Try changing your block IF structure to look like this: If $sizeCIS == $sizeDefault Then MsgBox(0, "Copy Completed", "CIS profile has copied successfully.") Else MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") EndIf Your previous Else was stated as an elseif but there was no condition to the elseif so I figure it's just an else I'm pretty sure that is your solution and or bug. Edited February 7, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
bobbykohn Posted February 7, 2012 Author Share Posted February 7, 2012 No problem. I appreciate any input. I basically just want to copy a directory (our "CIS" profile in Windows7) and replace the "Default" profile. I found that this was easy enough to do and ran the program on a couple hundred computers, but I found a couple rare instances where the administrator didn't have permissions to some of the files in the "CIS" profile. Therefore the program would fail without warning, because I didn't have any error checking in it. The cacls is a command prompt command to give permissions of folders/files to users (in this case full rights to an administrator). Thanks again! Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 (edited) I will find a use for cacls; a nice tool to have around. Thank you for the upgrade. I left a Then statement previously in my solution above. It was an error and has been removed.The correct IF block structure is here:If $sizeCIS == $sizeDefault Then MsgBox(0, "Copy Completed", "CIS profile has copied successfully.") Else MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") EndIf Edited February 7, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
bobbykohn Posted February 7, 2012 Author Share Posted February 7, 2012 (edited) I tried that and you're probably right that the "ElseIf" isn't correct there (I replaced it with Else and removed Then), but the program still isn't working properly as the 2 folder sizes will be different and it still says "CIS profile has copied successfully." ...I'm sure I have something with the syntax incorrect or I'm making a stupid mistake, but this is driving me slightly crazy. lol. Edited February 7, 2012 by bobbykohn Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 (edited) This edited code works for me you can use it to help yourself test. and by works I mean that it will report same-size or differant-size folders good luck! $sizeCIS = DirGetSize("C:Util", 0) $sizeDefault = DirGetSize("C:UtilMedia Replication", 0) ;RunWait("cacls C:UsersCIS /t /e /g Administrators:F") ;RunWait("cacls C:UsersDefault /t /e /g Administrators:F") ;If FileExists("C:UsersDefault") Then ;DirRemove("C:UsersDefault", 1) ;Sleep(500) ;DirCreate("C:UsersDefault") ;Sleep(500) ;DirCopy("C:UsersCIS", "C:UsersDefault", 1) ;EndIf ;MsgBox(0, "Done", "Size(bytes):" & $sizeCIS & @CRLF & "Size(bytes):" & $sizeDefault) out($sizeCIS) out($sizeDefault) If $sizeCIS == $sizeDefault Then MsgBox(0, "Copy Completed", "CIS profile has copied successfully.") Else MsgBox(0, "Copy Failed", "Please check folders as the copy process failed.") EndIf func out($output= "");debug tool ConsoleWrite(@CRLF&$output);to console new line, value of $output EndFunc; end out() sorry if you saw the out("your face") it was just a debug tool. Dumb things keep me laughing inside, I didn't intend any offence. Edited February 7, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Developers Jos Posted February 7, 2012 Developers Share Posted February 7, 2012 Shouldn't you do the following command after you copied everything in stead of the beginning of the script when it is supposed to check the copy went correct?:$sizeDefault = DirGetSize("C:UsersDefault", 0) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
bobbykohn Posted February 7, 2012 Author Share Posted February 7, 2012 Awesome! Thanks Xandy and Jos...I got it working! I appreciate the help. I just moved where the variable was declared like you suggested Jos and it works perfect. Thanks Xandy I'm sure that would have worked too! I'm very happy now. lol. Link to comment Share on other sites More sharing options...
Xandy Posted February 7, 2012 Share Posted February 7, 2012 (edited) Best wishes. I'm glad you got it sorted out. Edited February 7, 2012 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Chimaera Posted February 8, 2012 Share Posted February 8, 2012 Incidentally calcs is a bit depreciated these daysHave a look at icalcs which is a better version to be usinghttp://ss64.com/nt/icacls.html If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now