|
Hi Sam,
Take a look at System.Management namespace, its a wrapper for WMI, you might find what you are looking for.
Cheers
Kannan
|
|
|
|
|
Try this out:
private void btnComPorts_Click(object sender, System.EventArgs e)
{
txtOutput.Clear();
string server = @"\\" + txtServer.Text;
ManagementScope ms = new ManagementScope(server + @"\root\cimv2");
ObjectQuery oq = new ObjectQuery("select deviceID from win32_SerialPort");
ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq);
ManagementObjectCollection moc = mos.Get();
foreach(ManagementObject mo in moc)
{
txtOutput.AppendText(mo["DeviceID"].ToString());
txtOutput.AppendText("\r\n");
}
}
Matt is a network administrator for an auditing company in the midwest. He is shamelessly looking for Windows programming side work.
|
|
|
|
|
Thanks Matt, worked excellent!
|
|
|
|
|
I've seen many really good examples of how to add scrolling credits to your Visual C++ applications, but I haven't found any yet for a C# Windows application. Are there any out there?
|
|
|
|
|
How can I test for a null string?
if (str == "")
doesn't work if str is a string containing just \0.
|
|
|
|
|
if (str == null)
[edit]Note that .NET makes a distinction between null and "" - both are possible. The first one throws a Null exception, when you try to use it, the second one bevaves like you expect from a zero-length string.[/edit]
If I could find a souvenir / just to prove the world was here [sighist]
|
|
|
|
|
So, if (str == null || str.Length == 0) then.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am not sure what you mean by "contains just \0". If you mean something like the C string terminator this is not really used and if you happen to get strings like this you will have to test for this case explicitly.
If you want to treat null references the same as empty strings you need a test like this:
if((str == null) || (str == ""))
Do not check the string length, by the way. Strings can contain characters such as writing direction markers that do not show. Hence, their length is > 0 but they are still empty!
cheers
erik
|
|
|
|
|
Yes, I did mean the C string terminator. If you write out a string to memory using MemoryStream and StreamWriter and then read it back in with a MemoryStream and StreamReader, you get that terminating \0 at the end of the string. However, (str == null), (str.Length == 0), and (str == "") all fail. The only solution I found was to use string.Trim to manually remove the \0.
|
|
|
|
|
Hi!
I have a problem thats been itching for days now and i really need help with this one.
I want to get the text that i write to begin from the bottom of the RichRTextBox, just like they having int the mIRC program.
im building a chat program and i need that thing too work.
hopes for an answer!
thanks
// trones
|
|
|
|
|
If you change the HideSelection property to false it will keep scrolling to the bottom. It will still start the text at the top, but will scroll down with it.
Maybe you could just pad it off the bat to bring it down?
Hope that helps..
-Sam
|
|
|
|
|
I want my C# program to be able to, at runtime, check a directory for small "drivers", display the drivers in a comboBox, and use the driver.
The drivers would just take in a string, parse it, and call a set number of functions like SetPos(x,y), SetHeading().....
It would be nice if they could be written in different languages, but that isn't necessary.
What would be the best way to go about this, could anyone point me to some info.
Thanks...
-Sam
|
|
|
|
|
The drivers could be DLL containing classes which implement a specific interface. With Reflection, you load them dinamically, and scan for the interface.
To simplify things (security), the drivers would be in a subdirectory of your application.
This would allow your users to create drivers in any .NET application.
If you want more end-user flexibility in choosing languages, go for COM and publish a typelibrary with an interface.
I see dumb people
|
|
|
|
|
Thanks for the reply, I will look into reflection...
|
|
|
|
|
Is it possible given two strings (class name and method name) to dynamically create an instance of the class and get a delegate pointing to the method?
For example (almostcode):
<br />
public delegate void ActionHandler(Message m);<br />
<br />
string className = <br />
"Exony.Runtime.StateServices.Test.States.Stopped";<br />
<br />
string actionName = "OnStart";<br />
<br />
Type t = Type.GetType(className);<br />
<br />
object instance = t.Assembly.CreateInstance(t.FullName);<br />
<br />
ActionHandler handler = ?CREATE_DELEGATE?(instance, actionName);<br />
<br />
fsm.Handlers += handler;<br />
<br />
Thanks in advance,
James.
|
|
|
|
|
Doh.... If you look hard enough there is nearly always something in the FCL to do the job...
ActionHandler handler = <br />
Delegate.CreateDelegate(typeof(ActionHandler), instance, actionName)
Thanks anyway...
James.
|
|
|
|
|
hi there
i have a problem using a text box
i have a text multiline box (accepts return = true) and TextBox1.Text=varText.
varText is a text with many lines (in fact is an XML source indented)
if i show the text with MessageBox.Show(TextBox1.Text) it looks fine but in the edit box instead of 'new line' i have '|'
what can i do?
any idea?
thanks in advance for your help
|
|
|
|
|
i had the same problem but i solved it like this:
msgbox.text = "texttext\r\n";
and it worked for mem so i suggest u should try that!
// trones
|
|
|
|
|
thank you for your answer, trones
i solve the problem this way:
char cr=(char)13;
char lf=(char)10;
string strCR,strLF,strCRLF;
strCR=cr.ToString();
strLF=lf.ToString();
strCRLF=strCR+strLF;
art=art.Replace(strLF,strCRLF);
textBox1.Text=art;
|
|
|
|
|
How can I find out if the computer is connected with a TCP-Network?
I don't want to find out if TCP is installed successfull, but I want to find out if there is a working TCP conntection to a network without using any IP adresses (that means on every computer without knowing anything about the existing network), etc.
There must be a solution, but I can not see the right method (
Can you help me?
|
|
|
|
|
Hi!
It's me again! I guess you need the IP-Adress of the Computer to find out if the connection is working
|
|
|
|
|
I wanna provide a MC++ lib for C# user. One function is: bool ReadString(string str)
I must write it in MC++ for some former code ReadBuffer.
I write it like something below, but failed in get the StringBuilder or String's char buffer. The marshal must be something wrong, can't pass the compiler.
bool ReadString(String * &str)
{
void * pBuffer;
int num;
ReadBuffer(&pBuffer, num);
StringBuilder* sb = new StringBuilder(64*1024);
MultiByteToWideChar(0,0,pBuffer, num, [MarshalAs(UnmanagedType.LPWStr)]sb, 64*1024);
str = sb->ToString();
}
Can anything lend me a hand?
|
|
|
|
|
I think this would be better asked in the MC++ forum.
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
Microsoft has reinvented the wheel, this time they made it round.
-Peterchen on VS.NET
|
|
|
|
|
novachen wrote:
I wanna provide a MC++ lib for C# user. One function is: bool ReadString(string str)
Do you mind if I ask why you are writing a library in MC++ to read a string. This can easily be done in C#, especially if other parts of the project will be written in C#. Could you provide further info?
Nick Parker
Not everything that can be counted counts, and not everything that counts can be counted. - Albert Einstein
|
|
|
|
|
Nick Parker wrote:
Do you mind if I ask why you are writing a library in MC++ to read a string.
In fact, the function is provided for a gzip lib. My ReadString's function is extract the text from the gz file. And because the dotnet use the Unicode char, i have to transform single byte into unicode (double bytes form). So the win32 api is used. When use the API, the address of buffer must provided, so i need some marshal on the String or StringBuilder.
Did i say it clearly now ?
|
|
|
|