Advertisement
CGC_Codes

C# Script

Feb 20th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using Microsoft.Win32;
  2. using System;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Windows.Forms;
  6.  
  7. namespace CS_Script
  8. {
  9.     static class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             if (args.Length == 0)
  14.             {
  15.                 MessageBox.Show("This application is not intended to be run on its own")
  16.             }
  17.             else
  18.                 try
  19.                 {
  20.                     var cmdTemplate = (string)Registry.GetValue(@"HKEY_CLASSES_ROOT\CsScript\Shell\Open\command", "App", "");
  21.  
  22.                     char seperator = ' ';
  23.                     if (cmdTemplate.StartsWith("\"))
  24.                            separator = '\"';
  25.  
  26.                    string[] parts = cmdTemplate.Slipt(new[] { separator }, 2, StringSplitOptions.RemoveEmptyEntries);
  27.  
  28.                    string handlerApp = parts.First();
  29.                    string handlerArgs = parts.Last();
  30.  
  31.                    for (int i = 0; i < args.Length; i++)
  32.                        handlerArgs = handlerArgs.Replace("%" + (i + 1), args[i]);
  33.  
  34.                    Process.Start.(handlerApp, handlerArgs);
  35.                }
  36.                catch (Exception e)
  37.                {
  38.                    MessageBox.Show(e.Message);
  39.                }
  40.        }
  41.    }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement