[go: up one dir, main page]

0% found this document useful (0 votes)
11 views2 pages

Functions

The document contains C# methods for managing printers, including adding, removing, and setting default printers on a specified server. Each method logs actions and errors related to printer management using the Windows PrintUI command. Error handling is implemented to ensure that any issues are logged appropriately without disrupting the application flow.

Uploaded by

jaxifo3552
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Functions

The document contains C# methods for managing printers, including adding, removing, and setting default printers on a specified server. Each method logs actions and errors related to printer management using the Windows PrintUI command. Error handling is implemented to ensure that any issues are logged appropriately without disrupting the application flow.

Uploaded by

jaxifo3552
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

private bool removePrinter(string printer,string serverName)

{
try
{
Process.Start("rundll32", "printui.dll,PrintUIEntry /q /dn /n\\\\"
+ serverName + "\\" + printer);

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
removed Printer: " + printer);
return true;
}
catch (Exception ex)
{
// MessageBox.Show("Printer settings are incorrect.", "ERROR",
// MessageBoxButtons.OK, MessageBoxIcon.Error);

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Error: " + ex.ToString());
}
return false;

}
private void getDefaultPrinter()
{
try
{
label5.Text = LocalPrintServer.GetDefaultPrintQueue().ShareName;

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Got default Printer from Windows: " +
LocalPrintServer.GetDefaultPrintQueue().ShareName.ToString());
}
catch (Exception ex) {
label5.Text = "None";

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Error: " + ex.ToString());
}

}
private void OpenPrinterPropertiesDialog(string printer, string serverName)
{
try
{
Process.Start("rundll32", "printui.dll,PrintUIEntry /q /p /n\\\\"+
serverName + "\\" + printer);
}
catch (Exception ex)
{

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Error: " + ex.ToString());
}
}

private bool addPrinter(string printer, string serverName)


{
try
{
string exe = "C:\\Windows\\System32\\rundll32.exe";
string command = "printui.dll,PrintUIEntry /in /q /G w /n\\\\"
+ serverName + "\\" + printer;
Process process = new Process();
process.StartInfo.FileName = exe;
process.StartInfo.Arguments = command;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.Start();

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Printer: " + printer + " Sucessfully added to System");
return true;

}
catch (Exception ex)
{

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Error: " + ex.ToString());

}
return false;
}
private bool setDefaultPrinter(string printer, string serverName)
{
try
{
Process.Start("rundll32", "printui.dll,PrintUIEntry /q /y /n\\\\" +
serverName + "\\" + printer);
setRegKey(printer, serverName);

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Default Printer: " + printer + " Successfully set manual");
return true;
}
catch (Exception ex)
{

WriteLog(System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString() + "
Error: " + ex.ToString());
}
return false;
}

You might also like