andrew4582

Copy path shell utility

Aug 15th, 2010
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. #define TESTINGde
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Text;
  9. using System.Threading;
  10. using System.IO;
  11. using System.Net;
  12. using System.Diagnostics;
  13. using System.Xml;
  14. using System.Xml.Serialization;
  15. using System.Configuration;
  16. using System.Globalization;
  17. using System.Reflection;
  18. using System.Data.Common;
  19.  
  20. using System.Windows.Forms;
  21. using System.Drawing;
  22. using System.Drawing.Design;
  23. using System.Drawing.Printing;
  24. using System.Drawing.Imaging;
  25. using System.Deployment;
  26. using System.Deployment.Application;
  27. using Microsoft.Win32;
  28.  
  29.  
  30.  
  31. namespace CopyPathShellUtility {
  32.     static class Program {
  33.         /// <summary>
  34.         /// The main entry point for the application.
  35.         /// </summary>
  36.         [STAThread]
  37.         static void Main(string[] args) {          
  38.             try {
  39.                 if (args.Length == 0) {
  40.                     Application.EnableVisualStyles();
  41.                     Application.SetCompatibleTextRenderingDefault(false);
  42.                     Application.Run(new Form1());
  43.                     return;
  44.                 }
  45.                 for (int i = 0; i < args.Length; i++) {
  46.                     args[i] = "\"" + args[i] + "\"";
  47.                 }
  48.                
  49.                 Clipboard.SetText(string.Join(Environment.NewLine, args));
  50. #if TESTING
  51.                 string msgOK = Clipboard.GetText();
  52.                 MessageBox.Show(
  53.                   Form.ActiveForm,
  54.                   msgOK,
  55.                   Application.ProductName,
  56.                   MessageBoxButtons.OK,
  57.                   MessageBoxIcon.Information,
  58.                   MessageBoxDefaultButton.Button1);
  59. #endif
  60.                 string regKey = @"HKEY_CURRENT_USER\Software\CopyPathShellUtility\";
  61.                 for (int i = 0; i < args.Length; i++) {
  62. #if TESTING
  63.                     Trace.TraceInformation(string.Format("Copied path {0} to clipboard", args[i]));
  64. #endif
  65.                     Registry.SetValue(regKey, args[0], DateTime.Now);
  66.                 }
  67.             }
  68.             catch (Exception ex) {
  69.                 string msgError = ex.ToString();
  70.                 MessageBox.Show(
  71.                     Form.ActiveForm,
  72.                     msgError,
  73.                     Application.ProductName,
  74.                     MessageBoxButtons.OK,
  75.                     MessageBoxIcon.Error);
  76.             }
  77.  
  78.             return;
  79.  
  80.         }
  81.        
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment