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;
}