What am I missing?
its a bit of a pain trying to execute wmi methods through .NET, the
syntax is less than obvious and the help is almost non-existent...so it
will be something like thsi (not exact, this is modified from my own
code and thus will not be perfect - cos it'll be executing a diff
method)
Good luck
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
using System.Management;
//connect to the comp
string strComputerName = Environment.MachineName;
ConnectionOptions oConn = new ConnectionOptions();
oConn.Impersonation = ImpersonationLevel.Impersonate;
oConn.Timeout = new TimeSpan(0,0,0,5);
oMs = new ManagementScope(@"\\" + strComputerName + @"\root\cimv2",
oConn);
oMs.Connect();
//this executes the Create method of Win32_ScheduledJob
string stringCommandLine = strSharedPath + @"\" + strComputerName +
".hta ";// + nTestCounter.ToString();
ManagementPath myPath = new ManagementPath("Win32_ScheduledJob");
ManagementClass myTaskClass = new ManagementClass(oMs,myPath,null);
DateTime dtNow = DateTime.Now;
dtNow = dtNow.AddMinutes(1);
string LocalDateTime = ToDMTFTime(dtNow);
ManagementBaseObject inputArgs =
myTaskClass.GetMethodParameters("Create");
inputArgs["Command"] = stringCommandLine;
inputArgs["DaysOfMonth"] = 0;
inputArgs["DaysOfWeek"] = 0;
inputArgs["InteractWithDesktop"] = true;
inputArgs["RunRepeatedly"] = false;
inputArgs["StartTime"] = LocalDateTime;
ManagementBaseObject outParams = myTaskClass.InvokeMethod("Create",
inputArgs, null);
"This Sucks. It seems like the most obvious thing that when you want
to print, you would like to programmatically set a default printer.
You can't always leave it up to the user, and I shouldn't have to go to
the WinAPI or WMI to work around it..."
<stepping off soapbox> :)
Will report back if it doesn't work... otherwise, I'll be off in the
corner hitting myself in the head with a 2x4.