Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
AnswerRe: Database security - Any suggestions? Pin
Heath Stewart7-Oct-04 22:40
protectorHeath Stewart7-Oct-04 22:40 
AnswerRe: Database security - Any suggestions? Pin
Vasudevan Deepak Kumar8-Oct-04 3:55
Vasudevan Deepak Kumar8-Oct-04 3:55 
GeneralRe: Database security - Any suggestions? Pin
totig8-Oct-04 4:10
totig8-Oct-04 4:10 
GeneralRe: Database security - Any suggestions? Pin
Vasudevan Deepak Kumar8-Oct-04 4:52
Vasudevan Deepak Kumar8-Oct-04 4:52 
QuestionHow to get the PrinterSettings of a Printer? Pin
sachinkalse7-Oct-04 22:10
sachinkalse7-Oct-04 22:10 
AnswerRe: How to get the PrinterSettings of a Printer? Pin
Heath Stewart7-Oct-04 22:23
protectorHeath Stewart7-Oct-04 22:23 
GeneralRe: How to get the PrinterSettings of a Printer? Pin
sachinkalse7-Oct-04 22:49
sachinkalse7-Oct-04 22:49 
GeneralRe: How to get the PrinterSettings of a Printer? Pin
Heath Stewart8-Oct-04 5:57
protectorHeath Stewart8-Oct-04 5:57 
The easiest way is through WMI. While on NT-based platforms you can make a single function call (you have to P/Invoke SetDefaultPrinter), the steps for Windows (i.e., Win98 and ME) platforms are more numerous.

WMI exposes a Win32_Printer.SetDefaultPrinter method that abstracts the correct implementation:
using System;
using System.Management;
 
class Printers
{
  static void Main(string[] args)
  {
    EnumeratePrinters(args.Length > 0 ? args[0] : null);
  }
 
  static void EnumeratePrinters(string defaultName)
  {
    ManagementObject defaultPrinter = null;
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(
      "select * from Win32_Printer");
    foreach (ManagementObject printer in searcher.Get())
    {
      string name = printer["Name"].ToString();
      Console.WriteLine("Printer: " + name);
      if (defaultName != null &&
        string.Compare(name, defaultName, true) == 0)
        defaultPrinter = printer;
    }
 
    if (defaultPrinter != null)
    {
      Console.WriteLine("Setting default printer to \"{0}\"",
        defaultPrinter["Name"]);
      defaultPrinter.InvokeMethod("SetDefaultPrinter", null);
    }      
  }
}


This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralMAPI programming Pin
ting6687-Oct-04 21:22
ting6687-Oct-04 21:22 
Questionhow to preprocess "ctrl + c" in console program Pin
williamchou7-Oct-04 21:06
williamchou7-Oct-04 21:06 
GeneralWeb Access Failed Error Pin
Hadi Fakhreddine7-Oct-04 20:48
Hadi Fakhreddine7-Oct-04 20:48 
GeneralRe: Web Access Failed Error Pin
sreejith ss nair7-Oct-04 21:21
sreejith ss nair7-Oct-04 21:21 
Generaluse of C++ dll in C# Pin
mitreviper7-Oct-04 19:17
mitreviper7-Oct-04 19:17 
GeneralRe: use of C++ dll in C# Pin
sreejith ss nair7-Oct-04 20:52
sreejith ss nair7-Oct-04 20:52 
GeneralRe: use of C++ dll in C# Pin
mitreviper8-Oct-04 2:12
mitreviper8-Oct-04 2:12 
Generallocalization kit example Pin
azusakt7-Oct-04 18:05
azusakt7-Oct-04 18:05 
GeneralRe: localization kit example Pin
minhpc_bk7-Oct-04 19:57
minhpc_bk7-Oct-04 19:57 
GeneralSimple question abt pop-up window Pin
Sudee7-Oct-04 17:25
Sudee7-Oct-04 17:25 
GeneralRe: Simple question abt pop-up window Pin
Alex Korchemniy7-Oct-04 17:49
Alex Korchemniy7-Oct-04 17:49 
Generalmanipulate IE favourites Pin
ppp0017-Oct-04 16:07
ppp0017-Oct-04 16:07 
GeneralRe: manipulate IE favourites Pin
benjymous7-Oct-04 22:10
benjymous7-Oct-04 22:10 
GeneralRe: manipulate IE favourites Pin
Heath Stewart7-Oct-04 22:13
protectorHeath Stewart7-Oct-04 22:13 
GeneralRe: manipulate IE favourites Pin
benjymous7-Oct-04 22:26
benjymous7-Oct-04 22:26 
GeneralRe: manipulate IE favourites Pin
Heath Stewart7-Oct-04 22:30
protectorHeath Stewart7-Oct-04 22:30 
GeneralRe: manipulate IE favourites Pin
benjymous8-Oct-04 2:11
benjymous8-Oct-04 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.