|
well thanks for helping but i don't know how to make use of a console application output to make it displayed in form applicaiton i know that sounds stupied but i'm not really good at c# so please advice
Hesham Hafez
|
|
|
|
|
The console application has nothing to do with the solution. Try this (where m_label is a label on your form):
ManagementClass myManagementClass = new ManagementClass
("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = myManagementClass.GetInstances();
m_label.Text = string.Empty;
if (moc.Count > 0)
m_label.Text = mo["MacAddress"].ToString();
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
ok i have tried this code it runs with no errors but still dosent show mac address into the textBox1
public string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress=String.Empty;
foreach(ManagementObject mo in moc)
{
if(MACAddress==String.Empty) // only return MAC Address from first card
{
if((bool)mo["IPEnabled"] == true) MACAddress= mo["MacAddress"].ToString() ;
}
mo.Dispose();
}
MACAddress=MACAddress.Replace(":","");
return MACAddress;
this.textBox1.Text=MACAddress.ToString();
}
can u advice what is wrong with it?
Hesham Hafez
|
|
|
|
|
Your code could be failing for several reasons. You could start by printing the "MacAddress" property of every ManagementObject you encounter. Be sure to compare the value of the property with null before attempting to print its value.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
well i tried this if that what u meant by checking with null but still dosn't return any thing to the textbox
if (moc.Count > 0)
{
this.textBox1.Text=MACAddress.ToString();
}
please modify my code to what u think will make it work
Hesham Hafez
|
|
|
|
|
I tried using the MAC and other various hardware signatures like the motherboard serial, bios serial, MAC Address to license my products but I found the MAC address reported is not always consistent. At first I thought it was laptop mac addresses reporting differently because of the transition to wireless/hard wired nics but I found some of the pc's were reporting different MAC addresses as well. I verified that the MAC addresses were indeed the item causing the trouble and verified that the hardware had not been changed out.
I have since ceased using the MAC address for product licensing and the problem has gone away. I would recommend using other hardware signatures and use as many as possible as some Bios serial numbers, motherboard serials, etc... still come back with empty strings or generic strings like "..Empty", "..None", "N/A", etc...
I would strongly discourage using the MAC as it only leads to embarassment down the road after your product is deployed and the customers are complaining your licenses are no longer valid.
For what it's worth...
|
|
|
|
|
well yes i agree with u that mac addess is not the securest referance that u can depend on as it changes when the local pc is connected to the internet and besides the mac adress spoofers .
can u sudgest another h/w signeture and can i programatically do this in a forms enviroment ?
Hesham Hafez
|
|
|
|
|
WMI (Windows Managment Instrumentation) will get you access to an assortment of hardware information.
To start, I would recommend
"Win32_Bios","SerialNumber"
"Win32_BaseBoard","SerialNumber"
but these are still sometimes blank even on newer boxes so I would search through the various items available. The Microsoft Platform SDK has some neat WMI browser tools. Also, MSDN has documentation in "Setup and System Administration".
moro145 wrote: programatically do this in a forms enviroment
I can't help you there as I'm a C++ programmer and I know nothing about Windows Forms programming. I was just wandering by and I thought I'd warn you about the MAC address since I got burned by it before.
Good luck!
|
|
|
|
|
yah i'm finding my way now thanks a milion
Hesham Hafez
|
|
|
|
|
Is there a way for me to create a button that isnt square or rectangular?
or maybe something similar
|
|
|
|
|
|
See this thread.
- It's easier to make than to correct a mistake.
|
|
|
|
|
1. is it possible for me to create an application in C# that will allow me to run my hyper terminal or is it possible for me touse commands in my application that will allow me to start programs on my computer????
2. is it possible for two programs to be writing to the same file at the same time?????
kenny
|
|
|
|
|
hiii
if i understood what u wana do right this code may be helpful
you can do so using the System.Diagnostics.Process.Start method as follows:
//just specifying the document name will open the appropriate app based on system settings
Process.Start("Http://msdn.microsoft.com")
//open a word doc
Process.Start(AWordDocument.doc")
Hesham Hafez
|
|
|
|
|
Thanks thats exactly what i wanted to do ...it works fine..............do u know anything about hyper terminal os rs232 connections?
kenny
|
|
|
|
|
Hi,
I am developing a paint application and I have a problem:
The user draws on a UserControl object, then the user has to save the drawings on the UserControl object as a Bitmap file. How can I save the paintings on the UserControl object as a Bitmap file?
thank you
|
|
|
|
|
If they're drawing on the control, then you have a Graphics object. You can use CreateGraphics() on a control to get an instance to draw with, I don't know how to get an instance with the control's existing painting on it. But if you've already got an instance of Graphics that they're using to draw, you can do something like the following...
private void SaveBitmap(Graphics g, Control ctrl) {
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ctrl.Width, ctrl.Height, g);
bmp.Save(@"C:\bmp.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}
Hope that helps, without a little more info I'm not sure it answers your question though.
Visit BoneSoft.com
|
|
|
|
|
Hi,
I tried your method but it didn't work, I get a black bitmap.
My problem is:
I have a UserControl object that I draw onto. There are lines, rectangels, circle on it. I want to save these drawings into a bitmap file. How can I do that?
|
|
|
|
|
How could i get (and then set) ASCII code of a character?For example when i pass a character A i want to get the ASCII code of it.If i change the ASCII code of a character does its function will change?I change the ASCII code of character A to B.Does character A change to B?Thanks for reading
|
|
|
|
|
Do you really mean ASCII character codes? The Char data type in .NET is a Unicode character, so it doesn't use ASCII characters codes. If you want to use ASCII character codes you would have to encode the string into ASCII, and that leaves you with an array of bytes that you can't use as text unless you decode it again.
Assuming that you mean Unicode character codes, and not ASCII character codes:
The Char data type is a 16 bit value that represeents a Unicode character. You can easily convert between Char and Int32, and manipulate the value in either form:
char c = 'A';
c++;
c += '!';
int i = (int)c;
i++;
char d = (char)i;
---
b { font-weight: normal; }
|
|
|
|
|
This code does that:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
char c = 'A';
int i = Convert.ToInt32(c);
Console.WriteLine(c);
Console.WriteLine(i);
++i;
c = Convert.ToChar(i);
Console.WriteLine(c);
Console.WriteLine(i);
}
}
}
Hope this helps.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
You can get/set ACSII code for any of the character and vice versa as follows:
// The encoding.
ASCIIEncoding ascii = new ASCIIEncoding();
//Conversion From ACSII code to character
Byte[] decodedBytesForChar= ascii.GetBytes("A"); //returns ACSII code for character A i.e. 65
Console.WriteLine("ACSII code for character A = {0}", decodedBytesForChar[0]);
//Conversion From ACSII character to code
Byte[] encodedBytes = new Byte[1];
encodedBytes[0] = 97;
Console.WriteLine("ACSII character for code 97 = {0}", ascii.GetString(encodedBytes));
Rizwan
|
|
|
|
|
thanks for all replies.I want to reassign the function of the keyboard.For example when i press A on the keyboard it will print B or something else on the screen.This what i mean "set" (reassign)ASCII code.Can anyone help me?Thanks again
|
|
|
|
|
Hi, I'm working on a very simple socket communication program. It needs to connect, send a string, and disconnect. However, I need to know if the connect is terminated by the remote client before I try to disconnect (this is a requirement of the remote client software before my code is "certified").
I have the following code:
<br />
EndPoint ep = new IPEndPoint(IPAddress.Parse(sServerIP), iPort);<br />
Socket sockBatch = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp); <br />
sockBatch.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 30000);<br />
sockBatch.Connect(ep);<br />
if (sockBatch.Connected)<br />
{<br />
Encoding ASCII = Encoding.ASCII;<br />
Byte[] byteDataLine = Encoding.ASCII.GetBytes(sSendData.ToCharArray());<br />
sockBatch.Send( byteDataLine, byteDataLine.Length, 0 );<br />
<br />
Byte[] RecvBytes = new Byte[256];<br />
Int32 bytes = sockBatch.Receive(RecvBytes, RecvBytes.Length, 0);<br />
StringBuilder sbResponse = new StringBuilder();<br />
sbResponse.Append(ASCII.GetString(RecvBytes, 0, bytes));<br />
string sResponsePacket = string.Empty;<br />
while ((sockBatch.Connected) && (bytes > 0) && (-1 == sbResponse.ToString().IndexOf(sEndMarker)))<br />
{<br />
bytes = sockBatch.Receive(RecvBytes, RecvBytes.Length, 0);<br />
sResponsePacket = ASCII.GetString(RecvBytes, 0, bytes);<br />
sbResponse.Append(sResponsePacket);<br />
}<br />
}<br />
<br />
loggerBatch.Info("TEST DELAY before disconnect socket");<br />
for (int iWait = 0; iWait < 1 * 60; iWait++)<br />
{<br />
Thread.Sleep(1000);<br />
}<br />
<br />
bool bPoll = sockBatch.Poll(10000, SelectMode.SelectWrite);<br />
loggerBatch.Info("Batch Socket Write poll: {0}", bPoll);<br />
<br />
bool bPoll1 = sockBatch.Poll(10000, SelectMode.SelectError);<br />
loggerBatch.Info("Batch Socket Error poll: {0}", bPoll1);<br />
<br />
loggerBatch.Info("Batch Socket is connected: {0}", sockBatch.Connected);<br />
if (bPoll && sockBatch.Connected)<br />
{<br />
loggerBatch.Info("Poll says connected");<br />
try<br />
{<br />
byteDataLine = Encoding.ASCII.GetBytes("AYT".ToCharArray());<br />
sockBatch.Send( byteDataLine, byteDataLine.Length, 0 );<br />
}<br />
catch (Exception ex)<br />
{<br />
logger.Info("AYT Error: {0}", ex.ToString());<br />
}<br />
<br />
loggerBatch.Info("Disconnect from socket");<br />
sockBatch.Shutdown(SocketShutdown.Both);<br />
sockBatch.Close();<br />
}<br />
else<br />
{<br />
loggerBatch.Info("Socket was disconnected.");<br />
}<br />
Output of above
<br />
2006-06-16 10:19:59.7241|INFO|batch|TEST DELAY before disconnect socket<br />
2006-06-16 10:20:59.7233|INFO|batch|Batch Socket Write poll: True<br />
2006-06-16 10:20:59.7390|INFO|batch|Batch Socket Error poll: False<br />
2006-06-16 10:20:59.7390|INFO|batch|Batch Socket is connected: True<br />
2006-06-16 10:20:59.7390|INFO|batch|Poll says connected<br />
2006-06-16 10:20:59.7546|INFO|main|AYT Error: System.Net.Sockets.SocketException: An established connection was aborted by the softw<br />
are in your host machine<br />
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)<br />
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 size, SocketFlags socketFlags)<br />
[snip]<br />
2006-06-16 10:20:59.7546|INFO|batch|Disconnect from socket<br />
I know that while I am in the delay section the socket connection is terminated (TCP FIN and/or TCP RST). However, the Connected property gives me nothing (I realize it only reports state at last activity), but the Poll method supposedly will let me know the current state. I get an error when I try to send the AYT (for testing), but this is unacceptable for production as I can't send unexpected data down the line.
Any ideas on what to try?
TIA
|
|
|
|
|
Is it possible to set the default button on a user control in the same way you would set myForm.AcceptButton = button for a Form.
|
|
|
|