0

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:

  1. Add it to windows startup so that when I start up my Windows XP/7 it should run at background?
  2. Run the application when I have data in my clipboard.
  3. 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

shA.t
  • 16,580
  • 5
  • 54
  • 111
Rahul Chowdhury
  • 1,138
  • 6
  • 29
  • 52
  • What subset of your requirements does your already written code meet and what subset doesn't it ? – Eduard Dumitru Nov 14 '13 at 18:03
  • I want to run the application at windows startup.and it should run if i have clipboard text – Rahul Chowdhury Nov 14 '13 at 18:05
  • How can you have something on the clipboard when Windows first boots? (Unless I am completely misunderstanding you.) – Brian Nov 14 '13 at 18:08
  • @Brain ---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"..is it clear now – Rahul Chowdhury Nov 14 '13 at 18:13
  • I understand what you mean. The thing about running at startup is not basically a matter of programming but rather of deploying your app. You should copy a shortcut to your exe in the `Startup` folder under the `Start` menu's folder. Whereas being triggered by a Clipboard change (you said "run when" and you meant "allow to be triggered/awoken when") that is not entirely impossible but it's not so easy: Please check out this question: http://stackoverflow.com/questions/621577/clipboard-event-c-sharp – Eduard Dumitru Nov 14 '13 at 18:14

0 Answers0