Xonos Posted April 27, 2009 Share Posted April 27, 2009 (edited) Hi, could someone show me an example (if it's possible) of a variable that returns an array of values from an ini file.For example..$My_Array = IniRead("config.ini", "Configuration", "Array1", "NotFound")config.ini[Configuration]Array1=[test.exe, test1.exe, test2.exe, test3.exe]Is this how I'd do it? Basically what I am trying to write is a background service that will close whatever executables I load into the array. (This is for a school environment to close certain games from opening and I think an array would help. As new games are introduced, we can add those proccesses to the ini file and push it out.) Any suggestions? Examples that could help? Edited April 27, 2009 by Richardo [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
colafrysen Posted April 27, 2009 Share Posted April 27, 2009 IniReadSection ? and instead make an .ini that looks like this [games] 1=game1.exe 2=game2.exe 3=game3.exe [font="Impact"]Use the helpfile, It´s one of the best exlusive features of Autoit.[/font]http://support.microsoft.com/kb/q555375ALIBI Run - a replacement for the windows run promptPC Controller - an application for controlling other PCs[size="1"]Science flies us to the moon. Religion flies us into buildings.[/size][size="1"]http://bit.ly/cAMPZV[/size] Link to comment Share on other sites More sharing options...
Xonos Posted April 27, 2009 Author Share Posted April 27, 2009 $games = IniReadSection("settings.ini", "Games")ProcessWait($games)if ProcessExists($games) Then ProcessClose($games)EndIfSettings.ini Contents:[Games]game1=Project64.exeI tried this but it doesn't work. Any pointers? [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 27, 2009 Share Posted April 27, 2009 You need to check each item in the array. You can't pass the array to those functions. Use a loop to check each index individually. Link to comment Share on other sites More sharing options...
Xonos Posted April 27, 2009 Author Share Posted April 27, 2009 You need to check each item in the array. You can't pass the array to those functions.Use a loop to check each index individually.I've always had problems with loops. Could you show me an example? [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
herewasplato Posted April 27, 2009 Share Posted April 27, 2009 (edited) I'll let others help you with the array from an INI thing... I'm not sure why you would need to use an INI file in the first place. You could place a simple text file on a server and update that whenever. The scripts on the local computers would read/split that file and you are ready to start killing processes. $file = FileOpen("games2kill.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $games = StringSplit(FileRead($file), ",") FileClose($file) For $i = 1 To $games[0] MsgBox(0, "", $games[$i]) ;ProcessClose($games[$i]) Sleep(9) Next Edit: The file named "games2kill.txt" would have text like this in it: test.exe, test1.exe, test2.exe, test3.exe Edit2: BTW, as soon as a student learns that they can usually rename the game exe to something like scvhost.exe then you will need to take other measures to counter the running of games. Edited April 27, 2009 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Xonos Posted April 27, 2009 Author Share Posted April 27, 2009 (edited) Dude, that's actually a brilliant idea! How would I make it run in the background and not exit the script when it closes the process? Edit: I read what you said about the executables. The students that get past it and are caught will be removed from the network, so their access to any machine at all will be removed. This is just an extra precaution that would help big time. Edited April 27, 2009 by Richardo [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 27, 2009 Share Posted April 27, 2009 To reread it, just make a loop and have a sleep timer. While 1 ; checking code Sleep(600000) ; 10 minutes WEnd Link to comment Share on other sites More sharing options...
Xonos Posted April 27, 2009 Author Share Posted April 27, 2009 $file = FileOpen("games2kill.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $games = StringSplit(FileRead($file), ",") FileClose($file) While 1 For $i = 1 To $games[0] ;MsgBox(0, "Novell Warden", 'Novell has detected that you are running $games[$i] and has flagged your account. Administrators have been notified.') ProcessClose($games[$i]) Sleep(10000) Next WEnd Halo.exe, Project64.exe, Game3.exe The txt file doesn't work. If I only put 1 exe file there, it will work but adding commas breaks it. I don't think it's parsing each value. I apologize for the silly newbie answers, I am trying my best to learn all of this! [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 27, 2009 Share Posted April 27, 2009 (edited) While 1 For $i = 1 To $games[0] ;MsgBox(0, "Novell Warden", 'Novell has detected that you are running $games[$i] and has flagged your account. Administrators have been notified.') ProcessClose($games[$i]) Sleep(10000) Next WEnd should be While 1 For $i = 1 To $games[0] ;MsgBox(0, "Novell Warden", 'Novell has detected that you are running $games[$i] and has flagged your account. Administrators have been notified.') ProcessClose($games[$i]) Next Sleep(10000) WEnd Also, no spaces between names. Just use a comma and then the next text. Edited April 27, 2009 by Richard Robertson Link to comment Share on other sites More sharing options...
Xonos Posted April 27, 2009 Author Share Posted April 27, 2009 Thank you so very much. You've helped me learn a lot! [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
herewasplato Posted April 27, 2009 Share Posted April 27, 2009 Thank you so very much. You've helped me learn a lot!You are welcome. If you are going to loop it - I would do it like this: ;#NoTrayIcon While 1 $file = FileOpen("games2kill.txt", 0) ;no error checking on opening this file ;since the end user does not need to see that info ;and the loop will attempt to open the file later $whole_file = FileRead($file) FileClose($file) If StringInStr($whole_file, ",") = 0 Then If ProcessExists($whole_file) Then SplashTextOn("Warning", "Do not play games") ;ProcessClose($whole_file) EndIf Else $games = StringSplit($whole_file, ",") For $i = 1 To $games[0] If ProcessExists($games[$i]) Then SplashTextOn("Warning", "Do not play games") ;ProcessClose($games[$i]) Sleep(99) EndIf Next EndIf Sleep(10000) ;every 10 seconds SplashOff() WEndYou can remove the remark in this line ;#NoTrayIcon to have no tray icon and these lines ;ProcessClose($whole_file) ;ProcessClose($games[$i]) to kill the games. Having the loop read the file each time will let you update the file without having to restart the script on each computer... but, you may need a true server operating system to allow for that number of simultaneous connections. If you do not have a server OS and you stick with your original idea of pushing the text file to each computer after each update - then I would still keep the reading of the file in the loop as shown above. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Xonos Posted April 29, 2009 Author Share Posted April 29, 2009 (edited) You are welcome. If you are going to loop it - I would do it like this: ;#NoTrayIcon While 1 $file = FileOpen("games2kill.txt", 0) ;no error checking on opening this file ;since the end user does not need to see that info ;and the loop will attempt to open the file later $whole_file = FileRead($file) FileClose($file) If StringInStr($whole_file, ",") = 0 Then If ProcessExists($whole_file) Then SplashTextOn("Warning", "Do not play games") ;ProcessClose($whole_file) EndIf Else $games = StringSplit($whole_file, ",") For $i = 1 To $games[0] If ProcessExists($games[$i]) Then SplashTextOn("Warning", "Do not play games") ;ProcessClose($games[$i]) Sleep(99) EndIf Next EndIf Sleep(10000) ;every 10 seconds SplashOff() WEndYou can remove the remark in this line ;#NoTrayIcon to have no tray icon and these lines ;ProcessClose($whole_file) ;ProcessClose($games[$i]) to kill the games. Having the loop read the file each time will let you update the file without having to restart the script on each computer... but, you may need a true server operating system to allow for that number of simultaneous connections. If you do not have a server OS and you stick with your original idea of pushing the text file to each computer after each update - then I would still keep the reading of the file in the loop as shown above. Yeah I see that. Great idea!... Thank you very much!! What we do is push the updates by use of Zenworks to each computer. If we update the txt file, we simply do a zen-push and it updates every computer at once. We've got servers covered. Edited April 29, 2009 by Richardo [center][/center][center]Xonos Development[font=trebuchet ms,helvetica,sans-serif]- Resources -[/font]AutoIT Documentation | Active Directory UDF | Windows Services UDF | Koda GUI Designer[/center] Link to comment Share on other sites More sharing options...
herewasplato Posted April 30, 2009 Share Posted April 30, 2009 You are welcome. Can the student get to (edit/change/delete) the local copy of the list of games? It might be better protected on a read-only sever share. [size="1"][font="Arial"].[u].[/u][/font][/size] 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