|
Hi Dave. I dont really need to know where to print jobs are coming from, I just need to be able to intercept them before they are printed and allow or cancel them. Its basically to control what gets printed and what doesnt.
John
|
|
|
|
|
Someone else posted an idea to attach a system wide message hook. There problem with it is that it will allow you to see the WM_PRINT message, but you can't stop it from happening.
Now, you could put the printers on hold and just monitor the print queues, determine wheather or not to allow the job, then just cancel it or release the printer to print, then put it back on hold.
The problem is your app will have to run as a service with Admin or Power User priveledges in order to put the printers on hold.
There is also another problem, how are you going to determine wheather or not the job should be allowed? What are the requirements for an allowable job vs. not allowable? What mechanism are you going to use to make this determination? You could peak into the job, but all it will show you is the printer language, which will vary from printer to printer, even model to model.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
basically, the print is allowed if the user has enough credit on their account (just a database entry). If there isnt sufficient credit then the print job will be cancelled. It should be all done automatically when the user goes to print. Their balance should be checked against the amount of sheets they are printing, and if there is sufficient balance then the print job can happen, otherwise its stopped.
Regards,
John
|
|
|
|
|
John,
I have no experience about it, but I think you can use "messaging hook provider/processor" to deal with the wm_print Window's message.
There are some articles about that in the help file with the vs.net.
good luck.
|
|
|
|
|
I'm using httpwebresponse and a StringBuilder to return a stream that originates as a file with the .txt suffix (My download code converts the html tags in this text file to well formed XHTML tags). The contents of the file contain html tags and the data in those tags.
eg.,
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
<TBODY>
<TR>
<TD width="48%"></TD>
<TD vAlign=bottom width="5%"><FONT
face="Times New Roman" size=1><B> Howdy!! </B></FONT></TD>
<TD width="47%"></TD></TR>
</TBODY></TABLE>
When I copy, paste and save the returned file from the textbox (txtOutput)with a .html extension, the file opens as a normal looking html file, but when I try to save the stream with an html suffix with the following code, something changes in the file and instead of opening as a normal html file, I instead get what looks like a text file with strikethrough font in numerous places...eg., <strike>Howdy !!</strike>
// Save File-----------------------------------
StreamWriter writer = new StreamWriter(sec_save);
writer.WriteLine(txtOutput.Text.ToString());
writer.Close();
The StreamWriter gets its input from a textbox (txtOutput) that has been populated by a StringBuilder (the html tags in the original text file have actually been converted to an XHTML file, ie well-formed html tags.)
I can supply the code that converts the html to xhtml if needed...
Basically, I'm just trying to find a way to save the stream as an .html file and have it open as any other html file would open, without the strikethroughs.
A different way to save the stream perhaps?
Thanks,
Paul
|
|
|
|
|
I have zonealarm installed and of course everyone knows, the vsmon services is basically the brains behind the outfit...anyways when I look at the services applet and go to options on vsmon almost everything is grayed out...so I went into the registry at
hkey_local_machine\system\currentcontrolset\services\vsmon\security
And in there, is a key called Security...It is a binary key and has a whole bunch of hex written in it. I imagine this is what is causing the services applet in XP to gray out all the configuration for it. Is there a way I can find out how to write my own Security reg keys like this for services I write in c# to keep people from tampering, etc?
P.S. I've already "googled" the matter lol but maybe someone knows the answer elsewhere. Thanks in advance.
|
|
|
|
|
I have a need to monitor a server. I found out that this can be done using FileWatcher. But filewatcher just tells what change & kind of change (delete, rename etc) that has taken place.
I also want to know who (User) made the chane and the machine name or address from where changes has taken place.
Any pointers in this regard
Thanks
Ruchi
|
|
|
|
|
The FileSystemWatcher component - nor the underlying ReadDirectoryChangesW API - record this information. In fact, IIRC, NTFS filesystem doesn't even record this information. There's no entries in it for the journal, at least (NTFS is now a journaling file system).
If you want to see who's got what files open (which may help indicate who changed what) and since this is on a server (so I assume people are accessing files via a UNC share), you could P/Invoke NetFileEnum . I've included some code below that can help and that I wrote some time back to assist with closing open file handles (for executables) in our shared build directory. I make no warranty of it in any way:
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Security;
namespace Example
{
public class NetFiles
{
private const int ErrorFileNotFound = 2;
private const int ErrorAccessDenied = 5;
private const int ErrorMoreData = 234;
private const int MaxPreferredLength = -1;
private const int BufferSize = 4000;
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
private static extern int NetFileEnum
(
[MarshalAs(UnmanagedType.LPWStr)]string serverName,
[MarshalAs(UnmanagedType.LPWStr)]string basePath,
[MarshalAs(UnmanagedType.LPWStr)]string userName,
[MarshalAs(UnmanagedType.U4)]int level,
[MarshalAs(UnmanagedType.SysUInt), Out]out IntPtr buffer,
[MarshalAs(UnmanagedType.U4)]int preferredMaxLength,
[MarshalAs(UnmanagedType.U4), Out]out int entriesRead,
[MarshalAs(UnmanagedType.U4), Out]out int totalEntries,
[MarshalAs(UnmanagedType.U4), In, Out]ref int resumeHandle
);
[DllImport("netapi32.dll", CharSet=CharSet.Unicode)]
private static extern int NetFileClose
(
[MarshalAs(UnmanagedType.LPWStr)]string serverName,
[MarshalAs(UnmanagedType.U4)]int fileID
);
[DllImport("netapi32.dll")]
private static extern int NetApiBufferFree
(
IntPtr buffer
);
private NetFiles()
{
}
public static IList GetOpenFiles()
{
return GetOpenFiles(null, null, null);
}
public static IList GetOpenFilesOnServer(string server)
{
return GetOpenFiles(server, null, null);
}
public static IList GetOpenFilesWithPath(string basePath)
{
return GetOpenFiles(null, basePath, null);
}
public static IList GetOpenFilesForUsername(string username)
{
return GetOpenFiles(null, null, username);
}
public static IList GetOpenFiles(string server, string basePath,
string username)
{
IntPtr buffer;
int entriesRead;
int totalEntries;
int resumeHandle = 0;
ArrayList list = new ArrayList();
int retVal = NetFileEnum(server, basePath, username, 3, out buffer,
BufferSize, out entriesRead, out totalEntries, ref resumeHandle);
while ((retVal == 0 || retVal == ErrorMoreData) &&
buffer != IntPtr.Zero)
{
for (int i=0; i<entriesRead; i++)
{
IntPtr address = new IntPtr(buffer.ToInt32() +
i * Marshal.SizeOf(typeof(FileInfo)));
if (address != IntPtr.Zero)
{
FileInfo info =
(FileInfo)Marshal.PtrToStructure(address, typeof(FileInfo));
list.Add(info);
}
}
NetApiBufferFree(buffer);
if (retVal == ErrorMoreData)
retVal = NetFileEnum(server, basePath, username, 3, out buffer,
MaxPreferredLength, out entriesRead, out totalEntries,
ref resumeHandle);
else break;
}
if (retVal == 0) return list;
else if (retVal == 5) throw new SecurityException("Access denied");
else throw new System.ComponentModel.Win32Exception(retVal);
}
public static void CloseFile(int handle)
{
CloseFile(handle, null);
}
public static void CloseFile(int handle, string server)
{
int retVal = NetFileClose(server, handle);
if (retVal == 0) return;
else if (retVal == ErrorAccessDenied)
throw new SecurityException("Access denied");
else if (retVal == ErrorFileNotFound)
throw new System.IO.FileNotFoundException("The file was not found.");
else throw new System.ComponentModel.Win32Exception(retVal);
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct FileInfo
{
[MarshalAs(UnmanagedType.U4)]public int ID;
[MarshalAs(UnmanagedType.U4)]public FilePermissions Permissions;
[MarshalAs(UnmanagedType.U4)]public int Locks;
[MarshalAs(UnmanagedType.LPWStr)]public string Path;
[MarshalAs(UnmanagedType.LPWStr)]public string Username;
}
[Flags]
public enum FilePermissions
{
Read = 1,
Write = 2,
Create = 4
}
} This information - combined with what you track using the FileSystemWatcher , could help you make adequate guesses as to who changed what file.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi, guys
I use MSComm control to write a serial port communication routine.
But the event "OnComm" don't response. And I have set RThreshold and SThreshold 1. It 's correct when I send out a character, the OnComm event should response, But it not.
What do u think of that?
Expect some serial communication specialists' idea.
Thank a lot
vigorous
|
|
|
|
|
This has nothing to do with serial communications (unless, of course, the serial device is not responding); it has to do with the COM control (it's receiving data and firing events).
Make sure you've attached an EventHandler to the MSComm.OnComm event:
msComm1.OnComm += new EventHandler(this.OnComm); If you haven't attached an event handler, your event handler will not be fired (it's a callback).
For more information about interop'ing the MSComm control, read http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=320[^] from a dev site I haunted long ago.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
from a dev site I haunted long ago
Ah, the old days.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Nick Parker wrote:
Ah, the old days.
Are you nuts? DevHood wasn't very good. CodeProject is much better, despite the connection problems lately.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I've been requested to create a custom combobox that gives the user the power to change the color of the outline (easy) and also the foreground/background for the drop down 'button' (the button to the right of a combobox with the down arrow). I can't figure out how to get a handle to that button. Can I do that? If not, can I create my own button of that size/shape and force it to use it instead? Would appreciate any help. I've found: ControlPaint.DrawComboButton, but that just takes a rectangle and a button 'state'. I need something more...
thanks very much,
Deanna
|
|
|
|
|
The HWND (window handle) of every Control is exposed from the Handle property. That returns an IntPtr that represents the HWND , and any native API that you P/Invoke should define any handle property (HWND , HDC , HRGN , etc.) as an IntPtr .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I realize that, but what I need to know is how to get the hwnd of JUST the button, not the whole combobox control.
|
|
|
|
|
ddelapasse wrote:
I realize that, but what I need to know is how to get the hwnd of JUST the button, not the whole combobox control.
The ComboBox class is simply a wrapper around the Win32 class, check out the ClassName property of a CreateParams object in the get_CreateParams method of the ComboBox class, it's value is "COMBOBOX". You will need to override the WndProc of a derived class inheriting from ComboBox to perform the task you are trying to complete.
- Nick Parker My Blog | My Articles
|
|
|
|
|
It isn't a control. A Combobox is - natively (like Nick pointed out) - an Edit control with UI elements drawn around it (basically). The button is drawn, just like you've found with the ControlPaint class members.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello All,
Have a "minor" issue that i hope someone here can help me with.
I have the following code [Example below] that runs throu all directories to find specific files (eg. doc files).
When the code is run from a user who have admin right, then there are no issues. but if its run as a user with no rights whatsoever i get into trouble.
Running in the directory C:\documents and settings with the folders Administrator, Admin, Lousy User, Teds & BillG.
When the code is run in standard user mode, it will stop executing the folders in that thread when there is no access rights on a folder - in this case it will begin with Administrator folder first, and stop search in that directory. meaning it will newer get to search the users own folder "Lousy User".
Is there any was to get over this issue?
hope u all understood my meaning by this.
<code>
try
{
foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, filetype))
{
FileInfo fs = new FileInfo(f);
view.Items.Add(itm);
}
}
}
catch (System.Exception excpt)
{
// Console.WriteLine(excpt.Message);
}</code>
|
|
|
|
|
Off the top of my head, I'm guessing that an exception is thrown if you don't have access to the directory you are trying to get the files for. If that is the case then your try catch block should be around the inner loop rather than the outer loop - that will allow you to continue searching in other directories, at the moment as soon as a directory is encountered that you don't have permission to view an exception is thrown that will stop the rest of your process.
Does this help?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hi all,
I am currently using the Outlook Model to get a list of all tasks from Outlook 2003. The list of tasks is encapsulated within a MAPIFolder object known as theTasks and then to grab each individual task we use foreach(TaskItem taks in theTasks.Items). I would like to encapsulate this functionality within an interface so that the user can plug-in other Personal Information Managers if SDK's exist, and would like these tasks to be displayed within the main interface and not have a dependance on the Outlook model. Is there any way of returning an object with a list of the tasks to the main interface, as I assume you cannot return multiple items from a particular method.
Any help on this matter would be greatly appreciated!
Paul Kiddie
Developer
interactivelogbook.tk
|
|
|
|
|
Well, the interface you're talking about wouldn't be tied directly with the Outlook object model (OOM), no other PIMs. As for a collection or array of objects, that's pretty simple: object[] . Since the OOM and any other PIMs' OMs would define types that you can't change (like implement other interfaces, and casting down may not always work) so you'd have to return a generic object. That doesn't help you much, though. You'd have to use reflection or the component model to discover properties and methods, and that would be very grueling. Another idea is to encapsulate the objects themselves into yet another interface or abstract class. This would require you to - for each item - wrap it (in your provider, since what you're referring to is a provider pattern) and store it in a collection or list (which is also a collection), then return that collection. That's not an uncommon approach, however. The component model - in many places - actually uses reflection, wraps properties (for example) in PropertyDescriptor s, puts those in a PropertyDescriptorCollection , and returns that.
To aide with the component model (for good design-time behavior), you might also look into implementing the ICustomTypeDescriptor interface if you want to customize the behavior or such a base class for use in the component model (to return "virtual" properties (shadowed), etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to check whether the content in a datagrid cell has been changed or not... how can u achieve this?
samitha
|
|
|
|
|
The cell itself doesn't record anything - the underlying data set does. If you're binding to a DataSet , DataTable , or DataView , get the DataRow for the row for that cell and query the DataRow.RowState property.
There's several ways to do this. The easiest that takes sorting into account is like so:
CurrencyManager cm = (CurrencyManager)
dataGrid1.BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember];
if (cm != null)
{
DataView view = (DataView)cm.List;
DataRowView rowView = view.Item[dataGrid1.CurrentRowIndex];
bool changed = rowView.Row.RowState == DataRowState.Modified;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thnks 4 the reply...My actual requiremnt is this..
Suppiose u have a datagrid with only one row has been entred. When you click on the close button on the form(without giving the focus on any other control) it should check whether the row has a value. This ckeck happens correctly when u click else where on the form or on the next row and then try to close..
can anybody help me...?
samitha
|
|
|
|
|
Please state your actual requirement next time. It will save time.
You should still get the currency manager like I showed you in the first reply in your Form.Closing event handler. Then you can call CurrencyManager.EndCurrentEdit . See the method documentation for CurrencyManager.EndCurrentEdit for an example.
You could also use DataGrid.EndEdit , which also includes an example of usage in the method documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|