Als je een PCL printopdracht opslaat in een bestand (voorbeeld: fakturen.prn) dan kun je deze met een copy commando kopieren naar een geshared printer waarna deze mooi uitgepirnt wordt.
voorbeeld:
copy fakturen.prn //mijnserver/hp4000
Nu probeer ik een programma in vb.net te schrijven die dit doet onder andere gebruikersnaam. Alles gaat goed, aanmaken van de gebruikers etc, alleen de printopdracht wordt niet gekopieerd. Ook als ik hem wil kopieren naar een andere directory dan gebeurt dit niet.
Mijn code:
voorbeeld:
copy fakturen.prn //mijnserver/hp4000
Nu probeer ik een programma in vb.net te schrijven die dit doet onder andere gebruikersnaam. Alles gaat goed, aanmaken van de gebruikers etc, alleen de printopdracht wordt niet gekopieerd. Ook als ik hem wil kopieren naar een andere directory dan gebeurt dit niet.
Mijn 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
| Imports System.IO Imports System.Diagnostics Public Class Form1 Public watchfolder As FileSystemWatcher Public ComputerName As String Public PrintQueue As String Public Password As String Public ini As New iniFile(Environment.CurrentDirectory + "\settings.ini") Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Password = "P@ssw0rd" watchfolder = New System.IO.FileSystemWatcher() 'this is the path we want to monitor watchfolder.Path = ini.GetString("main", "folder", "") 'Add a list of Filter we want to specify 'make sure you use OR for each Filter as we need to 'all of those watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _ IO.NotifyFilters.FileName watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _ IO.NotifyFilters.Attributes ' add the handler to each event AddHandler watchfolder.Created, AddressOf CopyJob MsgBox(ini.FileName) MsgBox(watchfolder.Path) 'Set this property to true to start watching watchfolder.EnableRaisingEvents = True End Sub Private Sub StartCommand(ByVal Command As String, ByVal Args As String, ByVal User As String, ByVal Password As String, ByVal WorkDir As String) Dim ProcessInfo As New ProcessStartInfo Dim sstr As New System.Security.SecureString Dim pwd As String = Password Dim chars() As Char = pwd.ToCharArray() Dim i As Integer For i = 0 To chars.Length - 1 sstr.AppendChar(chars(i)) Next ProcessInfo.UseShellExecute = False ProcessInfo.UserName = User ProcessInfo.Password = sstr ProcessInfo.FileName = Command ProcessInfo.Arguments = Args ProcessInfo.WorkingDirectory = WorkDir ProcessInfo.WindowStyle = ProcessWindowStyle.Hidden ProcessInfo.CreateNoWindow = True Dim myProcess As New Process() myProcess.StartInfo = ProcessInfo myProcess.Start() End Sub Private Sub CreateUser(ByVal User As String) 'Create Account Dim strUser As String = User Dim oDomain As Object = GetObject("WinNT://" + ComputerName) Dim oUser As Object = oDomain.Create("user", strUser) If (Err.Number = 0) Then oUser.SetInfo() oUser.SetPassword(Password) oUser.SetInfo() End If End Sub Private Sub DeleteUser(ByVal User As String) Dim strUser As String = User Dim oDomain As Object = GetObject("WinNT://" + ComputerName) Try Dim oUser As Object = oDomain.Delete("user", strUser) Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub CopyJob(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs) Dim filename As String = e.FullPath MsgBox(filename) ComputerName = System.Environment.MachineName PrintQueue = ini.GetString("main", "printqueue", "") Dim Username As String = "" If Not e.Name.IndexOf("_") = -1 Then Dim NewOwner() As String = e.Name.ToString.Split("_") Username = NewOwner(0) End If If Not Username = "" Then DeleteUser(Username) CreateUser(Username) StartCommand("c:\windows\system32\cmd.exe", "/c copy " & filename & " " & PrintQueue, Username, Password, watchfolder) DeleteUser(Username) MsgBox("Done") End If End Sub End Class |
[ Voor 5% gewijzigd door Verwijderd op 17-01-2006 15:26 ]