|
Any final solution with full source code sample application ?
IMHO, better samples for minimize learning curve are real applications with full source code and good patterns.
The one line of Power-shell script below un-mounts a USB cable attached Windows Portable Device (WPD) from the Windows Operating System (XP thru W8/2012)
And just in case you have not yet started playing with Powershell, here is the equivalent VBScript (maybe be can port to C#):
Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from Win32ext_WPD Where strFriendlyName = 'SAMSUNG-SGH-I747'")
For Each objItem in colItems
Set objWMIWPDStatic = objWMIService.Get("Win32ext_WPD")
Set objInParam = objWMIWPDStatic.Methods_("EjectDevice").inParameters.SpawnInstance_()
objInParam.Properties_.Item("strObjectDeviceId") = objItem.strId
Set objOutParams = objWMIService.ExecMethod("Win32ext_WPD", "EjectDevice", objInParam)
Exit For
Next
Note change ‘SAMSUNG-SGH-I747′ to the phone/tablet name you see in Windows Explorer
About Win32ext_WPD
"Select * from Win32ext_WPD Where strFriendlyName = 'SAMSUNG-SGH-I747'"
Not well document googleing, not found more 2 references.
Maybe port to C# using:
var oScope = new ManagementScope(@"\\" + MachineName + @"\root\cimv2");
Reference:
http://squadratechnologies.wordpress.com/2013/07/24/windows-powershellvbscript-to-un-mount-a-smart-phone-or-tablet/
kiquenet.com
modified 26-Aug-14 4:56am.
|
|
|
|
|
I have this bit of code:
short s1 = 10;
short s2 = 5;
short s3 = s1 - s2;
Error says: Error Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?)
Aren't shorts just 16 bit integers? You can't subtract two of them?
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
modified on Sunday, August 30, 2009 9:45 PM
|
|
|
|
|
int was assumed on the right side of the assignment.
MSDN
|
|
|
|
|
For some reason the designers of C# decided that 8- and 16-bit operations should return a 32-bit result rather than the expected data type .
|
|
|
|
|
Thanks to both. That makes very little sense to me.
If anyone knows a good *why* answer, I would love to hear it, but I will just use a cast.
Thanks,
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
All integer expressions are computed using ints or larger, even if all the terms in it are bytes or shorts; that has been true in all C-like languages. The difference with C# is it complains when trying to store such expression result in anything smaller than int; C and C++ silently truncated the result, with a possible value error for free. In C# you need a cast, so you know you are responsible for a possible truncation.
try this (or its equivalent) in different languages:
ushort a=1;
ushort b=0xFFFF;
a++;
a=(ushort)(a+1);
b++;
b=(ushort)(b+1);
You may not like it, but this is how it has been defined.
The details can be found in section 7.2.6.2 of the C# language specification.
If you were to study the programming language you choose from a book, you would probably know such things.
|
|
|
|
|
Luc,
Thanks for your explanation. Not sure if the last line is meant condescendingly, but I value your input too much to complain . And your right. Its been a while since I really dug through my c# books. This is a PT thing for me. When it was FT, I did spend a lot more time in the books.
Thanks again.
*****************
"We need to apply 21st-century information technology to the health care field. We need to have our medical records put on the I.T." —GW
|
|
|
|
|
Dwayner79 wrote: Not sure if the last line is meant condescendingly
Not at all.
Too many people try and learn a language by experimenting, or reading a few things on the web, instead of really studying a book. A book tends to teach such stuff in a logic order, explaining how and why things are the way they are, and IMO there isn't really any alternative. And that's what I wanted to suggest.
|
|
|
|
|
I have some code that I'm trying to use to create a service on a remote machine. I am doing this:
static bool CreateService() {
try {
ManagementClass classInstance = new ManagementClass("root\\CIMV2", "Win32_Service", null);
ManagementBaseObject inParams = classInstance.GetMethodParameters("Create");
inParams["DesktopInteract"] = true;
inParams["DisplayName"] = "WallRotate";
inParams["ErrorControl"] = 0;
inParams["Name"] = "WallRotate";
inParams["PathName"] = "c:\\program files\\nts\\wallrotate\\wallclient.exe";
inParams["ServiceType"] = 16;
inParams["StartMode"] = "Automatic";
ManagementBaseObject outParams = classInstance.InvokeMethod("Create", inParams, null);
Write(outParams["returnvalue"].ToString());
} catch (Exception e) {
Write(e.Message.ToString());
return false;
}
return true;
}
...and it always fails. The outParams["returnvalue"] is 23. What other options can you get from the return on InvokeMethod? I was hoping to find something a little more, I dunno.. message-like? Hehe. "23" doesn't tell me much.
Thanks!
|
|
|
|
|
Apparently, you're trying to create a service that already exists on the machine. All you had to do was read the documentation on the Win32_Service class, Create method, here[^].
|
|
|
|
|
I have a listview and two bits fields (is_active) and (in_use) but it's showing on the ListView as True or False..
I am using this code to show in the ListView:
item.SubItems.Add(sql_reader["is_active"].ToString());
item.SubItems.Add(sql_reader["in_use"].ToString());
how can I change it to show as checkbox?
|
|
|
|
|
Checkbox is only available in Detail view of a listview.
You can add a listviewitem and use its checked property.
ListViewItem sitem = new ListViewItem();
sitem.checked = sql_reader["is_active"] as bool;
item.subitems.add(sitem);
This will do the trick I think...
|
|
|
|
|
A listview only allows 1 checkbox AFAIK and only in the first column, use a datagridview if this does not meet you needs.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
how to make sure there is always an item selected in the listview even if the user clicked in the outside area?
|
|
|
|
|
This is the common behavior to most of the .NET UI controls. The selection remains when you click on another control. Only thing that you have to do, is to select for the first time..
If your intention is to show the selection to the user, you may change the background color of the item on selection.
|
|
|
|
|
Set the 'Hide Selection' property to false on the listview.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to know how can hide and again show a column in the listview control just like visible=true or =false?
|
|
|
|
|
AFAIK you need to remove the item when you want it invisible, and again you can add when needed.
|
|
|
|
|
Like was mentioned, you have to remove the column from the ListView to hide it, then re-add it when you want it to be visible.
|
|
|
|
|
is there any way to give a domain name then .NET will search for all created emails under that domain name?
|
|
|
|
|
jrahma wrote: is there any way to give a domain name then .NET will search for all created emails under that domain name?
Why would you need that?
I can not think of any other thing other than a SPAMMER needing this.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
First, the question is why would yo want this?
The second question is search in WHAT for these emails? Search an Outlook archive?, an SMTP server?, your own database?, ... what is storing these emails??
|
|
|
|
|
Hello,
VS 2008
I am filling the buffer with the read method in the code below, using SlimDX to capture the audio input from the microphone.
The problem I have is that the buffer will overrun. It there anyway to create a circuler buffer that once it gets to the the end it will start over again?
Many thanks for any suggestions,
private void bgwAudioInput_DoWork(object sender, DoWorkEventArgs e)
{
Int16[] samples = new Int16[8192 / sizeof(Int16)];
Int16 audioValue = 0;
int i = 0;
captureBuff.Start(true);
while (captureAudio)
{
if (!this.bgwAudioInput.CancellationPending)
{
captureBuff.Read(samples, 0, true);
audioValue = Math.Abs(samples[i++]);
this.bgwAudioInput.ReportProgress(audioValue);
}
}
}
|
|
|
|
|
Hi,
Steve1_rm wrote: The problem I have is that the buffer will overrun
Are you sure about that? It looks to me as if you are attempting to read beyond the end of the array.
Every iteration of the while loop reads data into the samples array. That's ok but eventually the indexer i has the value 4096 and the array access in the line audioValue = Math.Abs(samples[i++]); will fail.
I can't understand the meaning of audioValue and how it would relate to progress. Did you mean to report total amount of data read perhaps?
Alan.
|
|
|
|
|
Steve1_rm wrote: It there anyway to create a circuler buffer that once it gets to the the end it will start over again?
Sure, just index with i%length or i&(length-1) for powers of 2 (which you have here)
|
|
|
|