|
Looking up WMI, it appears that the following should work like I want:
ManagementClass mc = new ManagementClass("CIM_PowerSupply");
object[] methodArgs = { 6, null };
object result = mc.InvokeMethod("SetPowerState", methodArgs);
However, the program crashes with a ManagementException, saying "This method is not implemented in any class." And, Microsoft's article on the SetPowerState function says "This method is currently not implemented by WMI. To use this method, you must implement it in your own provider."
It's kind of cruel to tease me with a function that doesn't actually do anything... Anyone know how it's supposed to be "implemented"?
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
|
yes shutdown sucks with shutdown.exe, specially in older windows version eg. XP
here is the code i use to shut my pc down
void Shutdown()
{
ManagementClass W32_OS = new ManagementClass("Win32_OperatingSystem");
ManagementBaseObject inParams, outParams;
int result;
W32_OS.Scope.Options.EnablePrivileges = true;
foreach (ManagementObject obj in W32_OS.GetInstances())
{
inParams = obj.GetMethodParameters("Win32Shutdown");
inParams["Flags"] = ShutDown.ForcedShutdown;
inParams["Reserved"] = 0;
outParams = obj.InvokeMethod("Win32Shutdown", inParams, null);
result = Convert.ToInt32(outParams["returnValue"]);
if (result != 0) throw new Win32Exception(result);
}
}
public enum ShutDown
{
LogOff = 0,
Shutdown = 1,
Reboot = 2,
ForcedLogOff = 4,
ForcedShutdown = 5,
ForcedReboot = 6,
PowerOff = 8,
ForcedPowerOff = 12
}
When you test this, save all your work. There is no way to stop this thing.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thank you, Xmen, but the PowerOff and ForcedPowerOff enum values are deceptive. Yes, they do power off the computer, but they also shut down Windows before then. I was looking for a way to power off the computer without wasting time shutting down Windows (the computer just goes silent right after I double-click something.exe on my desktop). But, thanks anyway!
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Hi all, quick question, using the following
using(DataModel.DatabaseDataContext context = GetDatabaseContext())<br />
var result = from b in context.Branches<br />
where b.Id == id<br />
select new Branch()<br />
{<br />
Id = b.Id,<br />
RowVersion = b.RowVersion.ToArray(),<br />
Name = b.Name,<br />
Description = b.Description<br />
};
I get a compiler error stating that an embedded statement cannot be a declaration or labbeled statement. I believe this is related to the return type from the Linq statement.
Is anybody able to point me in the correct direction of what this type should be? I have tried several types and get the impression that I have a fundamental misunderstanding.
Just racking up the postings
|
|
|
|
|
Did I understand correctly that you're querying for branches which have a specific id? I that's correct, I think it could be something like:
using(DataModel.DatabaseDataContext context = GetDatabaseContext()) {
var result = from b in context.Branches
where b.Id == id
select b;
foreach(Branch branch in result) {
...
}
}
|
|
|
|
|
How to have access the drivers and API?
|
|
|
|
|
|
|
I got a gridview with 12 unbound columns that is gonna be exported to Excel document. The exporting is already done but here is where im failing. Some cells can be empty in the gridview and trying to get its value will result in error: "Object reference not set to an instance of an object". Value property doesnt even seem to exist if its an empty cell.
This is how i do it now. Im sending the gridviews rowcollection to the method that exports it to excel. There i get the value from a cell with rows[index].Cells["columnname"].Value. Temporarily fixed it now with a try catch for every column as i got tired of it, but there must be another way.
|
|
|
|
|
I just did this a couple of days ago. Check for rows[i].Cells[j].Value == null. If my whole row is null I don't send that row since the gridview automatically creates the row and I may not have used it. Otherwise, set the data for that cell to "" so it doesn't cause an error.
string getCellValue(int row, int cell)
{
string rtn = "";
if (dataGridView1.Rows[row].Cells[0].Value != null) {
rtn = dataGridView1.Rows[i].Cells[0].Value.ToString();
}
return rtn;
}
But I like this better
string getCellValue(DataGridViewCell cell)
{
return (cell.Value != null ? cell.Value.ToString() : "");
}
SS => Qualified in Submarines
"We sleep soundly in our beds because rough men stand ready in the night to visit violence on those who would do us harm". Winston Churchill
|
|
|
|
|
I am creating a program that will simulate the functions of a robot by parsing a log file created by another program for a school placement. The problem here is I'm not really a programmer, I am a hardware/network guy but they assigned me this task anyways. If anyone can help with some resources that would help me out with this would be grateful.
|
|
|
|
|
There are many tool available in the market to read the log files.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
What format are your log files in, do you know? By that I meant do you know what program wrote them? or where they handwritten so to speak? If manual, do they follow a schema? (I'm thinking XML here)
|
|
|
|
|
The log is actually not really a file but created in ram and shown in a console like interface. However, I am not getting into that mess and have decided that the process to get the simulation running would be done by simply copying the log and pasting into a notepad document and saving. Short answer: txt. The logs are very structured and follow strict set of rules. I made a short set of instructions and this is what was spit out:
D 10:44:57 Starting program "Prog1" (lines 1 to 5)
A 10:44:57 initializing instrument
E 10:44:57 Line 1 : Dispense
tip 1 : dispense 0.00nl 1, 1 Deep Well, landscape [1,1]
10.00µl ">> Water << 23" Fixed <3 - 50µl> Single
E 10:44:59 Line 2 : Aspirate
tip 1 : aspirate 0.00nl 4, 5 Deep Well, landscape [1,2]
0.00nl "Water" Fixed <all volumes> Single
E 10:45:01 Line 3 : Aspirate
tip 1 : aspirate 10.56µl 4, 4 Deep Well, landscape [1,2]
10.00µl "Water" Fixed <3 - 50µl> Single
E 10:45:03 Line 4 : Dispense
tip 1 : dispense 20.56µl 6, 3 Deep Well, landscape [1,1]
10.00µl ">> Water << 23" Fixed <3 - 50µl> Single
E 10:45:05 Line 5 : Wash Tips
wash (2ml + 1ml), grid 20 and grid 20
|
|
|
|
|
To do it in a hurry, just infer what it looks like and parse it manually. If you want a more robust solution, write out a formal grammar for it, and use something like Percenburg Grammatica.
Theres another nice one whose name escapes me, which is used declaratively instead of using a grammar file and codegen. Argh. Ahah. Irony. Thank you CP search :P
|
|
|
|
|
Sorry about that. Time difference and everything.
Do you have a formal structure for it? If you do, its real easy to translate that into an XSD (XML Schema Document) after which you'd write a DOM parser (there are lots of free tools that can do it for you so you don't have to muck around with actually writing the parser), if you don't then there's no easy way about this and you're going to have to write your own parser.
|
|
|
|
|
|
|
|
I don't know about anybody else, but I use a transparent Panel to select the area of the screen to capture, then:
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap
(
this.pPanel.Width
,
this.pPanel.Height
) ;
using ( System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage ( bitmap ) )
{
gr.CopyFromScreen
(
this.pPanel.PointToScreen ( new System.Drawing.Point ( 0 , 0 ) )
,
new System.Drawing.Point ( 0 , 0 )
,
this.pPanel.Size
) ;
try
{
System.IO.StreamWriter sw = new System.IO.StreamWriter
(
new System.IO.FileStream
(
this.dlgFileSave.FileName
,
System.IO.FileMode.Create
,
System.IO.FileAccess.Write
,
System.IO.FileShare.None
)
) ;
bitmap.Save ( sw.BaseStream , System.Drawing.Imaging.ImageFormat.Png ) ;
sw.Close() ;
}
catch ( System.Exception err )
{
System.Windows.Forms.MessageBox.Show
(
"Could not open file\n" +
err.Message
,
"File open error"
,
System.Windows.Forms.MessageBoxButtons.OK
,
System.Windows.Forms.MessageBoxIcon.Exclamation
) ;
}
}
|
|
|
|
|
|
You don't - if you didn't get an answer you're happy with, then you probably won't get a better one this time around
|
|
|
|
|
|
And what if I started a discussion, and made some progress since and want to ask further related question? what would you suggest?
|
|
|
|
|