rendered paste body//omfg.
private void openWithToolStripMenuItem_DropDownOpening(object sender, EventArgs e) {
Microsoft.Win32.RegistryKey appsnames = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.txt\\OpenWithList");
List<string> omg = new List<string>();
openWithToolStripMenuItem.DropDownItems.Clear();
foreach(char b in appsnames.GetValue("MRUList").ToString()) {
string appname = appsnames.GetValue(b.ToString()).ToString();
Process path = GetPath(appname, false);
if(path != null) {
string path2 = path.StartInfo.FileName;
if(!String.IsNullOrEmpty(path2)) {
omg.Add(GivePath(path2) + " " + GetFriendlyName(appname));
}
}
}
omg.AddRange(GetProgIDS(".txt"));
foreach(string shit in omg) {
openWithToolStripMenuItem.DropDownItems.Add(shit);
}
}
string GetFriendlyName(string appname) {
Process temp = GetPath(appname, false);
string name1 = "";
if(temp != null) {
if(!String.IsNullOrEmpty(temp.StartInfo.Verb)) {
name1 = ExistsInMUI(GivePath(GetPath(appname, false).StartInfo.Verb));
} else {
name1 = ExistsInMUI(GivePath(GetPath(appname, false).StartInfo.FileName));
}
}
if(!String.IsNullOrEmpty(name1)) {
return name1;
} else {
return GetFriendlyAppName(appname);
}
}
Process GetPath(string appname, bool forceAbsolute) {
Process temp = new Process();
if(appname == "shimgvw.dll") {
temp.StartInfo.FileName = ExecuteCommand("shimgvw.dll").GetValue("").ToString();
temp.StartInfo.Verb = Environment.GetEnvironmentVariable("SystemRoot")+"\\system32\\shimgvw.dll";
//split up the executable from the params..
return temp;
} else {
Microsoft.Win32.RegistryKey key1 = ExistsInAppPaths(appname);
if(key1 != null && !String.IsNullOrEmpty(key1.GetValue("").ToString())) {
if(forceAbsolute) {
temp.StartInfo.FileName = (key1.GetValue("").ToString()).Contains("~") ? Path.GetFullPath(key1.GetValue("").ToString()) : key1.GetValue("").ToString();
} else {
temp.StartInfo.FileName = key1.GetValue("").ToString();
}
return temp;
} else {
if(ExecuteCommand(appname) != null && ExecuteCommand(appname).GetValue("") != null) {
temp.StartInfo.FileName = ExecuteCommand(appname).GetValue("").ToString();
return temp;
} else {
return null;
}
}
}
}
List<string> GetProgIDS(string extension) {
List<string> wee = new List<string>();
Microsoft.Win32.RegistryKey otherapps = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(extension+"\\OpenWithProgids");
foreach(string blah in otherapps.GetValueNames()) {
Microsoft.Win32.RegistryKey other = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(blah+"\\shell\\Open\\command");
string friendlyName = GetFriendlyName(GivePath(other.GetValue("").ToString()).Substring(GivePath(other.GetValue("").ToString()).LastIndexOf("\\")+1));
Process temp = GetPath(GivePath(other.GetValue("").ToString()).Substring(GivePath(other.GetValue("").ToString()).LastIndexOf("\\")+1), false);
string path2 = temp.StartInfo.FileName;
if(!String.IsNullOrEmpty(path2)) {
wee.Add(GivePath(path2) + " " + friendlyName);
}
}
return wee;
}
string GivePath(string value) {
//path here\to file\name omg.exe couldinclude""--stuff-here %1
//"path here\to file\name omg.exe" --stuff-here %1
//"path here\to file\name omg.exe"
//path here\to file\name omg.exe
System.Text.RegularExpressions.Regex exes = new System.Text.RegularExpressions.Regex("(^.*?\\.exe)(.*)");
System.Text.RegularExpressions.Regex stuff = new System.Text.RegularExpressions.Regex("^\"(.*?)\"(.*)");
System.Text.RegularExpressions.Match blah = stuff.Match(value.ToLower());
if(blah.Groups[1].Value != "") {
return blah.Groups[1].Value;
}
System.Text.RegularExpressions.Match blah2 = exes.Match(value.ToLower());
if(blah2.Groups[1].Value != "") {
return blah2.Groups[1].Value;
}
return null;
}
Microsoft.Win32.RegistryKey ExecuteCommand(string appname) {
Microsoft.Win32.RegistryKey b = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Applications\\"+appname+"\\shell\\open\\command");
if(b == null) {
if(Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Applications\\"+appname+"\\shell\\edit\\command") != null) {
return Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Applications\\"+appname+"\\shell\\edit\\command");
} else {
return Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Applications\\"+appname+"\\shell\\Play\\command");
}
}
return b;
}
string ExistsInMUI(string path) {
if(path != null) {
Microsoft.Win32.RegistryKey apptitles2 = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\ShellNoRoam\\MUICache");
foreach(string title in apptitles2.GetValueNames()) {
if(title.ToLower() == path.ToLower()) {
return apptitles2.GetValue(title).ToString();
}
}
}
return null;
}
Microsoft.Win32.RegistryKey ExistsInAppPaths(string appname) {
return Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\"+appname);
}
string GetFriendlyAppName(string appname) {
Microsoft.Win32.RegistryKey b = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey("Applications\\"+appname+"\\shell\\open");
if(b != null && b.GetValue("FriendlyAppName") != null)
return b.GetValue("FriendlyAppName").ToString();
return null;
}