Naar aanleiding van het artikel How to call the EnumJobs function from a Visual Basic .NET application wil ik verder gaan dan alleen het uitlezen van gegevens over een printjob, ik wil ook gegevens wijzigen.
Er wordt gebruik gemaakt van API calls naar winspool.drv. Je moet een structure bouwen om de gegevens in op te slaan en deze vullen dmv pointer.
In het uitlezen wordt gebruik gemaakt van GetJobs. voorbeeld code:
Om gegevens weg te schrijven kun je gebruiken maken van SetJobs:
Nu snap ik nog niet hoe ik setjob kan gebruiken om bijvoorbeeld de username van een printjob te veranderen (username = eigenaar van een printjob). Zie de structure die gebruikt wordt om de gegevens van een printjob op te slaan:
Overigens heb je ook nog JOB_INFO_1 en JOB_INFO_3 structures.
Was is de manier om bijvoorbeeld de username te veranderen in de printjob?
Er wordt gebruik gemaakt van API calls naar winspool.drv. Je moet een structure bouwen om de gegevens in op te slaan en deze vullen dmv pointer.
In het uitlezen wordt gebruik gemaakt van GetJobs. voorbeeld code:
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| <DllImport("winspool.drv", EntryPoint:="GetJob", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=False, _ CallingConvention:=CallingConvention.StdCall)> _ Public Function GetJob _ (<InAttribute()> ByVal hPrinter As IntPtr, _ <InAttribute()> ByVal dwJobId As Int32, _ <InAttribute()> ByVal Level As Int32, _ <OutAttribute()> ByVal lpJob As IntPtr, _ <InAttribute()> ByVal cbBuf As Int32, _ <OutAttribute()> ByRef lpbSizeNeeded As Int32) As Boolean End Function <DllImport("winspool.drv", EntryPoint:="GetJob", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=False, _ CallingConvention:=CallingConvention.StdCall)> _ Public Function GetJob _ (<InAttribute()> ByVal hPrinter As Int32, _ <InAttribute()> ByVal dwJobId As Int32, _ <InAttribute()> ByVal Level As Int32, _ <OutAttribute()> ByVal lpJob As IntPtr, _ <InAttribute()> ByVal cbBuf As Int32, _ <OutAttribute()> ByRef lpbSizeNeeded As Int32) As Boolean End Function |
Om gegevens weg te schrijven kun je gebruiken maken van SetJobs:
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| <DllImport("winspool.drv", EntryPoint:="SetJob", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=False, _ CallingConvention:=CallingConvention.StdCall)> _ Public Function SetJob _ (<InAttribute()> ByVal hPrinter As IntPtr, _ <InAttribute()> ByVal dwJobId As Int32, _ <InAttribute()> ByVal Level As Int32, _ <InAttribute()> ByVal lpJob As IntPtr, _ <InAttribute(), MarshalAs(UnmanagedType.U4)> ByVal dwCommand As PrintJobControlCommands _ ) As Boolean End Function <DllImport("winspool.drv", EntryPoint:="SetJob", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=False, _ CallingConvention:=CallingConvention.StdCall)> _ Public Function SetJob _ (ByVal hPrinter As IntPtr, _ ByVal dwJobId As Int32, _ ByVal Level As Int32, _ <MarshalAs(UnmanagedType.LPStruct)> ByVal lpJob As JOB_INFO_1, _ ByVal dwCommand As PrintJobControlCommands _ ) As Boolean End Function <DllImport("winspool.drv", EntryPoint:="SetJob", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=False, _ CallingConvention:=CallingConvention.StdCall)> _ Public Function SetJob _ (ByVal hPrinter As IntPtr, _ ByVal dwJobId As Int32, _ ByVal Level As Int32, _ <MarshalAs(UnmanagedType.LPStruct)> ByVal lpJob As JOB_INFO_2, _ ByVal dwCommand As PrintJobControlCommands _ ) As Boolean End Function |
Nu snap ik nog niet hoe ik setjob kan gebruiken om bijvoorbeeld de username van een printjob te veranderen (username = eigenaar van een printjob). Zie de structure die gebruikt wordt om de gegevens van een printjob op te slaan:
Overigens heb je ook nog JOB_INFO_1 en JOB_INFO_3 structures.
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _ Friend Class JOB_INFO_2 Public JobId As Int32 <MarshalAs(UnmanagedType.LPStr)> Public pPrinterName As String <MarshalAs(UnmanagedType.LPStr)> Public pMachineName As String <MarshalAs(UnmanagedType.LPStr)> Public pUserName As String <MarshalAs(UnmanagedType.LPStr)> Public pDocument As String <MarshalAs(UnmanagedType.LPStr)> Public pNotifyName As String <MarshalAs(UnmanagedType.LPStr)> Public pDatatype As String <MarshalAs(UnmanagedType.LPStr)> Public pPrintProcessor As String <MarshalAs(UnmanagedType.LPStr)> Public pParameters As String <MarshalAs(UnmanagedType.LPStr)> Public pDriverName As String <MarshalAs(UnmanagedType.U4)> Public LPDeviceMode As Int32 <MarshalAs(UnmanagedType.LPStr)> Public pStatus As String Public lpSecurity As Int32 <MarshalAs(UnmanagedType.U4)> Public Status As PrintJobStatuses Public Priority As Int32 Public Position As Int32 Public StartTime As Int32 Public UntilTime As Int32 Public TotalPage As Int32 Public JobSize As Int32 <MarshalAs(UnmanagedType.Struct)> Public Submitted As SYSTEMTIME Public Time As Int32 Public TotalPages As Int32 |
Was is de manier om bijvoorbeeld de username te veranderen in de printjob?