Sign in to follow this  
Followers 0
Sarah2016

Library Printing Services

6 posts in this topic

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!?

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by j0kky

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by Sarah2016

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by j0kky

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by j0kky

Share this post


Link to post
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
Sign in to follow this  
Followers 0