samelamin
asked on
using WMI commands to add a printer
Dear All
I would like to add a printer using a WMI command
any ideas
so far i can get a list of drivers using the code below but how do i add a printer?
thye string chosen is the chosen printer i want to install copies of. so forexample if the chosen is an HP printer i want to install copies of this HP
I would like to add a printer using a WMI command
any ideas
so far i can get a list of drivers using the code below but how do i add a printer?
thye string chosen is the chosen printer i want to install copies of. so forexample if the chosen is an HP printer i want to install copies of this HP
string path="not working";
chosen = comboBox1.SelectedItem.ToString();
ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PrinterDriver");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
foreach (ManagementObject mo in searcher.Get())
{
if (chosen == mo["Name"].ToString())
path = mo["DriverPath"].ToString();
}
ASKER
Is this in c# though
because if i do that i get multiple errors
because if i do that i get multiple errors
Are you trying to script it in C#? If not what are you using?
M@
M@
ASKER
yes
ASKER
so far i am trying to make it work using this program but i keep getting error
string printerName, printerDriver, portName; bool sharedPrinter;
string path="not working";
string infname = "";
portName = null;
chosen = comboBox1.SelectedItem.ToString();
ObjectQuery objectQuery = new ObjectQuery("SELECT * FROM Win32_PrinterDriver WHERE NAME='"+chosen+"'");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(objectQuery);
foreach (ManagementObject mo in searcher.Get())
{
infname = mo["InfName"].ToString();
}
MessageBox.Show(infname);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The following code should be what you are looking for to add a printer, replace the printer name in the strcomputer string and the \\PrintServer1\ArtDepartme
M@
Open in new window