Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Repair Network Connection Using C#

Posted on 2005-05-10
5
Medium Priority
?
537 Views
Last Modified: 2012-06-27
Good afternoon,

Normally, when our Wireless network cuts out, I right click on the wireless icon in the system tray and select "Repair".  Is there a way to accomplish this using C#?  Thanks!
0
Comment
Question by:fattumsdad
  • 3
  • 2
5 Comments
 
LVL 21

Expert Comment

by:Yurich
ID: 13973655
there is, but you'll have to start your c# application and click repair on it, then it will move your mouse cursor to your systray, right-click the icon , and select "repair"...

if you want to automate it, you'll have to create a resident-program that would check the state of connection all the time and if it's not connected - see above.

regards,
yurich
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 13973669
Yurich,

How do I have the mouse cursor move to the systray?  That sounds interesting!
0
 
LVL 21

Accepted Solution

by:
Yurich earned 2000 total points
ID: 13974249
you can use a couple of api functions to get in there which would be the right way of doing it, but again, you can just assume that your icon is always at the same place (since it's not a commercial project but your own utility) and move it like (say when you press a button) this:

Rectangle rect = Screen.PrimaryScreen.Bounds;
Cursor.Position = new Point( rect.Width - 20, rect.Height - 20 );

in the case above it jumps exactly on my system day-time display...

regards,
yurich


0
 
LVL 1

Author Comment

by:fattumsdad
ID: 13978895
That works great, and I now have the cursor jumping directly to the network icon...  however, I can't figure out how to simulate the right-click and then left-clicking "repair".
0
 
LVL 21

Expert Comment

by:Yurich
ID: 13982152
well, that one will be a bit more complicated...
you'll have to use api function since i don't know other ways of doing it.

using System.Runtime.InteropServices;

...

// somewhere in your class scope (namespace)
[ DllImport( "user32.dll" )]
private static extern void mouse_event( UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo );

private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
private const UInt32 MOUSEEVENTF_RIGHTDOWN = 0x0008;
private const UInt32 MOUSEEVENTF_RIGHTUP = 0x0010;

private void SendLeftClick()
{
      mouse_event( MOUSEEVENTF_LEFTDOWN, 0, 0, 0, new System.IntPtr());
      mouse_event( MOUSEEVENTF_LEFTUP, 0, 0, 0, new System.IntPtr());
}

private void SendRightClick()
{
      mouse_event( MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, new System.IntPtr());
      mouse_event( MOUSEEVENTF_RIGHTUP, 0, 0, 0, new System.IntPtr());
}


// then, somewhere in the same function where you moved your button to the icon on the systray:
...
SendRightClick();
// pick the right values for ?? to move your cursor just slight above your appeared menu
Cursor.Position = new Point( Cursor.Position.X - ??, Cursor.Position.Y - ?? );
SendLeftClick();
...

well, that should be pretty much it,
good luck,
yurich
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 21 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question