I want to create a console app. Purpose of the application is to change the local drive to network drive while copy-paste;
If I copy "C:\TempEI4
"
it should paste "\\MY IP address\C$\TempEI4
"
Things I need to do:
- Add it to windows startup so that when I start up my Windows XP/7 it should run at background?
- Run the application when I have data in my clipboard.
- Create a standalone
exe
so it can work on any system.
I have already done the coding for it but need to do some modification on it no meet my requirements. Please help me on the same .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Net;
using System.Net.Sockets;
namespace CopyPasteNetworkPath
{
class Program
{
[DllImport("user32.dll")]
internal static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll")]
internal static extern bool CloseClipboard();
[DllImport("user32.dll")]
internal static extern bool SetClipboardData(uint uFormat, IntPtr data);
[STAThread]
static void Main(string[] args)
{
Program p = new Program();
OpenClipboard(IntPtr.Zero);
var copiedText = System.Windows.Forms.Clipboard.GetText();
IPAddress ipAdress = p.LocalIPAddress();
string networkIP = @"\\" + ipAdress.ToString().Trim() + @"\" + "C$\\";
string networkAddress = string.Empty;
if(copiedText.StartsWith(cDrive))
{
networkAddress = copiedText.Replace(cDrive,networkIP);
}
if(!string.IsNullOrEmpty(networkAddress))
System.Windows.Forms.Clipboard.SetText(networkAddress,System.Windows.Forms.TextDataFormat.UnicodeText);
}
/// <summary>
/// Geting IP
/// </summary>
/// <returns></returns>
private IPAddress LocalIPAddress()
{
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
return null;
}
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
return host
.AddressList
.FirstOrDefault(ip => ip.AddressFamily == AddressFamily.InterNetwork);
}
private static string cDrive = "C:\\";
}
}
Let say, I have an application which need to run at background on Windows startup. Purpose is to change the text. Let say it will change the copied text to upper case. If I copy "I am Rahul
" it should paste "I AM RAHUL
". Hope the purpose is clear for a layman view