Sarah2016 Posted December 4, 2016 Posted December 4, 2016 Hi, I am making a script for library printing services in the university. It will run on a public computer for students who will use it to print their documents. The idea of the script is to monitor the balance of printing fees. I made the following script: #NoTrayIcon #include <File.au3> If UBound(ProcessList(@ScriptName)) > 2 Then Exit EndIf $temp = "E,F,G,H,I,J,K,L" $letters = StringSplit($temp, ",") While 1 For $i = 1 to $letters[0] If (DriveStatus($letters[$i] & ":") = "READY") Then Local $Folder = _FileListToArrayRec($letters[$i] & ":", "*.doc*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If IsArray($Folder) Then For $a = 1 To $Folder[0] FileCopy($Folder[$a],@WorkingDir & "\files\",$FC_CREATEPATH + $FC_NOOVERWRITE) Run("count.exe") Next EndIf EndIf Next Sleep(100) WEnd The count.exe file will count how many pages in the doc files and calculate the fees accordingly and add them to a database, then delete the file from the folder. Of course you noticed that While Loop like this is not the proper coding! as it will keep copying even if the same USB is inserted and will count single file thousands time!! How to solve it!?
j0kky Posted December 4, 2016 Posted December 4, 2016 (edited) Don't you think that automatically copying each document from any inserted USB drive is an enormous security issue? And how can you be sure that each file/page you count is printed? Edited December 4, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
Sarah2016 Posted December 4, 2016 Author Posted December 4, 2016 (edited) Oh yes, that's another point! any suggestion? Or we might put an announcement that USB must have only the documents that will be printed?? Edited December 4, 2016 by Sarah2016
j0kky Posted December 4, 2016 Posted December 4, 2016 (edited) A reasonable way to accomplish what you're trying to do is retrieving data from JOB_INFO_1 or JOB_INFO_2 structures, which can be obtained through Print Spooler API Functions, for example EnumJobs or GetJob... Edited December 4, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
Sarah2016 Posted December 4, 2016 Author Posted December 4, 2016 8 minutes ago, j0kky said: A reasonable way to accomplish what you're trying to do is retrieving data from JOB_INFO_1 or JOB_INFO_2 structures, which can be obtained through Print Spooler API Functions, for example EnumJobs or GetJob... thanks, but how? using while loop will result in the problem mentioned in my first post
j0kky Posted December 4, 2016 Posted December 4, 2016 (edited) No problem with While loop because you need to change your entire script, it requires time and a decent level of programming knowledge, and honestly I don't think you can handle it alone because it is quite difficult. I'm sorry but I don't have much free time in this period, but if somebody else can help you writing it, the right sequence should be: - enum printers through EnumPrinters - register each printers for job notifications through FindFirstPrinterChangeNotification - using the returned handle with MsgWaitForMultipleObjects or MsgWaitForMultipleObjectsEx - when you are notified about a job, call FindNextPrinterChangeNotification - call GetJob with the data notified and parse JOB_INFO_1 or JOB_INFO_2 to retrieve TotalPages and PagesPrinted members Good luck! Edited December 4, 2016 by j0kky Spoiler Some UDFs I created: Winsock UDF STUN UDF WinApi_GetAdaptersAddresses _WinApi_GetLogicalProcessorInformation Bitwise with 64 bit integers An useful collection of zipping file UDFs
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