├── src ├── super.ico ├── bin │ ├── Release │ │ ├── SuperCMD.exe │ │ ├── SuperCMD.exe.config │ │ ├── Command Line Usage.txt │ │ └── MUI │ │ │ ├── zh-TW.xml │ │ │ ├── zh-CN.xml │ │ │ └── ja-JP.xml │ └── x64 │ │ └── Release │ │ ├── SuperCMD.exe │ │ ├── SuperCMD.exe.config │ │ ├── Command Line Usage.txt │ │ └── MUI │ │ ├── zh-TW.xml │ │ ├── zh-CN.xml │ │ └── ja-JP.xml ├── SuperCMD.csproj.user ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Resources │ ├── defaultSettings.xml │ └── defaultLanguage.xml ├── Q.cs ├── frmWait.cs ├── SuperCMD.sln ├── app.manifest ├── frmWait.Designer.cs ├── frmConfig.cs ├── frmQEditor.cs ├── MUI.cs ├── frmConfig.resx ├── frmWait.resx ├── frmQEditor.resx ├── frmMain.resx ├── Win32.cs ├── SuperCMD.csproj ├── W31Button.cs ├── frmMain.cs ├── frmConfig.Designer.cs ├── ShellLink.cs ├── Program.cs ├── frmQEditor.Designer.cs └── SuperCore.cs ├── README.md └── LICENSE /src/super.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raymai97/SuperCMD/HEAD/src/super.ico -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperCMD 2 | Run program as SYSTEM, with TrustedInstaller token if desired 3 | -------------------------------------------------------------------------------- /src/bin/Release/SuperCMD.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raymai97/SuperCMD/HEAD/src/bin/Release/SuperCMD.exe -------------------------------------------------------------------------------- /src/bin/x64/Release/SuperCMD.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Raymai97/SuperCMD/HEAD/src/bin/x64/Release/SuperCMD.exe -------------------------------------------------------------------------------- /src/SuperCMD.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectFiles 5 | 6 | -------------------------------------------------------------------------------- /src/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/bin/Release/SuperCMD.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/bin/x64/Release/SuperCMD.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Resources/defaultSettings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Q.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace SuperCMD 5 | { 6 | public class Q 7 | { 8 | public string Name = "", ExeToRun = "", Arguments = "", WorkingDir = ""; 9 | public bool UseTItoken = true; 10 | 11 | public override string ToString() 12 | { 13 | string n = Environment.NewLine; 14 | string s = ""; 15 | if (Name != "") s += MUI.GetText("frmQEditor.lblName") + Name + n; 16 | s += MUI.GetText("frmQEditor.lblProgramPath") + ExeToRun + n; 17 | s += MUI.GetText("frmQEditor.lblArguments") + Arguments + n; 18 | s += MUI.GetText("frmQEditor.grpWorkingDir") + 19 | ((WorkingDir == "") ? "" : WorkingDir) + n; 20 | s += "TrustedInstaller: " + UseTItoken.ToString() + n; 21 | return s; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SuperCMD.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/frmWait.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Drawing; 5 | 6 | namespace SuperCMD 7 | { 8 | public partial class frmWait : Form 9 | { 10 | bool needed() 11 | { 12 | return (System.Diagnostics.Process 13 | .GetProcessesByName("TrustedInstaller").Length == 0); 14 | } 15 | 16 | public void ShowIfNeeded() 17 | { 18 | if (needed()) 19 | { 20 | this.Show(); 21 | } 22 | } 23 | 24 | public void ShowDialogIfNeeded(Form owner) 25 | { 26 | if (needed()) 27 | { 28 | this.ShowDialog(owner); 29 | } 30 | } 31 | 32 | public frmWait() 33 | { 34 | InitializeComponent(); 35 | } 36 | 37 | private void frmWait_FormClosing(object sender, FormClosingEventArgs e) 38 | { 39 | if (e.CloseReason == CloseReason.UserClosing) e.Cancel = true; 40 | } 41 | 42 | private void frmWait_Load(object sender, EventArgs e) 43 | { 44 | if (this.Owner == null) 45 | { 46 | this.CenterToScreen(); 47 | } 48 | else 49 | { 50 | this.CenterToParent(); 51 | } 52 | lbl.Text = MUI.GetText("Common.StartingTI"); 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/SuperCMD.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SuperCMD", "SuperCMD.csproj", "{9F3E4698-8459-4E07-A455-8600D8958B3A}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x64 = Debug|x64 9 | Debug|x86 = Debug|x86 10 | Release|x64 = Release|x64 11 | Release|x86 = Release|x86 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Debug|x64.ActiveCfg = Debug|x64 15 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Debug|x64.Build.0 = Debug|x64 16 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Debug|x86.ActiveCfg = Debug|x86 17 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Debug|x86.Build.0 = Debug|x86 18 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Release|x64.ActiveCfg = Release|x64 19 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Release|x64.Build.0 = Release|x64 20 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Release|x86.ActiveCfg = Release|x86 21 | {9F3E4698-8459-4E07-A455-8600D8958B3A}.Release|x86.Build.0 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /src/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SuperCMD")] 9 | [assembly: AssemblyDescription("Run program as SYSTEM, with TI token if desired")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("MaiSoft")] 12 | [assembly: AssemblyProduct("SuperCMD")] 13 | [assembly: AssemblyCopyright("Copyright © MaiSoft 2015")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("ca825b5c-0a23-4a88-aeb2-bc8d3a00267f")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.1.0.0")] 36 | [assembly: AssemblyFileVersion("2.1.0.0")] 37 | -------------------------------------------------------------------------------- /src/bin/Release/Command Line Usage.txt: -------------------------------------------------------------------------------- 1 | ------ SuperCMD v2.1 Command Line Usage ------ 2 | 3 | SuperCMD.exe [Options] /Run:[Program path and arguments] 4 | 5 | Options: 6 | /TI : Use TrustedInstaller token 7 | /ShowWait : Show "Starting TrustedInstaller" screen 8 | /Dir:[DirPath] : Specify target's working directory 9 | /Silent : Don't show error message 10 | /Debug : Enable Debug mode which always show Log 11 | 12 | ------ Example usage ------ 13 | 14 | Run cmd.exe as SYSTEM user: 15 | SuperCMD.exe /Run:cmd.exe /k echo. Hello SuperCMD! 16 | 17 | Run cmd.exe as SYSTEM user with TrustedInstaller token: 18 | SuperCMD.exe /TI /Run:cmd.exe /k echo. Hello SuperCMD! 19 | 20 | ------ Notes ------ 21 | 22 | '/Run:' must always behind any other argument! 23 | 24 | Everything after '/Run:' should be transferred losslessly. 25 | SuperCMD can handle insane arguments like this: 26 | SuperCMD.exe /Run:cmd.exe /k echo."! // complicated "text"" here \\ !" 27 | 28 | If you're in Safe Mode, you might face error 1314. If so, log off and log on again would fix it. It's the fault of Windows, not SuperCMD. 29 | 30 | ------ Internal use options (Advanced user only) ------ 31 | 32 | /UseTokenOf:[Process Name] * 33 | Specify the process's name to steal token from. 34 | Unreliable if there are multiple same name processes running. 35 | Beware, there will be many 'winlogon.exe' running if multiple users have logged on. 36 | 37 | /UseTokenOfPID:[Process ID] * 38 | Specify the process's ID (PID) to steal token from. 39 | 40 | /ChangeToActiveSessionID 41 | Change the session ID of token to active session ID, so the target program will be visible on current user desktop. 42 | Must running as SYSTEM first! 43 | 44 | * If the process is with different session ID, and you're in Safe Mode, you MIGHT not see your program running on your desktop, unless you specify /ChangeToActiveSessionID. 45 | -------------------------------------------------------------------------------- /src/bin/x64/Release/Command Line Usage.txt: -------------------------------------------------------------------------------- 1 | ------ SuperCMD v2.1 Command Line Usage ------ 2 | 3 | SuperCMD.exe [Options] /Run:[Program path and arguments] 4 | 5 | Options: 6 | /TI : Use TrustedInstaller token 7 | /ShowWait : Show "Starting TrustedInstaller" screen 8 | /Dir:[DirPath] : Specify target's working directory 9 | /Silent : Don't show error message 10 | /Debug : Enable Debug mode which always show Log 11 | 12 | ------ Example usage ------ 13 | 14 | Run cmd.exe as SYSTEM user: 15 | SuperCMD.exe /Run:cmd.exe /k echo. Hello SuperCMD! 16 | 17 | Run cmd.exe as SYSTEM user with TrustedInstaller token: 18 | SuperCMD.exe /TI /Run:cmd.exe /k echo. Hello SuperCMD! 19 | 20 | ------ Notes ------ 21 | 22 | '/Run:' must always behind any other argument! 23 | 24 | Everything after '/Run:' should be transferred losslessly. 25 | SuperCMD can handle insane arguments like this: 26 | SuperCMD.exe /Run:cmd.exe /k echo."! // complicated "text"" here \\ !" 27 | 28 | If you're in Safe Mode, you might face error 1314. If so, log off and log on again would fix it. It's the fault of Windows, not SuperCMD. 29 | 30 | ------ Internal use options (Advanced user only) ------ 31 | 32 | /UseTokenOf:[Process Name] * 33 | Specify the process's name to steal token from. 34 | Unreliable if there are multiple same name processes running. 35 | Beware, there will be many 'winlogon.exe' running if multiple users have logged on. 36 | 37 | /UseTokenOfPID:[Process ID] * 38 | Specify the process's ID (PID) to steal token from. 39 | 40 | /ChangeToActiveSessionID 41 | Change the session ID of token to active session ID, so the target program will be visible on current user desktop. 42 | Must running as SYSTEM first! 43 | 44 | * If the process is with different session ID, and you're in Safe Mode, you MIGHT not see your program running on your desktop, unless you specify /ChangeToActiveSessionID. 45 | -------------------------------------------------------------------------------- /src/bin/Release/MUI/zh-TW.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/bin/x64/Release/MUI/zh-TW.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/bin/Release/MUI/zh-CN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/bin/x64/Release/MUI/zh-CN.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/bin/Release/MUI/ja-JP.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/bin/x64/Release/MUI/ja-JP.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/frmWait.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SuperCMD 2 | { 3 | partial class frmWait 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.lbl = new System.Windows.Forms.Label(); 32 | this.SuspendLayout(); 33 | // 34 | // lbl 35 | // 36 | this.lbl.Dock = System.Windows.Forms.DockStyle.Fill; 37 | this.lbl.Font = new System.Drawing.Font("Segoe UI", 12F); 38 | this.lbl.Location = new System.Drawing.Point(0, 0); 39 | this.lbl.Name = "lbl"; 40 | this.lbl.Size = new System.Drawing.Size(298, 148); 41 | this.lbl.TabIndex = 0; 42 | this.lbl.Text = "Starting TrustedInstaller service...\r\n\r\nPlease wait..."; 43 | this.lbl.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 44 | // 45 | // frmWait 46 | // 47 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 48 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 49 | this.ClientSize = new System.Drawing.Size(298, 148); 50 | this.ControlBox = false; 51 | this.Controls.Add(this.lbl); 52 | this.Font = new System.Drawing.Font("Segoe UI", 9F); 53 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 54 | this.MaximizeBox = false; 55 | this.MinimizeBox = false; 56 | this.Name = "frmWait"; 57 | this.ShowIcon = false; 58 | this.ShowInTaskbar = false; 59 | this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; 60 | this.TopMost = true; 61 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmWait_FormClosing); 62 | this.Load += new System.EventHandler(this.frmWait_Load); 63 | this.ResumeLayout(false); 64 | 65 | } 66 | 67 | #endregion 68 | 69 | private System.Windows.Forms.Label lbl; 70 | } 71 | } -------------------------------------------------------------------------------- /src/Resources/defaultLanguage.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 29 | 42 | 52 | 59 | 71 | -------------------------------------------------------------------------------- /src/frmConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Drawing; 5 | 6 | namespace SuperCMD 7 | { 8 | public partial class frmConfig : Form 9 | { 10 | 11 | #region Movable form 12 | 13 | bool mDown; 14 | Point mPos, frmPos; 15 | 16 | private void frm_MouseDown(object sender, MouseEventArgs e) 17 | { 18 | mDown = true; 19 | mPos = MousePosition; 20 | frmPos = this.Location; 21 | } 22 | 23 | private void frm_MouseMove(object sender, MouseEventArgs e) 24 | { 25 | if (mDown) 26 | { 27 | Point mPos2 = MousePosition; 28 | this.Left = frmPos.X + (mPos2.X - mPos.X); 29 | this.Top = frmPos.Y + (mPos2.Y - mPos.Y); 30 | } 31 | } 32 | 33 | private void frm_MouseUp(object sender, MouseEventArgs e) 34 | { 35 | mDown = false; 36 | } 37 | 38 | #endregion 39 | 40 | string initialLangName = ""; 41 | 42 | public frmConfig() 43 | { 44 | InitializeComponent(); 45 | lblTitle.Text = Program.Title; 46 | } 47 | 48 | private void frmConfig_Load(object sender, EventArgs e) 49 | { 50 | chkBeClassic.Checked = Program.beClassic; 51 | chkBeDPIaware.Checked = Program.beDPIaware; 52 | chkRunAsSYSTEM.Checked = Program.ContextMenuIntegration.RunAsSYSTEM; 53 | chkRunAsSYSTEM_TI.Checked = Program.ContextMenuIntegration.RunAsSYSTEM_TI; 54 | initialLangName = MUI.GetCurrentLangName(); 55 | MUI.RefreshLangList(); 56 | cmbLang.Items.Clear(); 57 | foreach (string DispName in MUI.GetLangDispNameList()) 58 | { 59 | cmbLang.Items.Add(DispName); 60 | } 61 | int LangIndex = MUI.GetCurrentLangIndex(); 62 | if (LangIndex == -1) 63 | { 64 | LangIndex = 0; 65 | Program.RevertFallbackLangFrom(initialLangName); 66 | } 67 | cmbLang.SelectedIndex = LangIndex; 68 | } 69 | 70 | private void frmConfig_FormClosing(object sender, FormClosingEventArgs e) 71 | { 72 | if (this.DialogResult != DialogResult.OK) 73 | { 74 | MUI.TrySetLangByName(initialLangName); 75 | MUI.RefreshFrmLang(); 76 | } 77 | } 78 | private void lblTitle_DoubleClick(object sender, EventArgs e) 79 | { 80 | Program.OfferToggleDebug(); 81 | } 82 | 83 | private void lnkHomepage_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 84 | { 85 | System.Diagnostics.Process.Start("http://raymai97.github.io/SuperCMD"); 86 | } 87 | 88 | private void cmbLang_SelectedIndexChanged(object sender, EventArgs e) 89 | { 90 | MUI.TrySetLangByIndex(cmbLang.SelectedIndex); 91 | MUI.RefreshFrmLang(); 92 | } 93 | 94 | private void btnOK_Click(object sender, EventArgs e) 95 | { 96 | bool RestartRequired = 97 | (Program.beClassic != chkBeClassic.Checked) | 98 | (Program.beDPIaware != chkBeDPIaware.Checked); 99 | Program.beClassic = chkBeClassic.Checked; 100 | Program.beDPIaware = chkBeDPIaware.Checked; 101 | Program.ContextMenuIntegration.RunAsSYSTEM = chkRunAsSYSTEM.Checked; 102 | Program.ContextMenuIntegration.RunAsSYSTEM_TI = chkRunAsSYSTEM_TI.Checked; 103 | 104 | Program.SaveSettings(); 105 | if (RestartRequired) 106 | { 107 | if (MessageBox.Show(MUI.GetText("Common.AskToRestart"), 108 | MUI.GetText("Common.SureBo_title"), 109 | MessageBoxButtons.YesNo, MessageBoxIcon.Question) 110 | == DialogResult.Yes) 111 | { 112 | Application.Restart(); 113 | } 114 | } 115 | DialogResult = DialogResult.OK; 116 | this.Close(); 117 | } 118 | 119 | private void btnCancel_Click(object sender, EventArgs e) 120 | { 121 | this.Close(); 122 | } 123 | 124 | 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SuperCMD.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SuperCMD.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?> 65 | ///<!--For new line, type \n.--> 66 | ///<SuperCMD_Lang Name="en-US" DispName="English"> 67 | /// <Common 68 | /// BadOS="SuperCMD only runs on Windows Vista or newer operating system!" 69 | /// CantStartTI="" 70 | /// FileType_LNK="" 71 | /// CreateLnkOK="" 72 | /// CreateLnkOK_title="" 73 | /// CreateLnkFailed="" 74 | /// CreateLnkFailed_title="" 75 | /// StartingTI="" 76 | /// UseTIToken="" 77 | /// /> 78 | /// <ContextMenuIntegration 79 | /// RunAsSYSTEM="" 80 | /// RunAsSYSTEM_TI="" 81 | /// /> 82 | ///</SuperCMD_Lang>. 83 | /// 84 | internal static string defaultLanguage { 85 | get { 86 | return ResourceManager.GetString("defaultLanguage", resourceCulture); 87 | } 88 | } 89 | 90 | /// 91 | /// Looks up a localized string similar to <?xml version="1.0" encoding="utf-8"?> 92 | ///<SuperCMD DPIaware="True" W31UI="True"> 93 | /// <QLaunch> 94 | /// <Q index="1" name="Command Prompt" exe="%windir%\System32\cmd.exe" args="/k Title SuperCMD v2.0" dir="C:\Users\Raymai\Desktop" /> 95 | /// <Q index="2" name="Registry Editor" exe="%windir%\regedit.exe" /> 96 | /// <Q index="3" name="Task Manager" exe="%windir%\System32\taskmgr.exe" /> 97 | /// <Q index="4" name="Services" exe="%windir%\System32\mmc.exe" args="%windir%\System32\services.msc" /> 98 | /// <Q index="5" /> 99 | /// <Q [rest of string was truncated]";. 100 | /// 101 | internal static string defaultSettings { 102 | get { 103 | return ResourceManager.GetString("defaultSettings", resourceCulture); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/frmQEditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Drawing; 5 | 6 | namespace SuperCMD 7 | { 8 | public partial class frmQEditor : Form 9 | { 10 | 11 | #region Smarter UI Tweak 12 | 13 | private void rdo_AutoCorrect(object sender, EventArgs e) 14 | { 15 | // Make the program usable even if keyboard only 16 | rdoCustomWorkingDir.TabStop = true; 17 | rdoAutoWorkingDir.TabStop = true; 18 | rdoCustomWorkingDir.TabIndex = 1; 19 | rdoAutoWorkingDir.TabIndex = 0; 20 | } 21 | 22 | private void txtCustomWorkingDir_Click(object sender, EventArgs e) 23 | { 24 | rdoCustomWorkingDir.Checked = true; 25 | } 26 | 27 | #endregion 28 | 29 | 30 | public frmQEditor() 31 | { 32 | InitializeComponent(); 33 | } 34 | 35 | private void frmQEditor_Load(object sender, EventArgs e) 36 | { 37 | foreach (TextBox t in new TextBox[] { 38 | txtName, txtArguments, txtCustomWorkingDir, txtProgramPath}) 39 | { 40 | t.BorderStyle = Program.beClassic ? 41 | BorderStyle.FixedSingle : BorderStyle.Fixed3D; 42 | } 43 | } 44 | 45 | public void ReadFrom(Q q) 46 | { 47 | txtName.Text = q.Name; 48 | txtArguments.Text = q.Arguments; 49 | txtProgramPath.Text = q.ExeToRun; 50 | if (q.WorkingDir != "") 51 | { 52 | rdoCustomWorkingDir.Checked = true; 53 | txtCustomWorkingDir.Text = q.WorkingDir; 54 | } 55 | chkTI.Checked = q.UseTItoken; 56 | } 57 | 58 | public void WriteTo(ref Q q) 59 | { 60 | q.Name = txtName.Text; 61 | q.Arguments = txtArguments.Text; 62 | q.ExeToRun = txtProgramPath.Text; 63 | q.WorkingDir = rdoCustomWorkingDir.Checked ? 64 | txtCustomWorkingDir.Text : ""; 65 | q.UseTItoken = chkTI.Checked; 66 | } 67 | 68 | public void ClearAll() 69 | { 70 | foreach (TextBox txt in new TextBox[] { 71 | txtName, txtArguments, txtProgramPath, 72 | txtCustomWorkingDir}) 73 | { 74 | txt.Clear(); 75 | txt.SelectionStart = int.MaxValue; 76 | } 77 | rdoAutoWorkingDir.Checked = true; 78 | chkTI.Checked = true; 79 | txtName.Select(); 80 | txtName.SelectAll(); 81 | } 82 | 83 | private void btnSelectExe_Click(object sender, EventArgs e) 84 | { 85 | OpenFileDialog ofd = new OpenFileDialog(); 86 | ofd.FileName = ""; 87 | ofd.Multiselect = false; 88 | ofd.Filter = "Executable files|*.exe;*.bat;*.cmd"; 89 | if (ofd.ShowDialog() == DialogResult.OK) 90 | { 91 | txtProgramPath.Text = ofd.FileName; 92 | } 93 | } 94 | 95 | private void btnAppendArgs_Click(object sender, EventArgs e) 96 | { 97 | OpenFileDialog ofd = new OpenFileDialog(); 98 | ofd.FileName = ""; 99 | ofd.Multiselect = true; 100 | if (ofd.ShowDialog() == DialogResult.OK) 101 | { 102 | foreach (string filePath in ofd.FileNames) 103 | { 104 | txtArguments.AppendText("\"" + filePath + "\" "); 105 | } 106 | } 107 | } 108 | 109 | private void btnSelectWorkingDir_Click(object sender, EventArgs e) 110 | { 111 | FolderBrowserDialog fbd = new FolderBrowserDialog(); 112 | fbd.SelectedPath = txtCustomWorkingDir.Text; 113 | fbd.ShowNewFolderButton = true; 114 | if (fbd.ShowDialog() == DialogResult.OK) 115 | { 116 | txtCustomWorkingDir.Text = fbd.SelectedPath; 117 | rdoCustomWorkingDir.Checked = true; 118 | } 119 | } 120 | 121 | private void btnOK_Click(object sender, EventArgs e) 122 | { 123 | DialogResult = System.Windows.Forms.DialogResult.OK; 124 | Close(); 125 | } 126 | 127 | private void btnCancel_Click(object sender, EventArgs e) 128 | { 129 | DialogResult = System.Windows.Forms.DialogResult.Cancel; 130 | Close(); 131 | } 132 | 133 | private void btnMenu_Click(object sender, EventArgs e) 134 | { 135 | mnuQEdit.Show(btnQEditMenu, new Point(0, 0), ToolStripDropDownDirection.AboveRight); 136 | } 137 | 138 | private void cmiCopy_Click(object sender, EventArgs e) 139 | { 140 | Q q = Program.CopiedQ; 141 | q.Name = txtName.Text; 142 | q.Arguments = txtArguments.Text; 143 | q.ExeToRun = txtProgramPath.Text; 144 | q.WorkingDir = rdoCustomWorkingDir.Checked ? txtCustomWorkingDir.Text : ""; 145 | q.UseTItoken = chkTI.Checked; 146 | } 147 | 148 | private void cmiCopyAsText_Click(object sender, EventArgs e) 149 | { 150 | Q q = new Q(); 151 | q.Name = txtName.Text; 152 | q.Arguments = txtArguments.Text; 153 | q.ExeToRun = txtProgramPath.Text; 154 | q.WorkingDir = rdoCustomWorkingDir.Checked ? txtCustomWorkingDir.Text : ""; 155 | q.UseTItoken = chkTI.Checked; 156 | Clipboard.SetText(q.ToString()); 157 | } 158 | 159 | private void cmiPaste_Click(object sender, EventArgs e) 160 | { 161 | Q q = Program.CopiedQ; 162 | txtName.Text = q.Name; 163 | txtArguments.Text = q.Arguments; 164 | txtProgramPath.Text = q.ExeToRun; 165 | if (q.WorkingDir == "") 166 | { 167 | rdoAutoWorkingDir.Checked = true; 168 | } 169 | else 170 | { 171 | rdoCustomWorkingDir.Checked = true; 172 | txtCustomWorkingDir.Text = q.WorkingDir; 173 | } 174 | chkTI.Checked = q.UseTItoken; 175 | } 176 | 177 | private void cmiClearAll_Click(object sender, EventArgs e) 178 | { 179 | ClearAll(); 180 | } 181 | 182 | private void cmiCreateLnk_Click(object sender, EventArgs e) 183 | { 184 | Q q = new Q(); 185 | q.Name = txtName.Text; 186 | q.Arguments = txtArguments.Text; 187 | q.ExeToRun = txtProgramPath.Text; 188 | q.WorkingDir = rdoCustomWorkingDir.Checked ? 189 | txtCustomWorkingDir.Text : ""; 190 | q.UseTItoken = chkTI.Checked; 191 | Program.OfferCreateLnk(q); 192 | } 193 | 194 | 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/MUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.IO; 5 | using System.Text; 6 | using System.Xml; 7 | 8 | namespace SuperCMD 9 | { 10 | public static class MUI 11 | { 12 | 13 | static List LangList = new List(); 14 | static Lang CurrentLang; 15 | 16 | public static frmMain MainUI; 17 | public static frmConfig ConfigUI; 18 | public static frmQEditor QEditorUI; 19 | 20 | static MUI() 21 | { 22 | RefreshLangList(); 23 | CurrentLang = LangList[0]; 24 | } 25 | 26 | public static List GetLangDispNameList() 27 | { 28 | List List = new List(); 29 | foreach (Lang lang in LangList) 30 | { 31 | List.Add(lang.DispName); 32 | } 33 | return List; 34 | } 35 | 36 | public static string GetCurrentLangName() 37 | { 38 | return CurrentLang.Name; 39 | } 40 | 41 | public static int GetCurrentLangIndex() 42 | { 43 | // Cannot use IndexOf becuz it will not work after RefreshLangList() 44 | for (int i = 0; i <= LangList.Count - 1; i++) 45 | { 46 | if (LangList[i].Name.ToLower() == 47 | CurrentLang.Name.ToLower()) return i; 48 | } 49 | return -1; 50 | } 51 | 52 | public static string GetText(string key) 53 | { 54 | string value; 55 | if (!CurrentLang.Strs.TryGetValue(key, out value)) 56 | { 57 | MessageBox.Show( 58 | "Can't find text for '" + key + "' in current language.\n" + 59 | "Will use fallback language (English) instead.", 60 | "Missing text", MessageBoxButtons.OK, MessageBoxIcon.Information); 61 | CurrentLang = LangList[0]; 62 | if (!CurrentLang.Strs.TryGetValue(key, out value)) 63 | { 64 | MessageBox.Show( 65 | "Can't find text for '" + key + "' even in fallback language!\n" + 66 | "Application will exit!", "CRITICAL ERROR", 67 | MessageBoxButtons.OK, MessageBoxIcon.Error); 68 | Environment.Exit(1); 69 | } 70 | } 71 | return value; 72 | } 73 | 74 | public static bool TrySetLangByName(string LangName) 75 | { 76 | foreach (Lang lang in LangList) 77 | { 78 | if (lang.Name.ToLower() == LangName.ToLower()) 79 | { 80 | CurrentLang = lang; 81 | return true; 82 | } 83 | } 84 | return false; 85 | } 86 | 87 | public static bool TrySetLangByIndex(int i) 88 | { 89 | try 90 | { 91 | CurrentLang = LangList[i]; 92 | return true; 93 | } 94 | catch (Exception) 95 | { 96 | return false; 97 | } 98 | } 99 | 100 | public static void RefreshLangList() 101 | { 102 | LangList.Clear(); 103 | // No matter what, English must always be available 104 | LangList.Add(XmlToLang(Properties.Resources.defaultLanguage)); 105 | // Load external Language XML if possible 106 | if (!Directory.Exists(Program.MUIDirPath)) return; 107 | foreach (string file in Directory.GetFiles(Program.MUIDirPath)) 108 | { 109 | try 110 | { 111 | Lang lang = XmlToLang( 112 | File.ReadAllText(file, Encoding.UTF8) 113 | ); 114 | LangList.Add(lang); 115 | } 116 | catch (Exception) 117 | { } 118 | } 119 | } 120 | 121 | public static void RefreshFrmLang() 122 | { 123 | foreach (KeyValuePair item in CurrentLang.Strs) 124 | { 125 | SetFrmCtrlText(MainUI, item.Key, item.Value); 126 | SetFrmCtrlText(QEditorUI, item.Key, item.Value); 127 | SetFrmCtrlText(ConfigUI, item.Key, item.Value); 128 | SetMenuText(MainUI.mnuQEdit, item.Key, item.Value); 129 | SetMenuText(QEditorUI.mnuQEdit, item.Key, item.Value); 130 | if (item.Key == "Common.UseTIToken") 131 | { 132 | foreach (CheckBox chk in new CheckBox[]{ 133 | MainUI.chkTI, MainUI.chkTI_quick, QEditorUI.chkTI}) 134 | { 135 | chk.Text = item.Value; 136 | chk.Left = (chk.Parent.Width - chk.Width) / 2; 137 | } 138 | } 139 | } 140 | } 141 | 142 | static void SetFrmCtrlText(Form frm, string key, string value) 143 | { 144 | if (key.StartsWith(frm.Name + ".")) 145 | { 146 | string ctrlName = key.Substring(key.IndexOf(".") + 1); 147 | Control[] _ = frm.Controls.Find(ctrlName, true); 148 | if (_.Length > 0) 149 | { 150 | _[0].Text = value; 151 | } 152 | else if (ctrlName == "TITLE") 153 | { 154 | frm.Text = value; 155 | } 156 | } 157 | } 158 | 159 | static void SetMenuText(ContextMenuStrip mnu, string key, string value) 160 | { 161 | if (key.StartsWith(mnu.Name + ".")) 162 | { 163 | string itemName = key.Substring(key.IndexOf(".") + 1); 164 | ToolStripItem[] _ = mnu.Items.Find(itemName, true); 165 | if (_.Length > 0) _[0].Text = value; 166 | } 167 | } 168 | 169 | static Lang XmlToLang(string XmlText) 170 | { 171 | XmlText = XmlText.Replace("\\n", " "); 172 | XmlDocument XmlDoc = new XmlDocument(); 173 | XmlDoc.LoadXml(XmlText); 174 | XmlNode root = XmlDoc.SelectSingleNode("SuperCMD_Lang"); 175 | Lang lang = new Lang(root.Attributes["Name"].Value, 176 | root.Attributes["DispName"].Value); 177 | foreach (XmlNode node in root.ChildNodes) 178 | { 179 | foreach (XmlAttribute attr in 180 | root.SelectSingleNode(node.Name).Attributes) 181 | { 182 | lang.Strs.Add(node.Name + "." + attr.Name, attr.Value); 183 | } 184 | } 185 | return lang; 186 | } 187 | 188 | public class Lang 189 | { 190 | public Dictionary Strs; 191 | public string Name, DispName; 192 | 193 | public Lang(string Name, string DispName) 194 | { 195 | this.Name = Name; 196 | this.DispName = DispName; 197 | Strs = new Dictionary(); 198 | } 199 | 200 | } 201 | 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /src/frmConfig.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /src/frmWait.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /src/frmQEditor.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | -------------------------------------------------------------------------------- /src/frmMain.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 85, 17 122 | 123 | 124 | 17, 17 125 | 126 | -------------------------------------------------------------------------------- /src/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\defaultLanguage.xml;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 123 | 124 | 125 | 126 | ..\Resources\defaultSettings.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 127 | 128 | -------------------------------------------------------------------------------- /src/Win32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using System.Windows.Forms; 6 | using System.ComponentModel; 7 | 8 | namespace SuperCMD 9 | { 10 | class Win32 11 | { 12 | 13 | [DllImport("user32.dll", SetLastError = true)] 14 | public static extern bool SetProcessDPIAware(); 15 | 16 | [DllImport("shell32.dll", CharSet = CharSet.Auto)] 17 | public static extern uint ExtractIconEx(string szFileName, int nIconIndex, 18 | IntPtr[] phiconLarge, IntPtr[] phiconSmall, uint nIcons); 19 | 20 | #region SendMessage API 21 | 22 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 23 | public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam); 24 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 25 | public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref COPYDATASTRUCT lParam); 26 | [DllImport("user32.dll")] 27 | public static extern bool InSendMessage(); 28 | [DllImport("user32.dll")] 29 | public static extern bool ReplyMessage(IntPtr lResult); 30 | 31 | public const int WM_COPYDATA = 0x004A; 32 | 33 | [StructLayout(LayoutKind.Sequential)] 34 | public struct COPYDATASTRUCT 35 | { 36 | /// 37 | /// Pointer of sender (so receiver can send back) 38 | /// 39 | public IntPtr dwData; 40 | /// 41 | /// Count of Bytes 42 | /// 43 | public int cbData; 44 | /// 45 | /// Pointer of a byte array 46 | /// 47 | public IntPtr lpData; 48 | } 49 | 50 | public static void _SendMessage(string msg, IntPtr target) 51 | { 52 | byte[] b = Encoding.UTF8.GetBytes(msg); 53 | IntPtr hLog = Marshal.AllocHGlobal(b.Length); 54 | Marshal.Copy(b, 0, hLog, b.Length); 55 | COPYDATASTRUCT data = new COPYDATASTRUCT(); 56 | data.cbData = b.Length; 57 | data.lpData = hLog; 58 | SendMessage(target, WM_COPYDATA, 0, ref data); 59 | } 60 | 61 | public static string _GetMessage(Message m) 62 | { 63 | string msg = null; 64 | if (m.Msg == Win32.WM_COPYDATA) 65 | { 66 | if (InSendMessage()) ReplyMessage(IntPtr.Zero); 67 | COPYDATASTRUCT data = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT)); 68 | byte[] b = new byte[data.cbData]; 69 | Marshal.Copy(data.lpData, b, 0, data.cbData); 70 | msg = Encoding.UTF8.GetString(b); 71 | } 72 | return msg; 73 | } 74 | 75 | #endregion 76 | 77 | #region Set form's large and small icon explicitly 78 | 79 | const int WM_SETICON = 0x80; 80 | const int ICON_SMALL = 0; 81 | const int ICON_BIG = 1; 82 | 83 | public static void SetFormIcon(IntPtr hWnd, string IconPath, int IconIndex = 0) 84 | { 85 | uint IconCount = (uint)(IconIndex) + 1; 86 | IntPtr[] hSmallIcon = new IntPtr[IconCount]; 87 | IntPtr[] hLargeIcon = new IntPtr[IconCount]; 88 | ExtractIconEx(IconPath, IconIndex, hLargeIcon, hSmallIcon, IconCount); 89 | SendMessage(hWnd, WM_SETICON, ICON_BIG, hLargeIcon[IconIndex]); 90 | SendMessage(hWnd, WM_SETICON, ICON_SMALL, hSmallIcon[IconIndex]); 91 | } 92 | 93 | #endregion 94 | 95 | #region Start service even if it's disabled 96 | 97 | [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 98 | static extern IntPtr OpenSCManager(string machineName, string databaseName, uint dwAccess); 99 | 100 | [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 101 | static extern IntPtr OpenService(IntPtr hSCManager, string lpServiceName, uint dwDesiredAccess); 102 | 103 | [DllImport("advapi32.dll", EntryPoint = "CloseServiceHandle")] 104 | static extern int CloseServiceHandle(IntPtr hSCObject); 105 | 106 | [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 107 | static extern Boolean ChangeServiceConfig( 108 | IntPtr hService, 109 | UInt32 nServiceType, 110 | SvcStartupType nStartType, 111 | UInt32 nErrorControl, 112 | String lpBinaryPathName, 113 | String lpLoadOrderGroup, 114 | IntPtr lpdwTagId, 115 | [In] char[] lpDependencies, 116 | String lpServiceStartName, 117 | String lpPassword, 118 | String lpDisplayName); 119 | 120 | [DllImport("advapi32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 121 | static extern Boolean QueryServiceConfig( 122 | IntPtr hService, 123 | IntPtr intPtrQueryConfig, 124 | UInt32 cbBufSize, 125 | out UInt32 pcbBytesNeeded); 126 | 127 | [DllImport("advapi32", SetLastError = true)] 128 | [return: MarshalAs(UnmanagedType.Bool)] 129 | public static extern bool StartService( 130 | IntPtr hService, 131 | int dwNumServiceArgs, 132 | string[] lpServiceArgVectors 133 | ); 134 | 135 | const uint SC_MANAGER_CONNECT = 0x00000001; 136 | const uint SC_MANAGER_ALL_ACCESS = 0x000F003F; 137 | const uint SERVICE_QUERY_CONFIG = 0x00000001; 138 | const uint SERVICE_CHANGE_CONFIG = 0x00000002; 139 | const uint SERVICE_START = 0x00000016; 140 | const uint SERVICE_NO_CHANGE = 0xFFFFFFFF; 141 | 142 | enum SvcStartupType : uint 143 | { 144 | BootStart = 0, //Device driver started by the system loader. 145 | SystemStart = 1, //Device driver started by the IoInitSystem function. 146 | Automatic = 2, 147 | Manual = 3, 148 | Disabled = 4 149 | } 150 | 151 | [StructLayout(LayoutKind.Sequential)] 152 | class QUERY_SERVICE_CONFIG 153 | { 154 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] 155 | public UInt32 dwServiceType; 156 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] 157 | public SvcStartupType dwStartType; 158 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] 159 | public UInt32 dwErrorControl; 160 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] 161 | public String lpBinaryPathName; 162 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] 163 | public String lpLoadOrderGroup; 164 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)] 165 | public UInt32 dwTagID; 166 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] 167 | public String lpDependencies; 168 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] 169 | public String lpServiceStartName; 170 | [MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)] 171 | public String lpDisplayName; 172 | }; 173 | 174 | public static bool TryStartService(string svcName) 175 | { 176 | bool wasDisabled = false; 177 | QUERY_SERVICE_CONFIG SvcConfig = new QUERY_SERVICE_CONFIG(); 178 | IntPtr hSvcMgr = OpenSCManager(null, null, SC_MANAGER_CONNECT); 179 | IntPtr hSvc = OpenService(hSvcMgr, "TrustedInstaller", 180 | SERVICE_CHANGE_CONFIG | SERVICE_QUERY_CONFIG | SERVICE_START); 181 | // Check if the service was disabled 182 | uint dummy = 0; 183 | IntPtr ptr = Marshal.AllocHGlobal(4096); 184 | if (!QueryServiceConfig(hSvc, ptr, 4096, out dummy)) return false; 185 | Marshal.PtrToStructure(ptr, SvcConfig); 186 | Marshal.FreeHGlobal(ptr); 187 | wasDisabled = (SvcConfig.dwStartType == SvcStartupType.Disabled); 188 | // If it was disabled, set it as manual temporary 189 | if (wasDisabled) 190 | { 191 | if (!ChangeServiceConfig(hSvc, SERVICE_NO_CHANGE, 192 | SvcStartupType.Manual, SERVICE_NO_CHANGE, 193 | null, null, IntPtr.Zero, null, null, null, null)) return false; 194 | } 195 | // Start the service 196 | StartService(hSvc, 0, null); 197 | // If it was disabled, set it back to disabled 198 | if (wasDisabled) 199 | { 200 | if (!ChangeServiceConfig(hSvc, SERVICE_NO_CHANGE, 201 | SvcStartupType.Disabled, SERVICE_NO_CHANGE, 202 | null, null, IntPtr.Zero, null, null, null, null)) return false; 203 | } 204 | // Clean up 205 | CloseServiceHandle(hSvc); 206 | CloseServiceHandle(hSvcMgr); 207 | return true; 208 | } 209 | 210 | #endregion 211 | 212 | public static string WinAPILastErrMsg() 213 | { 214 | return WinAPILastErrMsg(Marshal.GetLastWin32Error()); 215 | } 216 | 217 | public static string WinAPILastErrMsg(int err) 218 | { 219 | return new Win32Exception(err).Message + " (Error code: " + err + ")"; 220 | } 221 | 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/SuperCMD.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {9F3E4698-8459-4E07-A455-8600D8958B3A} 9 | WinExe 10 | Properties 11 | SuperCMD 12 | SuperCMD 13 | v2.0 14 | 512 15 | publish\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | 0 26 | 1.0.0.%2a 27 | false 28 | false 29 | true 30 | 31 | 32 | AnyCPU 33 | true 34 | full 35 | false 36 | bin\Debug\ 37 | DEBUG;TRACE 38 | prompt 39 | 4 40 | false 41 | 42 | 43 | x86 44 | pdbonly 45 | true 46 | bin\Release\ 47 | TRACE 48 | prompt 49 | 4 50 | false 51 | 52 | 53 | 54 | app.manifest 55 | 56 | 57 | super.ico 58 | 59 | 60 | true 61 | bin\x64\Debug\ 62 | DEBUG;TRACE 63 | full 64 | x64 65 | false 66 | prompt 67 | false 68 | false 69 | false 70 | 71 | 72 | bin\x64\Release\ 73 | TRACE 74 | true 75 | pdbonly 76 | x64 77 | false 78 | prompt 79 | false 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | Form 90 | 91 | 92 | frmConfig.cs 93 | 94 | 95 | Form 96 | 97 | 98 | frmMain.cs 99 | 100 | 101 | Form 102 | 103 | 104 | frmQEditor.cs 105 | 106 | 107 | Form 108 | 109 | 110 | frmWait.cs 111 | 112 | 113 | 114 | 115 | 116 | True 117 | True 118 | Resources.resx 119 | 120 | 121 | 122 | 123 | 124 | Component 125 | 126 | 127 | 128 | frmConfig.cs 129 | 130 | 131 | frmMain.cs 132 | 133 | 134 | frmQEditor.cs 135 | 136 | 137 | frmWait.cs 138 | 139 | 140 | ResXFileCodeGenerator 141 | Designer 142 | Resources.Designer.cs 143 | 144 | 145 | 146 | SettingsSingleFileGenerator 147 | Settings.Designer.cs 148 | 149 | 150 | True 151 | Settings.settings 152 | True 153 | 154 | 155 | 156 | 157 | False 158 | .NET Framework 3.5 SP1 Client Profile 159 | false 160 | 161 | 162 | False 163 | .NET Framework 3.5 SP1 164 | true 165 | 166 | 167 | False 168 | Windows Installer 3.1 169 | true 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 187 | -------------------------------------------------------------------------------- /src/W31Button.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Drawing; 5 | using System.Drawing.Drawing2D; 6 | using System.Drawing.Text; 7 | using System.ComponentModel; 8 | 9 | class W31Button : Button 10 | { 11 | 12 | #region SuperCMD custom code 13 | 14 | bool beClassic; 15 | 16 | public W31Button() 17 | { 18 | beClassic = (SuperCMD.Program.beClassic); 19 | if (beClassic) 20 | { 21 | this.BackColor = Color.FromArgb(195, 199, 203); 22 | this.ForeColor = Color.Black; 23 | } 24 | } 25 | 26 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 27 | public override Color BackColor 28 | { 29 | get 30 | { 31 | return base.BackColor; 32 | } 33 | set 34 | { 35 | base.BackColor = value; 36 | } 37 | } 38 | 39 | [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] 40 | public override Color ForeColor 41 | { 42 | get 43 | { 44 | return base.ForeColor; 45 | } 46 | set 47 | { 48 | base.ForeColor = value; 49 | } 50 | } 51 | 52 | #endregion 53 | 54 | Pen penBorder = Pens.Black; 55 | Pen penInnerBorderTopLeft = Pens.White; 56 | Pen penInnerBorderBottomRight = new Pen(Color.FromArgb(134, 138, 142)); 57 | Pen penBorder2 = new Pen(Color.Black,2); 58 | Pen penInnerBorderTopLeft2 = new Pen(Color.FromArgb(134, 138, 142)); 59 | Color ParentBgColor = Color.White; 60 | 61 | bool mDown, mOver, mPress; 62 | int maxX, maxY; 63 | Rectangle contentRect; 64 | StringFormat sf = new StringFormat(); 65 | 66 | public Bitmap toBmp() 67 | { 68 | Bitmap bmp = new Bitmap(this.ClientSize.Width, this.ClientSize.Height); 69 | Graphics g = Graphics.FromImage(bmp); 70 | if (this.Parent != null) 71 | { 72 | g.Clear(this.Parent.BackColor); 73 | } 74 | else 75 | { 76 | g.Clear(ParentBgColor); 77 | } 78 | // Prepare 79 | maxX = this.ClientSize.Width - 1; 80 | maxY = this.ClientSize.Height - 1; 81 | contentRect = new Rectangle(4, 4, maxX - 4 - 3, maxY - 4 - 3); 82 | contentRect.X += this.Padding.Left; 83 | contentRect.Y += this.Padding.Top; 84 | contentRect.Width -= this.Padding.Right; 85 | contentRect.Height -= this.Padding.Bottom; 86 | Int32 txtAgnNum = (Int32)Math.Log((Double)this.TextAlign, 2); 87 | sf.LineAlignment = (StringAlignment)(txtAgnNum / 4); 88 | sf.Alignment = (StringAlignment)(txtAgnNum % 4); 89 | sf.HotkeyPrefix = HotkeyPrefix.Show; 90 | // Fill button color 91 | g.FillRectangle(new SolidBrush(this.BackColor), new Rectangle(1, 1, maxX - 1, maxY - 1)); 92 | if ((mDown & mOver) | mPress) g.TranslateTransform(1, 1); 93 | // Draw background image 94 | if (this.BackgroundImage != null) 95 | { 96 | int imgX = 0, imgY = 0; 97 | switch (this.BackgroundImageLayout) 98 | { 99 | case ImageLayout.Center: 100 | imgX = (int)(contentRect.Width - this.BackgroundImage.Width) / 2; 101 | imgY = (int)(contentRect.Height - this.BackgroundImage.Height) / 2; 102 | imgX += contentRect.X; 103 | imgY += contentRect.Y; 104 | g.DrawImageUnscaled(this.BackgroundImage, imgX, imgY); 105 | break; 106 | case ImageLayout.Stretch: 107 | g.DrawImage(this.BackgroundImage, contentRect); 108 | break; 109 | case ImageLayout.Tile: 110 | g.FillRectangle(new TextureBrush(this.BackgroundImage, WrapMode.Tile), contentRect); 111 | break; 112 | case ImageLayout.Zoom: 113 | this.BackgroundImageLayout = ImageLayout.Stretch; 114 | break; 115 | default: // assume as None 116 | break; 117 | } 118 | } 119 | // Draw image 120 | if (this.Image != null) 121 | { 122 | int imgX = 0, imgY = 0; 123 | switch (this.ImageAlign) 124 | { 125 | case ContentAlignment.BottomCenter: 126 | imgX = (int)(contentRect.Width - this.Image.Width) / 2; 127 | imgY = contentRect.Height - this.Image.Height; 128 | break; 129 | case ContentAlignment.BottomLeft: 130 | imgY = contentRect.Height - this.Image.Height; 131 | break; 132 | case ContentAlignment.BottomRight: 133 | imgX = contentRect.Width - this.Image.Width; 134 | imgY = contentRect.Height - this.Image.Height; 135 | break; 136 | case ContentAlignment.MiddleLeft: 137 | imgY = (int)(contentRect.Height - this.Image.Height) / 2; 138 | break; 139 | case ContentAlignment.MiddleRight: 140 | imgX = contentRect.Width - this.Image.Width; 141 | imgY = (int)(contentRect.Height - this.Image.Height) / 2; 142 | break; 143 | case ContentAlignment.TopCenter: 144 | imgX = (int)(contentRect.Width - this.Image.Width) / 2; 145 | break; 146 | case ContentAlignment.TopLeft: 147 | break; 148 | case ContentAlignment.TopRight: 149 | imgX = contentRect.Width - this.Image.Width; 150 | break; 151 | default: // assume as MiddleCenter 152 | imgX = (int)(contentRect.Width - this.Image.Width) / 2; 153 | imgY = (int)(contentRect.Height - this.Image.Height) / 2; 154 | break; 155 | } 156 | imgX += contentRect.X; 157 | imgY += contentRect.Y; 158 | g.DrawImageUnscaled(this.Image, imgX, imgY); 159 | } 160 | // Draw text 161 | Brush textBrush = new SolidBrush(this.ForeColor); 162 | if (!this.Enabled) 163 | { 164 | textBrush = new HatchBrush(HatchStyle.Percent50, this.ForeColor, this.BackColor); 165 | } 166 | g.DrawString(this.Text, this.Font, textBrush, contentRect, sf); 167 | g.ResetTransform(); 168 | // Draw border 169 | if ((mDown & mOver) | mPress) 170 | { 171 | // Border (Top, Bottom, Left, Right) 172 | g.DrawLine(penBorder2, new Point(1, 1), new Point(maxX, 1)); 173 | g.DrawLine(penBorder2, new Point(1, maxY), new Point(maxX, maxY)); 174 | g.DrawLine(penBorder2, new Point(1, 1), new Point(1, maxY)); 175 | g.DrawLine(penBorder2, new Point(maxX, 1), new Point(maxX, maxY)); 176 | // Inner Border (Top) 177 | g.DrawLine(penInnerBorderTopLeft2, new Point(2, 2), new Point(this.ClientSize.Width - 3, 2)); 178 | // Inner Border (Left) 179 | g.DrawLine(penInnerBorderTopLeft2, new Point(2, 2), new Point(2, this.ClientSize.Height - 3)); 180 | } 181 | else if (this.Focused) 182 | { 183 | // Border (Top, Bottom, Left, Right) 184 | g.DrawLine(penBorder2, new Point(1, 1), new Point(maxX, 1)); 185 | g.DrawLine(penBorder2, new Point(1, maxY), new Point(maxX, maxY)); 186 | g.DrawLine(penBorder2, new Point(1, 1), new Point(1, maxY)); 187 | g.DrawLine(penBorder2, new Point(maxX, 1), new Point(maxX, maxY)); 188 | // Inner Border (Top) 189 | g.DrawLine(penInnerBorderTopLeft, new Point(2, 2), new Point(maxX - 2, 2)); 190 | g.DrawLine(penInnerBorderTopLeft, new Point(2, 3), new Point(maxX - 3, 3)); 191 | // Inner Border (Left) 192 | g.DrawLine(penInnerBorderTopLeft, new Point(2, 2), new Point(2, maxY - 2)); 193 | g.DrawLine(penInnerBorderTopLeft, new Point(3, 2), new Point(3, maxY - 3)); 194 | // Inner Border (Bottom) 195 | g.DrawLine(penInnerBorderBottomRight, new Point(3, maxY - 3), new Point(maxX - 3, maxY - 3)); 196 | g.DrawLine(penInnerBorderBottomRight, new Point(2, maxY - 2), new Point(maxX - 2, maxY - 2)); 197 | // Inner Border (Right) 198 | g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 3, 4), new Point(maxX - 3, maxY - 3)); 199 | g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 2, 3), new Point(maxX - 2, maxY - 2)); 200 | } 201 | else 202 | { 203 | // Border (Top, Bottom, Left, Right) 204 | g.DrawLine(penBorder, new Point(1, 0), new Point(maxX - 1, 0)); 205 | g.DrawLine(penBorder, new Point(1, maxY), new Point(maxX - 1, maxY)); 206 | g.DrawLine(penBorder, new Point(0, 1), new Point(0, maxY - 1)); 207 | g.DrawLine(penBorder, new Point(maxX, 1), new Point(maxX, maxY - 1)); 208 | // Inner Border (Top) 209 | g.DrawLine(penInnerBorderTopLeft, new Point(1, 1), new Point(maxX - 1, 1)); 210 | g.DrawLine(penInnerBorderTopLeft, new Point(1, 2), new Point(maxX - 2, 2)); 211 | // Inner Border (Left) 212 | g.DrawLine(penInnerBorderTopLeft, new Point(1, 1), new Point(1, maxY - 1)); 213 | g.DrawLine(penInnerBorderTopLeft, new Point(2, 1), new Point(2, maxY - 2)); 214 | // Inner Border (Bottom) 215 | g.DrawLine(penInnerBorderBottomRight, new Point(2, maxY - 2), new Point(maxX - 2, maxY - 2)); 216 | g.DrawLine(penInnerBorderBottomRight, new Point(1, maxY - 1), new Point(maxX - 1, maxY - 1)); 217 | // Inner Border (Right) 218 | g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 2, 3), new Point(maxX - 2, maxY - 2)); 219 | g.DrawLine(penInnerBorderBottomRight, new Point(maxX - 1, 2), new Point(maxX - 1, maxY - 1)); 220 | } 221 | g.Dispose(); 222 | return bmp; 223 | } 224 | 225 | protected override void OnPaint(PaintEventArgs pevent) 226 | { 227 | if (beClassic) 228 | { 229 | Bitmap bmp = this.toBmp(); 230 | pevent.Graphics.DrawImageUnscaled(bmp, 0, 0); 231 | bmp.Dispose(); 232 | } 233 | else 234 | { 235 | base.OnPaint(pevent); 236 | } 237 | } 238 | 239 | protected override void OnLostFocus(EventArgs e) 240 | { 241 | mDown = false; 242 | this.Refresh(); 243 | base.OnLostFocus(e); 244 | } 245 | 246 | protected override void OnMouseDown(MouseEventArgs mevent) 247 | { 248 | if (mevent.Button == MouseButtons.Left) 249 | { 250 | mDown = true; 251 | this.Refresh(); 252 | } 253 | base.OnMouseDown(mevent); 254 | } 255 | 256 | protected override void OnMouseUp(MouseEventArgs mevent) 257 | { 258 | if (mevent.Button == MouseButtons.Left) 259 | { 260 | mDown = false; 261 | this.Refresh(); 262 | } 263 | base.OnMouseUp(mevent); 264 | } 265 | 266 | protected override void OnMouseMove(MouseEventArgs mevent) 267 | { 268 | mOver = (this.ClientRectangle.Contains(PointToClient(MousePosition))); 269 | this.Refresh(); 270 | base.OnMouseMove(mevent); 271 | } 272 | 273 | protected override void OnKeyPress(KeyPressEventArgs e) 274 | { 275 | // If pressed Spacebar... 276 | if (e.KeyChar == ' ') 277 | { 278 | mPress = true; 279 | } 280 | this.Refresh(); 281 | base.OnKeyPress(e); 282 | } 283 | 284 | protected override void OnKeyUp(KeyEventArgs kevent) 285 | { 286 | mPress = false; 287 | this.Refresh(); 288 | base.OnKeyUp(kevent); 289 | } 290 | 291 | } 292 | -------------------------------------------------------------------------------- /src/frmMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Drawing; 5 | using System.ComponentModel; 6 | 7 | namespace SuperCMD 8 | { 9 | public partial class frmMain : Form 10 | { 11 | 12 | IntPtr hWnd; 13 | Q[] Qs = Program.Qs; 14 | frmConfig ConfigUI = new frmConfig(); 15 | frmQEditor QEditorUI = new frmQEditor(); 16 | frmWait WaitUI = new frmWait(); 17 | 18 | private void ClearAll() 19 | { 20 | foreach (TextBox txt in new TextBox[] { 21 | txtArguments, txtProgramPath, txtCustomWorkingDir}) 22 | { 23 | txt.Clear(); 24 | txt.SelectionStart = int.MaxValue; 25 | } 26 | rdoAutoWorkingDir.Checked = true; 27 | chkTI.Checked = true; 28 | txtProgramPath.Select(); 29 | txtProgramPath.SelectAll(); 30 | } 31 | 32 | private void Run(Q q) 33 | { 34 | if (bw.IsBusy) return; 35 | bw.RunWorkerAsync(q); 36 | if (q.UseTItoken) WaitUI.ShowDialogIfNeeded(this); 37 | } 38 | 39 | private void RunQbtn(Button btn) 40 | { 41 | int i = QbtnIndex(btn); 42 | Q q = Qs[i - 1]; 43 | if (q.Name == "") 44 | { 45 | MessageBox.Show(MUI.GetText("Common.AskToNameQbtn"), 46 | MUI.GetText("Common.Error_title"), 47 | MessageBoxButtons.OK, MessageBoxIcon.Error); 48 | } 49 | else 50 | { 51 | Run(q); 52 | } 53 | } 54 | 55 | private void EditQbtn(Button btn) 56 | { 57 | btn.Focus(); 58 | Color oriBgColor = btn.BackColor; 59 | Color oriForeColor = btn.ForeColor; 60 | btn.BackColor = SystemColors.Highlight; 61 | btn.ForeColor = SystemColors.HighlightText; 62 | 63 | int i = QbtnIndex(btn); 64 | frmQEditor UI = QEditorUI; 65 | UI.Left = this.Right - UI.Width; 66 | UI.Top = this.Bottom - UI.Height; 67 | UI.ClearAll(); 68 | UI.ReadFrom(Qs[i - 1]); 69 | if (UI.ShowDialog() == DialogResult.OK) 70 | { 71 | UI.WriteTo(ref Qs[i - 1]); 72 | Program.SaveSettings(); 73 | } 74 | RefreshQbtn(); 75 | 76 | btn.BackColor = oriBgColor; 77 | btn.ForeColor = oriForeColor; 78 | if (!Program.beClassic) btn.UseVisualStyleBackColor = true; 79 | } 80 | 81 | private void RefreshQbtn() 82 | { 83 | btnQ1.Text = "(1) " + Qs[0].Name; 84 | btnQ2.Text = "(2) " + Qs[1].Name; 85 | btnQ3.Text = "(3) " + Qs[2].Name; 86 | btnQ4.Text = "(4) " + Qs[3].Name; 87 | btnQ5.Text = "(5) " + Qs[4].Name; 88 | btnQ6.Text = "(6) " + Qs[5].Name; 89 | btnQ7.Text = "(7) " + Qs[6].Name; 90 | btnQ8.Text = "(8) " + Qs[7].Name; 91 | btnQ9.Text = "(9) " + Qs[8].Name; 92 | } 93 | 94 | private int QbtnIndex(Button btn) 95 | { 96 | if (btn == btnQ1) return 1; 97 | if (btn == btnQ2) return 2; 98 | if (btn == btnQ3) return 3; 99 | if (btn == btnQ4) return 4; 100 | if (btn == btnQ5) return 5; 101 | if (btn == btnQ6) return 6; 102 | if (btn == btnQ7) return 7; 103 | if (btn == btnQ8) return 8; 104 | if (btn == btnQ9) return 9; 105 | return 0; 106 | } 107 | 108 | #region Smarter UI Tweak 109 | 110 | private void rdo_AutoCorrect(object sender, EventArgs e) 111 | { 112 | // Make the program usable even if keyboard only 113 | rdoCustomWorkingDir.TabStop = true; 114 | rdoAutoWorkingDir.TabStop = true; 115 | rdoCustomWorkingDir.TabIndex = 1; 116 | rdoAutoWorkingDir.TabIndex = 0; 117 | } 118 | 119 | private void txtCustomWorkingDir_Click(object sender, EventArgs e) 120 | { 121 | rdoCustomWorkingDir.Checked = true; 122 | } 123 | 124 | #endregion 125 | 126 | private void bw_DoWork(object sender, DoWorkEventArgs e) 127 | { 128 | Q q = (Q)e.Argument; 129 | if (q.UseTItoken) 130 | { 131 | if (Program.StartTiService()) 132 | { 133 | SuperCore.RunWithTokenOf("winlogon.exe", true, 134 | Application.ExecutablePath, 135 | (Program.DebugMode ? "/Debug" : "") + 136 | " /SendLogTo:" + hWnd.ToInt64() + 137 | " /WithTokenOf:TrustedInstaller.exe" + 138 | " /ChangeToActiveSessionID" + 139 | " /Dir:\"" + q.WorkingDir + "\"" + 140 | " /Run:\"" + q.ExeToRun + "\" " + q.Arguments); 141 | } 142 | } 143 | else 144 | { 145 | SuperCore.RunWithTokenOf("winlogon.exe", true, 146 | q.ExeToRun, q.Arguments, q.WorkingDir); 147 | } 148 | } 149 | 150 | private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 151 | { 152 | WaitUI.Hide(); 153 | Program.ComplainAndLog(); 154 | SuperCore.ClearLog(); 155 | } 156 | 157 | public frmMain() 158 | { 159 | InitializeComponent(); 160 | this.Text = Program.Title; 161 | hWnd = this.Handle; 162 | Win32.SetFormIcon(this.Handle, Application.ExecutablePath); 163 | MUI.MainUI = this; 164 | MUI.QEditorUI = QEditorUI; 165 | MUI.ConfigUI = ConfigUI; 166 | MUI.RefreshFrmLang(); 167 | } 168 | 169 | private void frmMain_Load(object sender, EventArgs e) 170 | { 171 | this.CenterToScreen(); 172 | RefreshQbtn(); 173 | foreach (TextBox t in new TextBox[] { 174 | txtArguments, txtCustomWorkingDir, txtProgramPath }) 175 | { 176 | t.BorderStyle = Program.beClassic ? 177 | BorderStyle.FixedSingle : BorderStyle.Fixed3D; 178 | } 179 | } 180 | 181 | protected override void WndProc(ref Message m) 182 | { 183 | string msg = Win32._GetMessage(m); 184 | if (msg != null) 185 | { 186 | MessageBox.Show(msg, MUI.GetText("Common.Error_title"), 187 | MessageBoxButtons.OK, MessageBoxIcon.Error); 188 | } 189 | base.WndProc(ref m); 190 | } 191 | 192 | private void btnQ_Click(object sender, EventArgs e) 193 | { 194 | RunQbtn((Button)sender); 195 | } 196 | 197 | private void btnQ_MouseUp(object sender, MouseEventArgs e) 198 | { 199 | if (e.Button == MouseButtons.Right) EditQbtn((Button)sender); 200 | } 201 | 202 | private void btnQ_KeyUp(object sender, KeyEventArgs e) 203 | { 204 | if (e.KeyCode == Keys.Apps) EditQbtn((Button)sender); 205 | } 206 | 207 | private void lnkResetQ_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) 208 | { 209 | if (MessageBox.Show(MUI.GetText("Common.AskToResetQbtn"), 210 | MUI.GetText("Common.SureBo_title"), 211 | MessageBoxButtons.YesNo, MessageBoxIcon.Question, 212 | MessageBoxDefaultButton.Button2 ) == DialogResult.Yes) 213 | { 214 | Program.LoadSettings(Properties.Resources.defaultSettings); 215 | RefreshQbtn(); 216 | } 217 | } 218 | 219 | private void btnSelectExeAndRun_Click(object sender, EventArgs e) 220 | { 221 | OpenFileDialog ofd = new OpenFileDialog(); 222 | ofd.FileName = ""; 223 | ofd.Multiselect = false; 224 | ofd.Filter = MUI.GetText("Common.FileType_EXE") + "|*.exe;*.bat;*.cmd"; 225 | if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) 226 | { 227 | Q q = new Q(); 228 | q.UseTItoken = chkTI_quick.Checked; 229 | q.ExeToRun = ofd.FileName; 230 | Run(q); 231 | } 232 | } 233 | 234 | private void btnSelectExe_Click(object sender, EventArgs e) 235 | { 236 | OpenFileDialog ofd = new OpenFileDialog(); 237 | ofd.FileName = ""; 238 | ofd.Multiselect = false; 239 | ofd.Filter = MUI.GetText("Common.FileType_EXE") + "|*.exe;*.bat;*.cmd"; 240 | if (ofd.ShowDialog() == DialogResult.OK) 241 | { 242 | txtProgramPath.Text = ofd.FileName; 243 | } 244 | } 245 | 246 | private void btnAppendArgs_Click(object sender, EventArgs e) 247 | { 248 | OpenFileDialog ofd = new OpenFileDialog(); 249 | ofd.FileName = ""; 250 | ofd.Multiselect = true; 251 | if (ofd.ShowDialog() == DialogResult.OK) 252 | { 253 | foreach (string filePath in ofd.FileNames) 254 | { 255 | txtArguments.AppendText("\"" + filePath + "\" "); 256 | } 257 | } 258 | } 259 | 260 | private void btnSelectWorkingDir_Click(object sender, EventArgs e) 261 | { 262 | FolderBrowserDialog fbd = new FolderBrowserDialog(); 263 | fbd.SelectedPath = txtCustomWorkingDir.Text; 264 | fbd.ShowNewFolderButton = true; 265 | if (fbd.ShowDialog() == DialogResult.OK) 266 | { 267 | txtCustomWorkingDir.Text = fbd.SelectedPath; 268 | rdoCustomWorkingDir.Checked = true; 269 | } 270 | } 271 | 272 | private void btnRunAsSystem_Click(object sender, EventArgs e) 273 | { 274 | Q q = new Q(); 275 | q.UseTItoken = chkTI.Checked; 276 | q.ExeToRun = txtProgramPath.Text; 277 | q.Arguments = txtArguments.Text; 278 | q.WorkingDir = rdoCustomWorkingDir.Checked ? txtCustomWorkingDir.Text : ""; 279 | Run(q); 280 | } 281 | 282 | private void btnMenu_Click(object sender, EventArgs e) 283 | { 284 | mnuQEdit.Show(btnQEditMenu, new Point(0, 0), ToolStripDropDownDirection.AboveRight); 285 | } 286 | 287 | private void cmiCopy_Click(object sender, EventArgs e) 288 | { 289 | Q q = Program.CopiedQ; 290 | q.Name = ""; 291 | q.Arguments = txtArguments.Text; 292 | q.ExeToRun = txtProgramPath.Text; 293 | q.WorkingDir = rdoCustomWorkingDir.Checked ? txtCustomWorkingDir.Text : ""; 294 | q.UseTItoken = chkTI.Checked; 295 | } 296 | 297 | private void cmiCopyAsText_Click(object sender, EventArgs e) 298 | { 299 | Q q = new Q(); 300 | q.Name = ""; 301 | q.Arguments = txtArguments.Text; 302 | q.ExeToRun = txtProgramPath.Text; 303 | q.WorkingDir = rdoCustomWorkingDir.Checked ? txtCustomWorkingDir.Text : ""; 304 | q.UseTItoken = chkTI.Checked; 305 | Clipboard.SetText(q.ToString()); 306 | } 307 | 308 | private void cmiPaste_Click(object sender, EventArgs e) 309 | { 310 | Q q = Program.CopiedQ; 311 | txtArguments.Text = q.Arguments; 312 | txtProgramPath.Text = q.ExeToRun; 313 | if (q.WorkingDir == "") 314 | { 315 | rdoAutoWorkingDir.Checked = true; 316 | } 317 | else 318 | { 319 | rdoCustomWorkingDir.Checked = true; 320 | txtCustomWorkingDir.Text = q.WorkingDir; 321 | } 322 | chkTI.Checked = q.UseTItoken; 323 | } 324 | 325 | private void cmiClearAll_Click(object sender, EventArgs e) 326 | { 327 | ClearAll(); 328 | } 329 | 330 | private void btnConfig_Click(object sender, EventArgs e) 331 | { 332 | ConfigUI.ShowDialog(); 333 | } 334 | 335 | private void cmiCreateLnk_Click(object sender, EventArgs e) 336 | { 337 | Q q = new Q(); 338 | q.Arguments = txtArguments.Text; 339 | q.ExeToRun = txtProgramPath.Text; 340 | q.WorkingDir = rdoCustomWorkingDir.Checked ? 341 | txtCustomWorkingDir.Text : ""; 342 | q.UseTItoken = chkTI.Checked; 343 | Program.OfferCreateLnk(q); 344 | } 345 | 346 | 347 | } 348 | } 349 | -------------------------------------------------------------------------------- /src/frmConfig.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SuperCMD 2 | { 3 | partial class frmConfig 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.lblTitle = new System.Windows.Forms.Label(); 32 | this.btnCancel = new W31Button(); 33 | this.btnOK = new W31Button(); 34 | this.lblWarning = new System.Windows.Forms.Label(); 35 | this.lnkHomepage = new System.Windows.Forms.LinkLabel(); 36 | this.chkRunAsSYSTEM = new System.Windows.Forms.CheckBox(); 37 | this.chkRunAsSYSTEM_TI = new System.Windows.Forms.CheckBox(); 38 | this.grpCMIntegration = new System.Windows.Forms.GroupBox(); 39 | this.grpMisc = new System.Windows.Forms.GroupBox(); 40 | this.chkBeClassic = new System.Windows.Forms.CheckBox(); 41 | this.chkBeDPIaware = new System.Windows.Forms.CheckBox(); 42 | this.grpLang = new System.Windows.Forms.GroupBox(); 43 | this.cmbLang = new System.Windows.Forms.ComboBox(); 44 | this.grpCMIntegration.SuspendLayout(); 45 | this.grpMisc.SuspendLayout(); 46 | this.grpLang.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // lblTitle 50 | // 51 | this.lblTitle.AutoSize = true; 52 | this.lblTitle.Font = new System.Drawing.Font("Segoe UI", 12F); 53 | this.lblTitle.Location = new System.Drawing.Point(12, 12); 54 | this.lblTitle.Margin = new System.Windows.Forms.Padding(3); 55 | this.lblTitle.Name = "lblTitle"; 56 | this.lblTitle.Size = new System.Drawing.Size(151, 21); 57 | this.lblTitle.TabIndex = 0; 58 | this.lblTitle.Text = "SuperCMD title here"; 59 | this.lblTitle.DoubleClick += new System.EventHandler(this.lblTitle_DoubleClick); 60 | this.lblTitle.MouseDown += new System.Windows.Forms.MouseEventHandler(this.frm_MouseDown); 61 | this.lblTitle.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frm_MouseMove); 62 | this.lblTitle.MouseUp += new System.Windows.Forms.MouseEventHandler(this.frm_MouseUp); 63 | // 64 | // btnCancel 65 | // 66 | this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 67 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 68 | this.btnCancel.Location = new System.Drawing.Point(386, 251); 69 | this.btnCancel.Name = "btnCancel"; 70 | this.btnCancel.Size = new System.Drawing.Size(80, 25); 71 | this.btnCancel.TabIndex = 5; 72 | this.btnCancel.Text = "Cancel"; 73 | this.btnCancel.UseVisualStyleBackColor = true; 74 | this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); 75 | // 76 | // btnOK 77 | // 78 | this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 79 | this.btnOK.Location = new System.Drawing.Point(300, 251); 80 | this.btnOK.Name = "btnOK"; 81 | this.btnOK.Size = new System.Drawing.Size(80, 25); 82 | this.btnOK.TabIndex = 4; 83 | this.btnOK.Text = "OK"; 84 | this.btnOK.UseVisualStyleBackColor = true; 85 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click); 86 | // 87 | // lblWarning 88 | // 89 | this.lblWarning.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 90 | this.lblWarning.AutoSize = true; 91 | this.lblWarning.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold); 92 | this.lblWarning.ForeColor = System.Drawing.Color.Red; 93 | this.lblWarning.Location = new System.Drawing.Point(9, 241); 94 | this.lblWarning.Name = "lblWarning"; 95 | this.lblWarning.Size = new System.Drawing.Size(265, 30); 96 | this.lblWarning.TabIndex = 4; 97 | this.lblWarning.Text = "This program is intended for personal use only.\r\nDon\'t use it for malicious purpo" + 98 | "se!"; 99 | this.lblWarning.TextAlign = System.Drawing.ContentAlignment.BottomLeft; 100 | // 101 | // lnkHomepage 102 | // 103 | this.lnkHomepage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 104 | this.lnkHomepage.AutoSize = true; 105 | this.lnkHomepage.Location = new System.Drawing.Point(298, 17); 106 | this.lnkHomepage.Name = "lnkHomepage"; 107 | this.lnkHomepage.Size = new System.Drawing.Size(168, 15); 108 | this.lnkHomepage.TabIndex = 0; 109 | this.lnkHomepage.TabStop = true; 110 | this.lnkHomepage.Text = "raymai97.github.io/SuperCMD"; 111 | this.lnkHomepage.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.lnkHomepage_LinkClicked); 112 | // 113 | // chkRunAsSYSTEM 114 | // 115 | this.chkRunAsSYSTEM.AutoSize = true; 116 | this.chkRunAsSYSTEM.Location = new System.Drawing.Point(17, 31); 117 | this.chkRunAsSYSTEM.Name = "chkRunAsSYSTEM"; 118 | this.chkRunAsSYSTEM.Size = new System.Drawing.Size(107, 19); 119 | this.chkRunAsSYSTEM.TabIndex = 0; 120 | this.chkRunAsSYSTEM.Text = "Run as SYSTEM"; 121 | this.chkRunAsSYSTEM.UseVisualStyleBackColor = true; 122 | // 123 | // chkRunAsSYSTEM_TI 124 | // 125 | this.chkRunAsSYSTEM_TI.AutoSize = true; 126 | this.chkRunAsSYSTEM_TI.Location = new System.Drawing.Point(17, 56); 127 | this.chkRunAsSYSTEM_TI.Name = "chkRunAsSYSTEM_TI"; 128 | this.chkRunAsSYSTEM_TI.Size = new System.Drawing.Size(128, 19); 129 | this.chkRunAsSYSTEM_TI.TabIndex = 1; 130 | this.chkRunAsSYSTEM_TI.Text = "Run as SYSTEM (TI)"; 131 | this.chkRunAsSYSTEM_TI.UseVisualStyleBackColor = true; 132 | // 133 | // grpCMIntegration 134 | // 135 | this.grpCMIntegration.Controls.Add(this.chkRunAsSYSTEM); 136 | this.grpCMIntegration.Controls.Add(this.chkRunAsSYSTEM_TI); 137 | this.grpCMIntegration.Location = new System.Drawing.Point(16, 59); 138 | this.grpCMIntegration.Name = "grpCMIntegration"; 139 | this.grpCMIntegration.Size = new System.Drawing.Size(220, 100); 140 | this.grpCMIntegration.TabIndex = 1; 141 | this.grpCMIntegration.TabStop = false; 142 | this.grpCMIntegration.Text = "Context Menu Integration"; 143 | // 144 | // grpMisc 145 | // 146 | this.grpMisc.Controls.Add(this.chkBeClassic); 147 | this.grpMisc.Controls.Add(this.chkBeDPIaware); 148 | this.grpMisc.Location = new System.Drawing.Point(242, 59); 149 | this.grpMisc.Name = "grpMisc"; 150 | this.grpMisc.Size = new System.Drawing.Size(220, 100); 151 | this.grpMisc.TabIndex = 2; 152 | this.grpMisc.TabStop = false; 153 | this.grpMisc.Text = "Misc"; 154 | // 155 | // chkBeClassic 156 | // 157 | this.chkBeClassic.AutoSize = true; 158 | this.chkBeClassic.Location = new System.Drawing.Point(16, 56); 159 | this.chkBeClassic.Name = "chkBeClassic"; 160 | this.chkBeClassic.Size = new System.Drawing.Size(98, 19); 161 | this.chkBeClassic.TabIndex = 1; 162 | this.chkBeClassic.Text = "Use Win3.1 UI"; 163 | this.chkBeClassic.UseVisualStyleBackColor = true; 164 | // 165 | // chkBeDPIaware 166 | // 167 | this.chkBeDPIaware.AutoSize = true; 168 | this.chkBeDPIaware.Location = new System.Drawing.Point(16, 31); 169 | this.chkBeDPIaware.Name = "chkBeDPIaware"; 170 | this.chkBeDPIaware.Size = new System.Drawing.Size(94, 19); 171 | this.chkBeDPIaware.TabIndex = 0; 172 | this.chkBeDPIaware.Text = "Be DPI aware"; 173 | this.chkBeDPIaware.UseVisualStyleBackColor = true; 174 | // 175 | // grpLang 176 | // 177 | this.grpLang.Controls.Add(this.cmbLang); 178 | this.grpLang.Location = new System.Drawing.Point(129, 165); 179 | this.grpLang.Name = "grpLang"; 180 | this.grpLang.Size = new System.Drawing.Size(220, 54); 181 | this.grpLang.TabIndex = 3; 182 | this.grpLang.TabStop = false; 183 | this.grpLang.Text = "Language"; 184 | // 185 | // cmbLang 186 | // 187 | this.cmbLang.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 188 | | System.Windows.Forms.AnchorStyles.Right))); 189 | this.cmbLang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 190 | this.cmbLang.FlatStyle = System.Windows.Forms.FlatStyle.System; 191 | this.cmbLang.Font = new System.Drawing.Font("Microsoft YaHei", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 192 | this.cmbLang.FormattingEnabled = true; 193 | this.cmbLang.Location = new System.Drawing.Point(6, 22); 194 | this.cmbLang.Name = "cmbLang"; 195 | this.cmbLang.Size = new System.Drawing.Size(208, 25); 196 | this.cmbLang.TabIndex = 0; 197 | this.cmbLang.SelectedIndexChanged += new System.EventHandler(this.cmbLang_SelectedIndexChanged); 198 | // 199 | // frmConfig 200 | // 201 | this.AcceptButton = this.btnOK; 202 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 203 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 204 | this.BackColor = System.Drawing.SystemColors.Window; 205 | this.CancelButton = this.btnCancel; 206 | this.ClientSize = new System.Drawing.Size(478, 288); 207 | this.ControlBox = false; 208 | this.Controls.Add(this.grpLang); 209 | this.Controls.Add(this.grpMisc); 210 | this.Controls.Add(this.grpCMIntegration); 211 | this.Controls.Add(this.lnkHomepage); 212 | this.Controls.Add(this.lblWarning); 213 | this.Controls.Add(this.btnOK); 214 | this.Controls.Add(this.btnCancel); 215 | this.Controls.Add(this.lblTitle); 216 | this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 217 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 218 | this.MaximizeBox = false; 219 | this.MinimizeBox = false; 220 | this.Name = "frmConfig"; 221 | this.ShowInTaskbar = false; 222 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 223 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmConfig_FormClosing); 224 | this.Load += new System.EventHandler(this.frmConfig_Load); 225 | this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.frm_MouseDown); 226 | this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.frm_MouseMove); 227 | this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.frm_MouseUp); 228 | this.grpCMIntegration.ResumeLayout(false); 229 | this.grpCMIntegration.PerformLayout(); 230 | this.grpMisc.ResumeLayout(false); 231 | this.grpMisc.PerformLayout(); 232 | this.grpLang.ResumeLayout(false); 233 | this.ResumeLayout(false); 234 | this.PerformLayout(); 235 | 236 | } 237 | 238 | #endregion 239 | 240 | private System.Windows.Forms.Label lblTitle; 241 | private W31Button btnCancel; 242 | private W31Button btnOK; 243 | private System.Windows.Forms.Label lblWarning; 244 | private System.Windows.Forms.LinkLabel lnkHomepage; 245 | private System.Windows.Forms.CheckBox chkRunAsSYSTEM; 246 | private System.Windows.Forms.CheckBox chkRunAsSYSTEM_TI; 247 | private System.Windows.Forms.GroupBox grpCMIntegration; 248 | private System.Windows.Forms.GroupBox grpMisc; 249 | private System.Windows.Forms.CheckBox chkBeDPIaware; 250 | private System.Windows.Forms.CheckBox chkBeClassic; 251 | private System.Windows.Forms.GroupBox grpLang; 252 | private System.Windows.Forms.ComboBox cmbLang; 253 | 254 | } 255 | } -------------------------------------------------------------------------------- /src/ShellLink.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Runtime.InteropServices; 5 | using System.Diagnostics; 6 | using System.Windows.Forms; 7 | 8 | namespace SuperCMD 9 | { 10 | class ShellLink 11 | { 12 | #region Win32 native 13 | 14 | const int INFOTIPSIZE = 1024; 15 | const int MAX_PATH = 260; 16 | // GUID 17 | const string IID_IPersist = "0000010C-0000-0000-C000-000000000046"; 18 | const string IID_IPersistFile = "0000010B-0000-0000-C000-000000000046"; 19 | const string IID_IShellLinkA = "000214EE-0000-0000-C000-000000000046"; 20 | const string IID_IShellLinkW = "000214F9-0000-0000-C000-000000000046"; 21 | const string CLSID_ShellLink = "00021401-0000-0000-C000-000000000046"; 22 | // IShellLink.Resolve flags 23 | const uint SLR_NO_UI = 0x1; 24 | const uint SLR_ANY_MATCH = 0x2; 25 | const uint SLR_UPDATE = 0x4; 26 | const uint SLR_NOUPDATE = 0x8; 27 | const uint SLR_NOSEARCH = 0x10; 28 | const uint SLR_NOTRACK = 0x20; 29 | const uint SLR_NOLINKINFO = 0x40; 30 | const uint SLR_INVOKE_MSI = 0x80; 31 | // IShellLink.GetPath flags 32 | const uint SLGP_SHORTPATH = 0x1; 33 | const uint SLGP_UNCPRIORITY = 0x2; 34 | const uint SLGP_RAWPATH = 0x4; 35 | 36 | [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid(IID_IPersist)] 37 | public interface IPersist 38 | { 39 | [PreserveSig] 40 | void GetClassID(out Guid pClassID); 41 | } 42 | 43 | [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid(IID_IPersistFile)] 44 | public interface IPersistFile : IPersist 45 | { 46 | new void GetClassID(out Guid pClassID); 47 | [PreserveSig] 48 | int IsDirty(); 49 | 50 | [PreserveSig] 51 | void Load([In, MarshalAs(UnmanagedType.LPWStr)] 52 | string pszFileName, uint dwMode); 53 | 54 | [PreserveSig] 55 | int Save([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName, 56 | [In, MarshalAs(UnmanagedType.Bool)] bool fRemember); 57 | 58 | [PreserveSig] 59 | void SaveCompleted([In, MarshalAs(UnmanagedType.LPWStr)] string pszFileName); 60 | 61 | [PreserveSig] 62 | void GetCurFile([In, MarshalAs(UnmanagedType.LPWStr)] string ppszFileName); 63 | } 64 | 65 | [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid(IID_IShellLinkA)] 66 | interface IShellLinkA 67 | { 68 | /// Retrieves the path and file name of a Shell link object 69 | void GetPath([Out(), MarshalAs(UnmanagedType.LPStr)] StringBuilder pszFile, int cchMaxPath, out WIN32_FIND_DATA pfd, uint SLGPflags); 70 | /// Retrieves the list of item identifiers for a Shell link object 71 | void GetIDList(out IntPtr ppidl); 72 | /// Sets the pointer to an item identifier list (PIDL) for a Shell link object 73 | void SetIDList(IntPtr pidl); 74 | /// Retrieves the description string for a Shell link object 75 | void GetDescription([Out(), MarshalAs(UnmanagedType.LPStr)] StringBuilder pszName, int cchMaxName); 76 | /// Sets the description for a Shell link object. The description can be any application-defined string 77 | void SetDescription([MarshalAs(UnmanagedType.LPStr)] string pszName); 78 | /// Retrieves the name of the working directory for a Shell link object 79 | void GetWorkingDirectory([Out(), MarshalAs(UnmanagedType.LPStr)] StringBuilder pszDir, int cchMaxPath); 80 | /// Sets the name of the working directory for a Shell link object 81 | void SetWorkingDirectory([MarshalAs(UnmanagedType.LPStr)] string pszDir); 82 | /// Retrieves the command-line arguments associated with a Shell link object 83 | void GetArguments([Out(), MarshalAs(UnmanagedType.LPStr)] StringBuilder pszArgs, int cchMaxPath); 84 | /// Sets the command-line arguments for a Shell link object 85 | void SetArguments([MarshalAs(UnmanagedType.LPStr)] string pszArgs); 86 | /// Retrieves the hot key for a Shell link object 87 | void GetHotkey(out short pwHotkey); 88 | /// Sets a hot key for a Shell link object 89 | void SetHotkey(short wHotkey); 90 | /// Retrieves the show command for a Shell link object 91 | void GetShowCmd(out int piShowCmd); 92 | /// Sets the show command for a Shell link object. The show command sets the initial show state of the window. 93 | void SetShowCmd(int iShowCmd); 94 | /// Retrieves the location (path and index) of the icon for a Shell link object 95 | void GetIconLocation([Out(), MarshalAs(UnmanagedType.LPStr)] StringBuilder pszIconPath 96 | , int cchIconPath, out int piIcon); 97 | /// Sets the location (path and index) of the icon for a Shell link object 98 | void SetIconLocation([MarshalAs(UnmanagedType.LPStr)] string pszIconPath, int iIcon); 99 | /// Sets the relative path to the Shell link object 100 | void SetRelativePath([MarshalAs(UnmanagedType.LPStr)] string pszPathRel, int dwReserved); 101 | /// Attempts to find the target of a Shell link, even if it has been moved or renamed 102 | void Resolve(IntPtr hwnd, uint SLRflags); 103 | /// Sets the path and file name of a Shell link object 104 | void SetPath([MarshalAs(UnmanagedType.LPStr)] string pszFile); 105 | } 106 | 107 | [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid(IID_IShellLinkW)] 108 | interface IShellLinkW 109 | { 110 | /// Retrieves the path and file name of a Shell link object 111 | void GetPath([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out WIN32_FIND_DATA pfd, uint SLGPflags); 112 | /// Retrieves the list of item identifiers for a Shell link object 113 | void GetIDList(out IntPtr ppidl); 114 | /// Sets the pointer to an item identifier list (PIDL) for a Shell link object. 115 | void SetIDList(IntPtr pidl); 116 | /// Retrieves the description string for a Shell link object 117 | void GetDescription([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName); 118 | /// Sets the description for a Shell link object. The description can be any application-defined string 119 | void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName); 120 | /// Retrieves the name of the working directory for a Shell link object 121 | void GetWorkingDirectory([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath); 122 | /// Sets the name of the working directory for a Shell link object 123 | void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir); 124 | /// Retrieves the command-line arguments associated with a Shell link object 125 | void GetArguments([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath); 126 | /// Sets the command-line arguments for a Shell link object 127 | void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs); 128 | /// Retrieves the hot key for a Shell link object 129 | void GetHotkey(out short pwHotkey); 130 | /// Sets a hot key for a Shell link object 131 | void SetHotkey(short wHotkey); 132 | /// Retrieves the show command for a Shell link object 133 | void GetShowCmd(out int piShowCmd); 134 | /// Sets the show command for a Shell link object. The show command sets the initial show state of the window. 135 | void SetShowCmd(int iShowCmd); 136 | /// Retrieves the location (path and index) of the icon for a Shell link object 137 | void GetIconLocation([Out(), MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath, out int piIcon); 138 | /// Sets the location (path and index) of the icon for a Shell link object 139 | void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon); 140 | /// Sets the relative path to the Shell link object 141 | void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved); 142 | /// Attempts to find the target of a Shell link, even if it has been moved or renamed 143 | void Resolve(IntPtr hwnd, uint SLRflags); 144 | /// Sets the path and file name of a Shell link object 145 | void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile); 146 | } 147 | 148 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] 149 | struct WIN32_FIND_DATA 150 | { 151 | public uint dwFileAttributes; 152 | public System.Runtime.InteropServices.ComTypes.FILETIME ftCreationTime; 153 | public System.Runtime.InteropServices.ComTypes.FILETIME ftLastAccessTime; 154 | public System.Runtime.InteropServices.ComTypes.FILETIME ftLastWriteTime; 155 | public uint nFileSizeHigh; 156 | public uint nFileSizeLow; 157 | public uint dwReserved0; 158 | public uint dwReserved1; 159 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] 160 | public string cFileName; 161 | [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 14)] 162 | public string cAlternateFileName; 163 | } 164 | 165 | #endregion 166 | 167 | bool Unicode = Environment.OSVersion.Version.Major >= 5 ? true : false; 168 | IShellLinkA _slA; 169 | IShellLinkW _slW; 170 | string lnkPath; 171 | 172 | public ShellLink(string lnkPath) 173 | { 174 | this.lnkPath = lnkPath; 175 | if (Unicode) 176 | { 177 | _slW = (IShellLinkW)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_ShellLink))); 178 | ((IPersistFile)(_slW)).Load(lnkPath, 0); 179 | } 180 | else 181 | { 182 | _slA = (IShellLinkA)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID_ShellLink))); 183 | ((IPersistFile)(_slA)).Load(lnkPath, 0); 184 | } 185 | } 186 | 187 | public ShellLink(string lnkPath, bool Unicode) 188 | : this(lnkPath) 189 | { 190 | this.Unicode = Unicode; 191 | } 192 | 193 | public string Arguments 194 | { 195 | get 196 | { 197 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 198 | if (Unicode) 199 | { 200 | _slW.GetArguments(sb, sb.Capacity); 201 | } 202 | else 203 | { 204 | _slA.GetArguments(sb, sb.Capacity); 205 | } 206 | return sb.ToString(); 207 | } 208 | set 209 | { 210 | if (Unicode) 211 | { 212 | _slW.SetArguments(value); 213 | } 214 | else 215 | { 216 | _slA.SetArguments(value); 217 | } 218 | } 219 | } 220 | 221 | public string Description 222 | { 223 | get 224 | { 225 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 226 | if (Unicode) 227 | { 228 | _slW.GetDescription(sb, sb.Capacity); 229 | } 230 | else 231 | { 232 | _slA.GetDescription(sb, sb.Capacity); 233 | } 234 | return sb.ToString(); 235 | } 236 | set 237 | { 238 | if (Unicode) 239 | { 240 | _slW.SetArguments(value); 241 | } 242 | else 243 | { 244 | _slA.SetArguments(value); 245 | } 246 | } 247 | } 248 | 249 | public string WorkingDir 250 | { 251 | get 252 | { 253 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 254 | if (Unicode) 255 | { 256 | _slW.GetWorkingDirectory(sb, sb.Capacity); 257 | } 258 | else 259 | { 260 | _slA.GetWorkingDirectory(sb, sb.Capacity); 261 | } 262 | return sb.ToString(); 263 | } 264 | set 265 | { 266 | if (Unicode) 267 | { 268 | _slW.SetWorkingDirectory(value); 269 | } 270 | else 271 | { 272 | _slA.SetWorkingDirectory(value); 273 | } 274 | } 275 | } 276 | 277 | // If Path returns an empty string, the shortcut is associated with 278 | // a PIDL instead, which can be retrieved with IShellLink.GetIDList(). 279 | public string Path 280 | { 281 | get 282 | { 283 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 284 | WIN32_FIND_DATA fd; 285 | if (Unicode) 286 | { 287 | _slW.GetPath(sb, sb.Capacity, out fd, SLGP_RAWPATH); 288 | } 289 | else 290 | { 291 | _slA.GetPath(sb, sb.Capacity, out fd, SLGP_RAWPATH); 292 | } 293 | return sb.ToString(); 294 | } 295 | set 296 | { 297 | _slW.SetPath(value); 298 | } 299 | } 300 | 301 | public string IconPath 302 | { 303 | get 304 | { 305 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 306 | int i; 307 | if (Unicode) 308 | { 309 | _slW.GetIconLocation(sb, sb.Capacity, out i); 310 | } 311 | else 312 | { 313 | _slA.GetIconLocation(sb, sb.Capacity, out i); 314 | } 315 | return sb.ToString(); 316 | } 317 | set 318 | { 319 | if (Unicode) 320 | { 321 | _slW.SetIconLocation(value, IconIndex); 322 | } 323 | else 324 | { 325 | _slA.SetIconLocation(value, IconIndex); 326 | } 327 | } 328 | } 329 | 330 | public int IconIndex 331 | { 332 | get 333 | { 334 | StringBuilder sb = new StringBuilder(INFOTIPSIZE); 335 | int i; 336 | if (Unicode) 337 | { 338 | _slW.GetIconLocation(sb, sb.Capacity, out i); 339 | } 340 | else 341 | { 342 | _slA.GetIconLocation(sb, sb.Capacity, out i); 343 | } 344 | return i; 345 | } 346 | set 347 | { 348 | if (Unicode) 349 | { 350 | _slW.SetIconLocation(IconPath, value); 351 | } 352 | else 353 | { 354 | _slA.SetIconLocation(IconPath, value); 355 | } 356 | } 357 | } 358 | 359 | public ProcessWindowStyle WindowStyle 360 | { 361 | get 362 | { 363 | int i; 364 | if (Unicode) 365 | { 366 | _slW.GetShowCmd(out i); 367 | } 368 | else 369 | { 370 | _slA.GetShowCmd(out i); 371 | } 372 | switch (i) 373 | { 374 | case 3: return ProcessWindowStyle.Maximized; 375 | case 2: return ProcessWindowStyle.Minimized; 376 | default: return ProcessWindowStyle.Normal; 377 | } 378 | } 379 | set 380 | { 381 | int i; 382 | switch (value) 383 | { 384 | case ProcessWindowStyle.Maximized: i = 3; break; 385 | case ProcessWindowStyle.Minimized: i = 2; break; 386 | case ProcessWindowStyle.Normal: i = 1; break; 387 | default: throw new ArgumentException("No such thing in Shortcut!"); 388 | } 389 | if (Unicode) 390 | { 391 | _slW.SetShowCmd(i); 392 | } 393 | else 394 | { 395 | _slA.SetShowCmd(i); 396 | } 397 | } 398 | } 399 | 400 | public int Save() 401 | { 402 | if (Unicode) 403 | { 404 | return ((IPersistFile)(_slW)).Save(lnkPath, true); 405 | } 406 | else 407 | { 408 | return ((IPersistFile)(_slA)).Save(lnkPath, true); 409 | } 410 | } 411 | 412 | } 413 | } 414 | -------------------------------------------------------------------------------- /src/Program.cs: -------------------------------------------------------------------------------- 1 | // SuperCMD v2.1 by MaiSoft (Raymai97) 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Windows.Forms; 6 | using System.IO; 7 | using System.Text; 8 | using System.Diagnostics; 9 | using System.Xml; 10 | using Microsoft.Win32; 11 | 12 | namespace SuperCMD 13 | { 14 | static class Program 15 | { 16 | public static string Title = "SuperCMD v2.1"; 17 | public static string Ver = "2.1"; 18 | public static string DirPath = Path.GetDirectoryName(Application.ExecutablePath); 19 | public static string SettingsPath = DirPath + "\\settings.xml"; 20 | public static string MUIDirPath = Program.DirPath + "\\MUI"; 21 | public static string LastComplain = ""; 22 | // Quick Launch buttons 23 | public static Q[] Qs = new Q[9]; 24 | // Clipboard feature 25 | public static Q CopiedQ = new Q(); 26 | // Windows 3.1 theme (easter egg) 27 | public static bool beClassic = true; 28 | // In case user prefer DPI virtualization 29 | public static bool beDPIaware = true; 30 | // Can be enabled via /Debug argument 31 | public static bool DebugMode = false; 32 | 33 | // Prevent someone messes with my EXE when it's running 34 | static FileStream myStream = 35 | new FileStream(Application.ExecutablePath, FileMode.Open, FileAccess.Read); 36 | // If not IntPtr.Zero, will not show Complain but will SendMessage() to it 37 | static IntPtr hLogTarget = IntPtr.Zero; 38 | 39 | /// 40 | /// The main entry point for the application. 41 | /// 42 | [STAThread] 43 | static void Main(string[] args) 44 | { 45 | // Load default settings if settings.xml can't be loaded 46 | try 47 | { 48 | LoadSettings(File.ReadAllText(Program.SettingsPath, Encoding.UTF8)); 49 | } 50 | catch (Exception) 51 | { 52 | LoadSettings(Properties.Resources.defaultSettings); 53 | } 54 | if (Environment.OSVersion.Version.Major < 6) 55 | { 56 | MessageBox.Show(MUI.GetText("Common.BadOS"), 57 | MUI.GetText("Common.Error_title"), 58 | MessageBoxButtons.OK, MessageBoxIcon.Error); 59 | Environment.Exit(1); 60 | } 61 | SuperCore.Complain += new SuperCore.ComplainHandler(SuperCore_Complain); 62 | ParseCmdLine(args); 63 | if (beDPIaware) Win32.SetProcessDPIAware(); 64 | Application.ApplicationExit += new EventHandler(OnApplicationExit); 65 | Application.EnableVisualStyles(); 66 | Application.SetCompatibleTextRenderingDefault(false); 67 | Application.Run(new frmMain()); 68 | } 69 | 70 | static void OnApplicationExit(object sender, EventArgs e) 71 | { 72 | SaveSettings(); 73 | } 74 | 75 | static void SuperCore_Complain(SuperCore.ComplainReason reason, string obj) 76 | { 77 | string msg = ""; 78 | switch (reason) 79 | { 80 | case SuperCore.ComplainReason.FileNotFound: 81 | msg = MUI.GetText("Common.FileNotFound"); break; 82 | case SuperCore.ComplainReason.FileNotExe: 83 | msg = MUI.GetText("Common.FileNotExe"); break; 84 | case SuperCore.ComplainReason.CantGetPID: 85 | msg = MUI.GetText("Common.CantGetPID"); break; 86 | case SuperCore.ComplainReason.APICallFailed: 87 | msg = MUI.GetText("Common.APICallFailed"); 88 | break; 89 | default: break; 90 | } 91 | msg = msg.Replace("%1", obj); 92 | LastComplain = msg; 93 | } 94 | 95 | public static bool LoadSettings(string xmlText) 96 | { 97 | try 98 | { 99 | XmlDocument xmlDoc = new XmlDocument(); 100 | xmlDoc.LoadXml(xmlText); 101 | XmlNode root = xmlDoc.SelectSingleNode("SuperCMD"); 102 | foreach (XmlAttribute attr in root.Attributes) 103 | { 104 | string attrName = attr.Name.ToLower(); 105 | if (attrName == "dpiaware") Program.beDPIaware = bool.Parse(attr.Value); 106 | if (attrName == "w31ui") Program.beClassic = bool.Parse(attr.Value); 107 | if (attrName == "lang") 108 | { 109 | if (!MUI.TrySetLangByName(attr.Value)) RevertFallbackLangFrom(attr.Value); 110 | } 111 | } 112 | XmlNodeList Q_nodes = root.SelectNodes("QLaunch/Q"); 113 | foreach (XmlNode Q_node in Q_nodes) 114 | { 115 | int i = int.Parse(Q_node.Attributes["index"].Value); 116 | if (i < 1 | i > 9) continue; 117 | Q q = new Q(); 118 | foreach (XmlAttribute attr in Q_node.Attributes) 119 | { 120 | string attrName = attr.Name.ToLower(); 121 | if (attrName == "name") q.Name = attr.Value; 122 | if (attrName == "exe") q.ExeToRun = attr.Value; 123 | if (attrName == "args") q.Arguments = attr.Value; 124 | if (attrName == "dir") q.WorkingDir = attr.Value; 125 | if (attrName == "ti") q.UseTItoken = bool.Parse(attr.Value); 126 | } 127 | Qs[i - 1] = q; 128 | } 129 | } 130 | catch (Exception) 131 | { 132 | return false; 133 | } 134 | return true; 135 | } 136 | 137 | public static bool SaveSettings() 138 | { 139 | try 140 | { 141 | using (StreamWriter writer = 142 | new StreamWriter(Program.SettingsPath, false, Encoding.UTF8)) 143 | { 144 | XmlDocument xmlDoc = new XmlDocument(); 145 | XmlElement root = xmlDoc.CreateElement("SuperCMD"); 146 | root.SetAttribute("DPIaware", Program.beDPIaware.ToString()); 147 | root.SetAttribute("W31UI", Program.beClassic.ToString()); 148 | root.SetAttribute("Lang", MUI.GetCurrentLangName()); 149 | root.SetAttribute("Ver", Program.Ver); 150 | XmlElement Q_nodes = xmlDoc.CreateElement("QLaunch"); 151 | for (int i = 0; i <= 8; i++) 152 | { 153 | Q q = Qs[i]; 154 | XmlElement Q_node = xmlDoc.CreateElement("Q"); 155 | Q_node.SetAttribute("index", (i + 1).ToString()); 156 | if (q.Name != "") Q_node.SetAttribute("name", q.Name); 157 | if (q.ExeToRun != "") Q_node.SetAttribute("exe", q.ExeToRun); 158 | if (q.Arguments != "") Q_node.SetAttribute("args", q.Arguments); 159 | if (q.WorkingDir != "") Q_node.SetAttribute("dir", q.WorkingDir); 160 | if (!q.UseTItoken) Q_node.SetAttribute("ti", "False"); 161 | Q_nodes.AppendChild(Q_node); 162 | } 163 | root.AppendChild(Q_nodes); 164 | xmlDoc.AppendChild(root); 165 | xmlDoc.Save(writer); 166 | } 167 | } 168 | catch (Exception ex) 169 | { 170 | MessageBox.Show( 171 | MUI.GetText("Common.SaveSettingsFailed") + "\n\n" + ex.Message, 172 | MUI.GetText("Common.Error_title"), 173 | MessageBoxButtons.OK, MessageBoxIcon.Error); 174 | return false; 175 | } 176 | return true; 177 | } 178 | 179 | static void ParseCmdLine(string[] args) 180 | { 181 | string ExeToRun = "", Arguments = "", WorkingDir = ""; 182 | string toRun = "", tokenProcessName = ""; 183 | int tokenPID = -1; 184 | bool metTI = false, metSilent = false, metShowWait = false; 185 | bool metChangeToActiveSessionID = false; 186 | // args[] can't process DirPath and ExeToRun containing '\' 187 | // and that will influence the other argument too :( 188 | // so I need to do it myself :/ 189 | string CmdLine = Environment.CommandLine; 190 | int iToRun = CmdLine.ToLower().IndexOf("/run:"); 191 | if (iToRun != -1) 192 | { 193 | toRun = CmdLine.Substring(iToRun + 5).Trim(); 194 | // Process toRun 195 | int iDQuote1, iDQuote2; 196 | iDQuote1 = toRun.IndexOf("\""); 197 | // If a pair of double quote is exist 198 | if (iDQuote1 != -1) 199 | { 200 | toRun = toRun.Substring(iDQuote1 + 1); 201 | iDQuote2 = toRun.IndexOf("\""); 202 | if (iDQuote2 != -1) 203 | { 204 | // before 2nd double quote is ExeToRun, after is Arguments 205 | ExeToRun = toRun.Substring(0, iDQuote2); 206 | Arguments = toRun.Substring(iDQuote2 + 1); 207 | } 208 | } 209 | else 210 | { 211 | // before 1st Space is ExeToRun, after is Arguments 212 | int firstSpace = toRun.IndexOf(" "); 213 | if (firstSpace == -1) { ExeToRun = toRun; } 214 | else 215 | { 216 | ExeToRun = toRun.Substring(0, firstSpace); 217 | Arguments = toRun.Substring(firstSpace + 1); 218 | } 219 | } 220 | } 221 | // Process all optional arguments before toRun, '/' as separator 222 | if (iToRun != -1) CmdLine = CmdLine.Substring(0, iToRun) + "/"; 223 | string cmdline = CmdLine.ToLower(); 224 | if (cmdline.Contains("/debug")) 225 | { 226 | DebugMode = true; Title += " Debug"; 227 | } 228 | // Only /debug affects GUI mode, others are only for command line usage 229 | // So if no '/run' then no need to go on 230 | if (iToRun == -1) return; 231 | if (cmdline.Contains("/ti")) metTI = true; 232 | if (cmdline.Contains("/silent")) metSilent = true; 233 | if (cmdline.Contains("/showwait")) metShowWait = true; 234 | if (cmdline.Contains("/changetoactivesessionid")) metChangeToActiveSessionID = true; 235 | 236 | string tmp; 237 | int iWithTokenOf, iWithTokenOfPID, iSendLogTo, iDir, iNextSlash; 238 | iWithTokenOf = cmdline.IndexOf("/withtokenof:"); 239 | if (iWithTokenOf != -1) 240 | { 241 | tmp = CmdLine.Substring(iWithTokenOf + 13); 242 | iNextSlash = tmp.IndexOf("/"); 243 | if (iNextSlash != -1) 244 | { 245 | tmp = tmp.Substring(0, iNextSlash); 246 | tokenProcessName = tmp.Replace("\"", "").Trim(); 247 | } 248 | } 249 | iWithTokenOfPID = cmdline.IndexOf("/withtokenofpid:"); 250 | if (iWithTokenOfPID != -1) 251 | { 252 | tmp = CmdLine.Substring(iWithTokenOfPID + 16); 253 | iNextSlash = tmp.IndexOf("/"); 254 | if (iNextSlash != -1) 255 | { 256 | tmp = tmp.Substring(0, iNextSlash); 257 | tmp = tmp.Replace("\"", "").Trim(); 258 | int.TryParse(tmp, out tokenPID); 259 | } 260 | } 261 | iSendLogTo = cmdline.IndexOf("/sendlogto:"); 262 | if (iSendLogTo != -1) 263 | { 264 | tmp = CmdLine.Substring(iSendLogTo + 11); 265 | iNextSlash = tmp.IndexOf("/"); 266 | if (iNextSlash != 1) 267 | { 268 | tmp = tmp.Substring(0, iNextSlash); 269 | tmp = tmp.Replace("\"", "").Trim(); 270 | long h; 271 | if (long.TryParse(tmp, out h)) hLogTarget = new IntPtr(h); 272 | } 273 | } 274 | iDir = cmdline.IndexOf("/dir:"); 275 | if (iDir != -1) 276 | { 277 | tmp = CmdLine.Substring(iDir + 5); 278 | iNextSlash = tmp.IndexOf("/"); 279 | if (iNextSlash != -1) 280 | { 281 | tmp = tmp.Substring(0, iNextSlash); 282 | WorkingDir = tmp.Replace("\"", "").Trim(); 283 | } 284 | } 285 | // Run... 286 | SuperCore.ForceTokenUseActiveSessionID = metChangeToActiveSessionID; 287 | if (metTI) 288 | { 289 | frmWait WaitUI = new frmWait(); 290 | if (metShowWait) WaitUI.ShowIfNeeded(); 291 | if (StartTiService()) 292 | { 293 | SuperCore.RunWithTokenOf("winlogon.exe", true, 294 | Application.ExecutablePath, 295 | "/WithTokenOf:TrustedInstaller.exe" + 296 | " /ForceUseActiveSessionID" + 297 | (metSilent ? " /Silent" : "") + 298 | (DebugMode ? " /Debug" : "") + 299 | " /Dir:\"" + WorkingDir + "\" " + 300 | " /Run:\"" + ExeToRun + "\" " + Arguments); 301 | } 302 | WaitUI.Hide(); 303 | } 304 | else 305 | { 306 | if (tokenProcessName != "") 307 | { 308 | SuperCore.RunWithTokenOf(tokenProcessName, false, 309 | ExeToRun, Arguments, WorkingDir); 310 | } 311 | else if (tokenPID > 0) 312 | { 313 | SuperCore.RunWithTokenOf(tokenPID, ExeToRun, Arguments, WorkingDir); 314 | } 315 | else 316 | { 317 | SuperCore.RunWithTokenOf("winlogon.exe", true, 318 | ExeToRun, Arguments, WorkingDir); 319 | } 320 | } 321 | ComplainAndLog(); 322 | Environment.Exit((LastComplain != "") ? 1 : 0); 323 | } 324 | 325 | public static void RevertFallbackLangFrom(string BadLangName) 326 | { 327 | MessageBox.Show( 328 | "Can't find language XML for '" + BadLangName + "'.\n" + 329 | "Reverting back to fallback language (English).", 330 | "Missing Lang XML", MessageBoxButtons.OK, MessageBoxIcon.Information); 331 | MUI.TrySetLangByIndex(0); 332 | } 333 | 334 | public static bool StartTiService() 335 | { 336 | try 337 | { 338 | Win32.TryStartService("TrustedInstaller"); 339 | return true; 340 | } 341 | catch (Exception) 342 | { 343 | LastComplain = MUI.GetText("Common.CantStartTI") + 344 | "\n\n" + Win32.WinAPILastErrMsg(); 345 | return false; 346 | } 347 | } 348 | 349 | public static void OfferCreateLnk(Q q) 350 | { 351 | SaveFileDialog sfd = new SaveFileDialog(); 352 | sfd.FileName = q.Name; 353 | sfd.Filter = MUI.GetText("Common.FileType_LNK") + "|*.lnk"; 354 | sfd.OverwritePrompt = true; 355 | if (sfd.ShowDialog() == DialogResult.OK) 356 | { 357 | string args = "/ShowWait "; 358 | args += (q.UseTItoken ? "/TI " : ""); 359 | args += (q.WorkingDir != "") ? 360 | "/Dir:\"" + q.WorkingDir + "\" " : ""; 361 | args += "/Run:\"" + q.ExeToRun + "\" " + q.Arguments; 362 | ShellLink lnk = new ShellLink(sfd.FileName); 363 | lnk.Path = Application.ExecutablePath; 364 | lnk.Arguments = args; 365 | lnk.IconPath = q.ExeToRun; 366 | int err = lnk.Save(); 367 | if (err == 0) 368 | { 369 | MessageBox.Show(MUI.GetText("Common.CreateLnkOK"), 370 | MUI.GetText("Common.OK_title"), 371 | MessageBoxButtons.OK, MessageBoxIcon.Information); 372 | } 373 | else 374 | { 375 | MessageBox.Show(MUI.GetText("Common.CreateLnkFailed") + 376 | "\n\n" + Win32.WinAPILastErrMsg(err), 377 | MUI.GetText("Common.Error_title"), 378 | MessageBoxButtons.OK, MessageBoxIcon.Error); 379 | } 380 | } 381 | } 382 | 383 | public static void OfferToggleDebug() 384 | { 385 | if (Program.DebugMode) 386 | { 387 | if (MessageBox.Show("Exit debug mode?", "SuperCMD Debug", 388 | MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 389 | { 390 | Process.Start(Application.ExecutablePath); 391 | Application.Exit(); 392 | } 393 | } 394 | else 395 | { 396 | if (MessageBox.Show("Enter debug mode?", "SuperCMD Debug", 397 | MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 398 | { 399 | Process.Start(Application.ExecutablePath, "/debug"); 400 | Application.Exit(); 401 | } 402 | } 403 | } 404 | 405 | public static void ComplainAndLog() 406 | { 407 | if (DebugMode) 408 | { 409 | MessageBox.Show(SuperCore.Log, "SuperCMD Log", 410 | MessageBoxButtons.OK, (LastComplain != "") ? 411 | MessageBoxIcon.Error : MessageBoxIcon.Information); 412 | } 413 | else if (LastComplain != "") 414 | { 415 | if (hLogTarget != IntPtr.Zero) 416 | { 417 | Win32._SendMessage(LastComplain, hLogTarget); 418 | } 419 | else 420 | { 421 | MessageBox.Show(LastComplain, MUI.GetText("Common.Error_title"), 422 | MessageBoxButtons.OK, MessageBoxIcon.Error); 423 | } 424 | LastComplain = ""; 425 | } 426 | } 427 | 428 | public static class ContextMenuIntegration 429 | { 430 | public static bool RunAsSYSTEM 431 | { 432 | get 433 | { 434 | foreach (string ext in new string[] {"exefile", "batfile", "cmdfile"}) 435 | { 436 | string KeyPath = "Software\\Classes\\" + ext + "\\shell\\runasSYSTEM"; 437 | if (Registry.CurrentUser.OpenSubKey(KeyPath) == null) return false; 438 | } 439 | return true; 440 | } 441 | set 442 | { 443 | foreach (string ext in new string[] { "exefile", "batfile", "cmdfile" }) 444 | { 445 | string KeyPath = "Software\\Classes\\" + ext + "\\shell\\runasSYSTEM"; 446 | RegistryKey Key; 447 | if (value) 448 | { 449 | Key = Registry.CurrentUser.CreateSubKey(KeyPath); 450 | Key.SetValue("", MUI.GetText("ContextMenuIntegration.RunAsSYSTEM")); 451 | Key.SetValue("MultiSelectModel", "Single"); 452 | Key.SetValue("Icon", Application.ExecutablePath); 453 | Key = Key.CreateSubKey("command"); 454 | Key.SetValue("", "\"" + Application.ExecutablePath + "\"" 455 | + " /ShowWait /Run:\"%1\" %*"); 456 | } 457 | else 458 | { 459 | Key = Registry.CurrentUser.OpenSubKey(KeyPath, true); 460 | if (Key != null) Registry.CurrentUser.DeleteSubKeyTree(KeyPath); 461 | } 462 | } 463 | } 464 | } 465 | 466 | public static bool RunAsSYSTEM_TI 467 | { 468 | get 469 | { 470 | foreach (string ext in new string[] { "exefile", "batfile", "cmdfile" }) 471 | { 472 | string KeyPath = "Software\\Classes\\" + ext + "\\shell\\runasSYSTEM_TI"; 473 | if (Registry.CurrentUser.OpenSubKey(KeyPath) == null) return false; 474 | } 475 | return true; 476 | } 477 | set 478 | { 479 | foreach (string ext in new string[] { "exefile", "batfile", "cmdfile" }) 480 | { 481 | string KeyPath = "Software\\Classes\\" + ext + "\\shell\\runasSYSTEM_TI"; 482 | RegistryKey Key; 483 | if (value) 484 | { 485 | Key = Registry.CurrentUser.CreateSubKey(KeyPath); 486 | Key.SetValue("", MUI.GetText("ContextMenuIntegration.RunAsSYSTEM_TI")); 487 | Key.SetValue("MultiSelectModel", "Single"); 488 | Key.SetValue("Icon", Application.ExecutablePath); 489 | Key = Key.CreateSubKey("command"); 490 | Key.SetValue("", "\"" + Application.ExecutablePath + "\"" 491 | + " /TI /ShowWait /Run:\"%1\" %*"); 492 | } 493 | else 494 | { 495 | Key = Registry.CurrentUser.OpenSubKey(KeyPath, true); 496 | if (Key != null) Registry.CurrentUser.DeleteSubKeyTree(KeyPath); 497 | } 498 | } 499 | } 500 | } 501 | 502 | } 503 | 504 | } 505 | } 506 | -------------------------------------------------------------------------------- /src/frmQEditor.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SuperCMD 2 | { 3 | partial class frmQEditor 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.lblName = new System.Windows.Forms.Label(); 33 | this.txtName = new System.Windows.Forms.TextBox(); 34 | this.lblProgramPath = new System.Windows.Forms.Label(); 35 | this.txtProgramPath = new System.Windows.Forms.TextBox(); 36 | this.lblArguments = new System.Windows.Forms.Label(); 37 | this.txtArguments = new System.Windows.Forms.TextBox(); 38 | this.btnOK = new W31Button(); 39 | this.btnCancel = new W31Button(); 40 | this.btnSelectExe = new W31Button(); 41 | this.btnAppendArgs = new W31Button(); 42 | this.chkTI = new System.Windows.Forms.CheckBox(); 43 | this.grpWorkingDir = new System.Windows.Forms.GroupBox(); 44 | this.btnSelectWorkingDir = new W31Button(); 45 | this.txtCustomWorkingDir = new System.Windows.Forms.TextBox(); 46 | this.rdoCustomWorkingDir = new System.Windows.Forms.RadioButton(); 47 | this.rdoAutoWorkingDir = new System.Windows.Forms.RadioButton(); 48 | this.btnQEditMenu = new W31Button(); 49 | this.mnuQEdit = new System.Windows.Forms.ContextMenuStrip(this.components); 50 | this.cmiCopy = new System.Windows.Forms.ToolStripMenuItem(); 51 | this.cmiCopyAsText = new System.Windows.Forms.ToolStripMenuItem(); 52 | this.cmiPaste = new System.Windows.Forms.ToolStripMenuItem(); 53 | this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); 54 | this.cmiClearAll = new System.Windows.Forms.ToolStripMenuItem(); 55 | this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); 56 | this.cmiCreateLnk = new System.Windows.Forms.ToolStripMenuItem(); 57 | this.grpWorkingDir.SuspendLayout(); 58 | this.mnuQEdit.SuspendLayout(); 59 | this.SuspendLayout(); 60 | // 61 | // lblName 62 | // 63 | this.lblName.AutoSize = true; 64 | this.lblName.Location = new System.Drawing.Point(12, 15); 65 | this.lblName.Margin = new System.Windows.Forms.Padding(3, 6, 3, 3); 66 | this.lblName.Name = "lblName"; 67 | this.lblName.Size = new System.Drawing.Size(42, 15); 68 | this.lblName.TabIndex = 0; 69 | this.lblName.Text = "Name:"; 70 | // 71 | // txtName 72 | // 73 | this.txtName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 74 | | System.Windows.Forms.AnchorStyles.Right))); 75 | this.txtName.Location = new System.Drawing.Point(12, 33); 76 | this.txtName.Name = "txtName"; 77 | this.txtName.Size = new System.Drawing.Size(370, 23); 78 | this.txtName.TabIndex = 0; 79 | // 80 | // lblProgramPath 81 | // 82 | this.lblProgramPath.AutoSize = true; 83 | this.lblProgramPath.Location = new System.Drawing.Point(12, 65); 84 | this.lblProgramPath.Margin = new System.Windows.Forms.Padding(3, 6, 3, 3); 85 | this.lblProgramPath.Name = "lblProgramPath"; 86 | this.lblProgramPath.Size = new System.Drawing.Size(83, 15); 87 | this.lblProgramPath.TabIndex = 0; 88 | this.lblProgramPath.Text = "Program path:"; 89 | // 90 | // txtProgramPath 91 | // 92 | this.txtProgramPath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 93 | | System.Windows.Forms.AnchorStyles.Right))); 94 | this.txtProgramPath.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; 95 | this.txtProgramPath.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.FileSystem; 96 | this.txtProgramPath.Location = new System.Drawing.Point(12, 83); 97 | this.txtProgramPath.Name = "txtProgramPath"; 98 | this.txtProgramPath.Size = new System.Drawing.Size(332, 23); 99 | this.txtProgramPath.TabIndex = 1; 100 | // 101 | // lblArguments 102 | // 103 | this.lblArguments.AutoSize = true; 104 | this.lblArguments.Location = new System.Drawing.Point(12, 115); 105 | this.lblArguments.Margin = new System.Windows.Forms.Padding(3, 6, 3, 3); 106 | this.lblArguments.Name = "lblArguments"; 107 | this.lblArguments.Size = new System.Drawing.Size(69, 15); 108 | this.lblArguments.TabIndex = 0; 109 | this.lblArguments.Text = "Arguments:"; 110 | // 111 | // txtArguments 112 | // 113 | this.txtArguments.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 114 | | System.Windows.Forms.AnchorStyles.Right))); 115 | this.txtArguments.Location = new System.Drawing.Point(12, 133); 116 | this.txtArguments.Name = "txtArguments"; 117 | this.txtArguments.Size = new System.Drawing.Size(332, 23); 118 | this.txtArguments.TabIndex = 3; 119 | // 120 | // btnOK 121 | // 122 | this.btnOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 123 | this.btnOK.Location = new System.Drawing.Point(202, 262); 124 | this.btnOK.Name = "btnOK"; 125 | this.btnOK.Size = new System.Drawing.Size(87, 28); 126 | this.btnOK.TabIndex = 8; 127 | this.btnOK.Text = "OK"; 128 | this.btnOK.UseVisualStyleBackColor = true; 129 | this.btnOK.Click += new System.EventHandler(this.btnOK_Click); 130 | // 131 | // btnCancel 132 | // 133 | this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 134 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 135 | this.btnCancel.Location = new System.Drawing.Point(295, 262); 136 | this.btnCancel.Name = "btnCancel"; 137 | this.btnCancel.Size = new System.Drawing.Size(87, 28); 138 | this.btnCancel.TabIndex = 9; 139 | this.btnCancel.Text = "Cancel"; 140 | this.btnCancel.UseVisualStyleBackColor = true; 141 | this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); 142 | // 143 | // btnSelectExe 144 | // 145 | this.btnSelectExe.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 146 | this.btnSelectExe.Location = new System.Drawing.Point(350, 82); 147 | this.btnSelectExe.Name = "btnSelectExe"; 148 | this.btnSelectExe.Size = new System.Drawing.Size(32, 23); 149 | this.btnSelectExe.TabIndex = 2; 150 | this.btnSelectExe.Text = "..."; 151 | this.btnSelectExe.UseVisualStyleBackColor = true; 152 | this.btnSelectExe.Click += new System.EventHandler(this.btnSelectExe_Click); 153 | // 154 | // btnAppendArgs 155 | // 156 | this.btnAppendArgs.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 157 | this.btnAppendArgs.Location = new System.Drawing.Point(350, 132); 158 | this.btnAppendArgs.Name = "btnAppendArgs"; 159 | this.btnAppendArgs.Size = new System.Drawing.Size(32, 23); 160 | this.btnAppendArgs.TabIndex = 4; 161 | this.btnAppendArgs.Text = "+"; 162 | this.btnAppendArgs.UseVisualStyleBackColor = true; 163 | this.btnAppendArgs.Click += new System.EventHandler(this.btnAppendArgs_Click); 164 | // 165 | // chkTI 166 | // 167 | this.chkTI.Anchor = System.Windows.Forms.AnchorStyles.Bottom; 168 | this.chkTI.AutoSize = true; 169 | this.chkTI.Checked = true; 170 | this.chkTI.CheckState = System.Windows.Forms.CheckState.Checked; 171 | this.chkTI.Location = new System.Drawing.Point(115, 225); 172 | this.chkTI.Name = "chkTI"; 173 | this.chkTI.Size = new System.Drawing.Size(165, 19); 174 | this.chkTI.TabIndex = 7; 175 | this.chkTI.Text = "Use TrustedInstaller token!"; 176 | this.chkTI.UseVisualStyleBackColor = true; 177 | // 178 | // grpWorkingDir 179 | // 180 | this.grpWorkingDir.Controls.Add(this.btnSelectWorkingDir); 181 | this.grpWorkingDir.Controls.Add(this.txtCustomWorkingDir); 182 | this.grpWorkingDir.Controls.Add(this.rdoCustomWorkingDir); 183 | this.grpWorkingDir.Controls.Add(this.rdoAutoWorkingDir); 184 | this.grpWorkingDir.Location = new System.Drawing.Point(12, 165); 185 | this.grpWorkingDir.Name = "grpWorkingDir"; 186 | this.grpWorkingDir.Size = new System.Drawing.Size(370, 54); 187 | this.grpWorkingDir.TabIndex = 5; 188 | this.grpWorkingDir.TabStop = false; 189 | this.grpWorkingDir.Text = "Working directory"; 190 | // 191 | // btnSelectWorkingDir 192 | // 193 | this.btnSelectWorkingDir.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 194 | this.btnSelectWorkingDir.Location = new System.Drawing.Point(332, 22); 195 | this.btnSelectWorkingDir.Name = "btnSelectWorkingDir"; 196 | this.btnSelectWorkingDir.Size = new System.Drawing.Size(32, 23); 197 | this.btnSelectWorkingDir.TabIndex = 3; 198 | this.btnSelectWorkingDir.Text = "..."; 199 | this.btnSelectWorkingDir.UseVisualStyleBackColor = true; 200 | this.btnSelectWorkingDir.Click += new System.EventHandler(this.btnSelectWorkingDir_Click); 201 | // 202 | // txtCustomWorkingDir 203 | // 204 | this.txtCustomWorkingDir.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 205 | | System.Windows.Forms.AnchorStyles.Right))); 206 | this.txtCustomWorkingDir.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.Suggest; 207 | this.txtCustomWorkingDir.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.FileSystemDirectories; 208 | this.txtCustomWorkingDir.Location = new System.Drawing.Point(81, 22); 209 | this.txtCustomWorkingDir.Name = "txtCustomWorkingDir"; 210 | this.txtCustomWorkingDir.Size = new System.Drawing.Size(245, 23); 211 | this.txtCustomWorkingDir.TabIndex = 2; 212 | this.txtCustomWorkingDir.Click += new System.EventHandler(this.txtCustomWorkingDir_Click); 213 | // 214 | // rdoCustomWorkingDir 215 | // 216 | this.rdoCustomWorkingDir.AutoSize = true; 217 | this.rdoCustomWorkingDir.Location = new System.Drawing.Point(63, 24); 218 | this.rdoCustomWorkingDir.Name = "rdoCustomWorkingDir"; 219 | this.rdoCustomWorkingDir.Size = new System.Drawing.Size(28, 19); 220 | this.rdoCustomWorkingDir.TabIndex = 1; 221 | this.rdoCustomWorkingDir.TabStop = true; 222 | this.rdoCustomWorkingDir.Text = " "; 223 | this.rdoCustomWorkingDir.UseVisualStyleBackColor = true; 224 | this.rdoCustomWorkingDir.CheckedChanged += new System.EventHandler(this.rdo_AutoCorrect); 225 | this.rdoCustomWorkingDir.Enter += new System.EventHandler(this.rdo_AutoCorrect); 226 | // 227 | // rdoAutoWorkingDir 228 | // 229 | this.rdoAutoWorkingDir.AutoSize = true; 230 | this.rdoAutoWorkingDir.Checked = true; 231 | this.rdoAutoWorkingDir.Location = new System.Drawing.Point(6, 24); 232 | this.rdoAutoWorkingDir.Name = "rdoAutoWorkingDir"; 233 | this.rdoAutoWorkingDir.Size = new System.Drawing.Size(51, 19); 234 | this.rdoAutoWorkingDir.TabIndex = 0; 235 | this.rdoAutoWorkingDir.TabStop = true; 236 | this.rdoAutoWorkingDir.Text = "Auto"; 237 | this.rdoAutoWorkingDir.UseVisualStyleBackColor = true; 238 | this.rdoAutoWorkingDir.CheckedChanged += new System.EventHandler(this.rdo_AutoCorrect); 239 | this.rdoAutoWorkingDir.Enter += new System.EventHandler(this.rdo_AutoCorrect); 240 | // 241 | // btnQEditMenu 242 | // 243 | this.btnQEditMenu.Font = new System.Drawing.Font("Webdings", 11.25F); 244 | this.btnQEditMenu.Location = new System.Drawing.Point(15, 264); 245 | this.btnQEditMenu.Name = "btnQEditMenu"; 246 | this.btnQEditMenu.Size = new System.Drawing.Size(32, 25); 247 | this.btnQEditMenu.TabIndex = 10; 248 | this.btnQEditMenu.Text = "5"; 249 | this.btnQEditMenu.UseVisualStyleBackColor = true; 250 | this.btnQEditMenu.Click += new System.EventHandler(this.btnMenu_Click); 251 | // 252 | // mnuQEdit 253 | // 254 | this.mnuQEdit.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 255 | this.cmiCopy, 256 | this.cmiCopyAsText, 257 | this.cmiPaste, 258 | this.toolStripMenuItem2, 259 | this.cmiClearAll, 260 | this.toolStripMenuItem1, 261 | this.cmiCreateLnk}); 262 | this.mnuQEdit.Name = "mnuQEdit"; 263 | this.mnuQEdit.Size = new System.Drawing.Size(157, 126); 264 | // 265 | // cmiCopy 266 | // 267 | this.cmiCopy.Name = "cmiCopy"; 268 | this.cmiCopy.Size = new System.Drawing.Size(156, 22); 269 | this.cmiCopy.Text = "Copy"; 270 | this.cmiCopy.Click += new System.EventHandler(this.cmiCopy_Click); 271 | // 272 | // cmiCopyAsText 273 | // 274 | this.cmiCopyAsText.Name = "cmiCopyAsText"; 275 | this.cmiCopyAsText.Size = new System.Drawing.Size(156, 22); 276 | this.cmiCopyAsText.Text = "Copy as text"; 277 | this.cmiCopyAsText.Click += new System.EventHandler(this.cmiCopyAsText_Click); 278 | // 279 | // cmiPaste 280 | // 281 | this.cmiPaste.Name = "cmiPaste"; 282 | this.cmiPaste.Size = new System.Drawing.Size(156, 22); 283 | this.cmiPaste.Text = "Paste"; 284 | this.cmiPaste.Click += new System.EventHandler(this.cmiPaste_Click); 285 | // 286 | // toolStripMenuItem2 287 | // 288 | this.toolStripMenuItem2.Name = "toolStripMenuItem2"; 289 | this.toolStripMenuItem2.Size = new System.Drawing.Size(153, 6); 290 | // 291 | // cmiClearAll 292 | // 293 | this.cmiClearAll.Name = "cmiClearAll"; 294 | this.cmiClearAll.Size = new System.Drawing.Size(156, 22); 295 | this.cmiClearAll.Text = "Clear All"; 296 | this.cmiClearAll.Click += new System.EventHandler(this.cmiClearAll_Click); 297 | // 298 | // toolStripMenuItem1 299 | // 300 | this.toolStripMenuItem1.Name = "toolStripMenuItem1"; 301 | this.toolStripMenuItem1.Size = new System.Drawing.Size(153, 6); 302 | // 303 | // cmiCreateLnk 304 | // 305 | this.cmiCreateLnk.Name = "cmiCreateLnk"; 306 | this.cmiCreateLnk.Size = new System.Drawing.Size(156, 22); 307 | this.cmiCreateLnk.Text = "Create Shortcut"; 308 | this.cmiCreateLnk.Click += new System.EventHandler(this.cmiCreateLnk_Click); 309 | // 310 | // frmQEditor 311 | // 312 | this.AcceptButton = this.btnOK; 313 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 314 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 315 | this.BackColor = System.Drawing.SystemColors.Window; 316 | this.CancelButton = this.btnCancel; 317 | this.ClientSize = new System.Drawing.Size(394, 302); 318 | this.Controls.Add(this.btnQEditMenu); 319 | this.Controls.Add(this.chkTI); 320 | this.Controls.Add(this.grpWorkingDir); 321 | this.Controls.Add(this.btnAppendArgs); 322 | this.Controls.Add(this.btnSelectExe); 323 | this.Controls.Add(this.btnCancel); 324 | this.Controls.Add(this.btnOK); 325 | this.Controls.Add(this.txtArguments); 326 | this.Controls.Add(this.lblArguments); 327 | this.Controls.Add(this.txtProgramPath); 328 | this.Controls.Add(this.lblProgramPath); 329 | this.Controls.Add(this.txtName); 330 | this.Controls.Add(this.lblName); 331 | this.Font = new System.Drawing.Font("Segoe UI", 9F); 332 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; 333 | this.MaximizeBox = false; 334 | this.MinimizeBox = false; 335 | this.Name = "frmQEditor"; 336 | this.ShowIcon = false; 337 | this.ShowInTaskbar = false; 338 | this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; 339 | this.Text = "Edit Quick Launch item"; 340 | this.Load += new System.EventHandler(this.frmQEditor_Load); 341 | this.grpWorkingDir.ResumeLayout(false); 342 | this.grpWorkingDir.PerformLayout(); 343 | this.mnuQEdit.ResumeLayout(false); 344 | this.ResumeLayout(false); 345 | this.PerformLayout(); 346 | 347 | } 348 | 349 | #endregion 350 | 351 | private System.Windows.Forms.Label lblName; 352 | private System.Windows.Forms.TextBox txtName; 353 | private System.Windows.Forms.Label lblProgramPath; 354 | private System.Windows.Forms.TextBox txtProgramPath; 355 | private System.Windows.Forms.Label lblArguments; 356 | private System.Windows.Forms.TextBox txtArguments; 357 | private W31Button btnOK; 358 | private W31Button btnCancel; 359 | private W31Button btnSelectExe; 360 | private W31Button btnAppendArgs; 361 | private System.Windows.Forms.GroupBox grpWorkingDir; 362 | private W31Button btnSelectWorkingDir; 363 | private System.Windows.Forms.TextBox txtCustomWorkingDir; 364 | private System.Windows.Forms.RadioButton rdoCustomWorkingDir; 365 | private System.Windows.Forms.RadioButton rdoAutoWorkingDir; 366 | private W31Button btnQEditMenu; 367 | private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; 368 | private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; 369 | internal System.Windows.Forms.ToolStripMenuItem cmiCopy; 370 | internal System.Windows.Forms.ToolStripMenuItem cmiCopyAsText; 371 | internal System.Windows.Forms.ToolStripMenuItem cmiPaste; 372 | internal System.Windows.Forms.ToolStripMenuItem cmiClearAll; 373 | internal System.Windows.Forms.ToolStripMenuItem cmiCreateLnk; 374 | internal System.Windows.Forms.ContextMenuStrip mnuQEdit; 375 | internal System.Windows.Forms.CheckBox chkTI; 376 | } 377 | } -------------------------------------------------------------------------------- /src/SuperCore.cs: -------------------------------------------------------------------------------- 1 | /* SuperCore.cs of SuperCMD v2.1 by MaiSoft (Raymai97) 2 | 3 | Run a program with token of a running process. 4 | 5 | To get TrustedInstaller token, you must run as SYSTEM first, and then 6 | RunWithTokenOf("TrustedInstaller.exe", ...) 7 | 8 | This class is designed to be as portable as possible. 9 | 10 | This class has a Log system. 11 | Capture the Log message via SuperCore.Log() in a try-catch statement. 12 | Don't forget to call SuperCore.ClearLog() after you're done. 13 | 14 | This class also has a Complain system. 15 | The "Complain" event has "reason" which is a ComplainReason (enum), 16 | and "obj" that tells the related object to this error. 17 | For example, ComplainReason.FileNotFound, obj is C:\troll.txt, means 18 | C:\troll.txt is a troll; it doesn't exist. 19 | 20 | */ 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | using System.ComponentModel; 25 | using System.Diagnostics; 26 | using System.IO; 27 | using System.Runtime.InteropServices; 28 | 29 | namespace SuperCMD 30 | { 31 | class SuperCore 32 | { 33 | 34 | #region WIN32 API 35 | 36 | [DllImport("kernel32.dll", SetLastError = true)] 37 | [return: MarshalAs(UnmanagedType.Bool)] 38 | static extern bool CloseHandle(IntPtr hObject); 39 | 40 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] 41 | static extern IntPtr GetCurrentProcess(); 42 | 43 | [DllImport("kernel32.dll")] 44 | static extern uint WTSGetActiveConsoleSessionId(); 45 | 46 | [DllImport("advapi32.dll", SetLastError = true)] 47 | [return: MarshalAs(UnmanagedType.Bool)] 48 | static extern bool AdjustTokenPrivileges( 49 | IntPtr TokenHandle, 50 | bool DisableAllPrivileges, 51 | [MarshalAs(UnmanagedType.Struct)] ref TOKEN_PRIVILEGES NewState, 52 | uint dummy, IntPtr dummy2, IntPtr dummy3); 53 | 54 | [StructLayout(LayoutKind.Sequential)] 55 | private struct TOKEN_PRIVILEGES 56 | { 57 | internal uint PrivilegeCount; 58 | internal LUID Luid; 59 | internal uint Attrs; 60 | } 61 | 62 | [StructLayout(LayoutKind.Sequential)] 63 | private struct LUID 64 | { 65 | internal int LowPart; 66 | internal uint HighPart; 67 | } 68 | 69 | const uint SE_PRIVILEGE_ENABLED = 0x00000002; 70 | 71 | [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] 72 | [return: MarshalAs(UnmanagedType.Bool)] 73 | static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, 74 | out LUID lpLuid); 75 | 76 | [DllImport("kernel32.dll")] 77 | static extern IntPtr OpenProcess( 78 | ProcessAccessFlags dwDesiredAccess, 79 | bool bInheritHandle, 80 | int processId 81 | ); 82 | 83 | [Flags] 84 | enum ProcessAccessFlags : uint 85 | { 86 | All = 0x001F0FFF, 87 | Terminate = 0x00000001, 88 | CreateThread = 0x00000002, 89 | VirtualMemoryOperation = 0x00000008, 90 | VirtualMemoryRead = 0x00000010, 91 | VirtualMemoryWrite = 0x00000020, 92 | DuplicateHandle = 0x00000040, 93 | CreateProcess = 0x000000080, 94 | SetQuota = 0x00000100, 95 | SetInformation = 0x00000200, 96 | QueryInformation = 0x00000400, 97 | QueryLimitedInformation = 0x00001000, 98 | Synchronize = 0x00100000 99 | } 100 | 101 | [DllImport("advapi32.dll", SetLastError = true)] 102 | [return: MarshalAs(UnmanagedType.Bool)] 103 | static extern bool OpenProcessToken(IntPtr ProcessHandle, 104 | uint DesiredAccess, out IntPtr TokenHandle); 105 | 106 | const uint STANDARD_RIGHTS_REQUIRED = 0x000F0000; 107 | const uint STANDARD_RIGHTS_READ = 0x00020000; 108 | const uint TOKEN_ASSIGN_PRIMARY = 0x0001; 109 | const uint TOKEN_DUPLICATE = 0x0002; 110 | const uint TOKEN_IMPERSONATE = 0x0004; 111 | const uint TOKEN_QUERY = 0x0008; 112 | const uint TOKEN_QUERY_SOURCE = 0x0010; 113 | const uint TOKEN_ADJUST_PRIVILEGES = 0x0020; 114 | const uint TOKEN_ADJUST_GROUPS = 0x0040; 115 | const uint TOKEN_ADJUST_DEFAULT = 0x0080; 116 | const uint TOKEN_ADJUST_SESSIONID = 0x0100; 117 | const uint TOKEN_READ = (STANDARD_RIGHTS_READ | TOKEN_QUERY); 118 | const uint TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | 119 | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | 120 | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | 121 | TOKEN_ADJUST_SESSIONID); 122 | 123 | [DllImport("advapi32.dll", SetLastError = true)] 124 | static extern Boolean SetTokenInformation(IntPtr TokenHandle, uint TokenInformationClass, 125 | ref uint TokenInformation, uint TokenInformationLength); 126 | 127 | const uint TOKEN_INFORMATION_CLASS_TokenSessionId = 12; 128 | 129 | [DllImport("userenv.dll", SetLastError = true)] 130 | [return: MarshalAs(UnmanagedType.Bool)] 131 | static extern bool CreateEnvironmentBlock(out IntPtr lpEnvironment, IntPtr hToken, bool bInherit); 132 | 133 | [DllImport("userenv.dll", SetLastError = true)] 134 | [return: MarshalAs(UnmanagedType.Bool)] 135 | static extern bool DestroyEnvironmentBlock(IntPtr lpEnvironment); 136 | 137 | [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] 138 | static extern bool CreateProcessAsUserW( 139 | IntPtr hToken, 140 | string lpApplicationName, 141 | string lpCommandLine, 142 | ref SECURITY_ATTRIBUTES lpProcessAttributes, 143 | ref SECURITY_ATTRIBUTES lpThreadAttributes, 144 | bool bInheritHandles, 145 | uint dwCreationFlags, 146 | IntPtr lpEnvironment, 147 | string lpCurrentDirectory, 148 | ref STARTUPINFO lpStartupInfo, 149 | out PROCESSINFO lpProcessInformation); 150 | 151 | [StructLayout(LayoutKind.Sequential)] 152 | private struct SECURITY_ATTRIBUTES 153 | { 154 | public int nLength; 155 | public IntPtr lpSecurityDescriptor; 156 | public int bInheritHandle; 157 | } 158 | 159 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] 160 | private struct STARTUPINFO 161 | { 162 | public int cb; 163 | public string lpReserved; 164 | public string lpDesktop; 165 | public string lpTitle; 166 | public int dwX; 167 | public int dwY; 168 | public int dwXSize; 169 | public int dwYSize; 170 | public int dwXCountChars; 171 | public int dwYCountChars; 172 | public int dwFillAttribute; 173 | public int dwFlags; 174 | public Int16 wShowWindow; 175 | public Int16 cbReserved2; 176 | public IntPtr lpReserved2; 177 | public IntPtr hStdInput; 178 | public IntPtr hStdOutput; 179 | public IntPtr hStdError; 180 | } 181 | 182 | [StructLayout(LayoutKind.Sequential)] 183 | private struct PROCESSINFO 184 | { 185 | public IntPtr hProcess; 186 | public IntPtr hThread; 187 | public int dwProcessId; 188 | public int dwThreadId; 189 | } 190 | 191 | [DllImport("advapi32", SetLastError = true, CharSet = CharSet.Unicode)] 192 | static extern bool CreateProcessWithTokenW( 193 | IntPtr hToken, 194 | LogonFlags dwLogonFlags, 195 | string lpApplicationName, 196 | string lpCommandLine, 197 | uint dwCreationFlags, 198 | IntPtr lpEnvironment, 199 | string lpCurrentDirectory, 200 | [In] ref STARTUPINFO lpStartupInfo, 201 | out PROCESSINFO lpProcessInformation); 202 | 203 | enum LogonFlags 204 | { 205 | WithProfile = 1, 206 | NetCredentialsOnly 207 | } 208 | 209 | const uint NORMAL_PRIORITY_CLASS = 0x00000020; 210 | const uint CREATE_NEW_CONSOLE = 0x00000010; 211 | const uint CREATE_UNICODE_ENVIRONMENT = 0x00000400; 212 | 213 | [DllImport("advapi32.dll", CharSet = CharSet.Auto, SetLastError = true)] 214 | extern static bool DuplicateTokenEx( 215 | IntPtr hExistingToken, 216 | uint dwDesiredAccess, 217 | ref SECURITY_ATTRIBUTES lpTokenAttributes, 218 | SecurityImpersonationLevel ImpersonationLevel, 219 | TokenType TokenType, 220 | out IntPtr phNewToken); 221 | 222 | enum SecurityImpersonationLevel 223 | { 224 | SecurityAnonymous = 0, 225 | SecurityIdentification = 1, 226 | SecurityImpersonation = 2, 227 | SecurityDelegation = 3 228 | } 229 | 230 | enum TokenType 231 | { 232 | TokenPrimary = 1, 233 | TokenImpersonation 234 | } 235 | 236 | #endregion 237 | 238 | #region Log System 239 | 240 | private static string _Log; 241 | public static string Log 242 | { 243 | get 244 | { 245 | return _Log; 246 | } 247 | private set 248 | { 249 | _Log = value + Environment.NewLine; 250 | } 251 | } 252 | 253 | public static void ClearLog() 254 | { 255 | _Log = ""; 256 | } 257 | 258 | private static void EndLog() 259 | { 260 | Log += " ---- end of log : " + DateTime.Now.ToString("d MMM yyyy hh:mm:ss tt") + " ---- "; 261 | } 262 | 263 | private static void LogErr(string msg, bool cleanup = true) 264 | { 265 | if (cleanup) CleanUp(); 266 | Log += msg; 267 | EndLog(); 268 | } 269 | 270 | #endregion 271 | 272 | #region Complain System 273 | 274 | public enum ComplainReason 275 | { 276 | FileNotFound, 277 | FileNotExe, 278 | CantGetPID, 279 | APICallFailed 280 | } 281 | 282 | public delegate void ComplainHandler(ComplainReason reason, string obj); 283 | 284 | public static event ComplainHandler Complain; 285 | 286 | static bool plsThrow = false; 287 | 288 | static void GoComplain(ComplainReason reason, string obj) 289 | { 290 | switch (reason) 291 | { 292 | case ComplainReason.FileNotFound: 293 | LogErr("ExeToRun is not an existing file!"); break; 294 | case ComplainReason.FileNotExe: 295 | LogErr("ExeToRun is not an executable file!"); break; 296 | case ComplainReason.CantGetPID: 297 | LogErr("Can't get the PID of: " + obj); break; 298 | case ComplainReason.APICallFailed: 299 | obj += ": " + WinAPILastErrMsg(); 300 | LogErr(obj); break; 301 | default: LogErr(""); break; 302 | } 303 | Complain.Invoke(reason, obj); 304 | if (plsThrow) 305 | { 306 | plsThrow = false; 307 | throw new Exception(); 308 | } 309 | } 310 | 311 | #endregion 312 | 313 | public static bool ForceTokenUseActiveSessionID = false; 314 | 315 | static STARTUPINFO SI; 316 | static PROCESSINFO PI; 317 | static SECURITY_ATTRIBUTES dummySA = new SECURITY_ATTRIBUTES(); 318 | static IntPtr hProc, hToken, hDupToken, pEnvBlock; 319 | 320 | // Run with the token of the first process with the name of ProcessName 321 | public static void RunWithTokenOf( 322 | string ProcessName, 323 | bool OfActiveSessionOnly, 324 | string ExeToRun, 325 | string Arguments, 326 | string WorkingDir = "") 327 | { 328 | List PIDs = new List(); 329 | foreach (Process p in Process.GetProcessesByName( 330 | Path.GetFileNameWithoutExtension(ProcessName))) 331 | { 332 | if (OfActiveSessionOnly) 333 | { 334 | if (p.SessionId == WTSGetActiveConsoleSessionId()) 335 | PIDs.Add(p.Id); 336 | } 337 | else 338 | { 339 | PIDs.Add(p.Id); 340 | } 341 | } 342 | if (PIDs.Count == 0) 343 | { 344 | GoComplain(ComplainReason.CantGetPID, ProcessName); 345 | return; 346 | } 347 | RunWithTokenOf(PIDs[0], ExeToRun, Arguments, WorkingDir); 348 | } 349 | 350 | public static void RunWithTokenOf( 351 | int ProcessID, 352 | string ExeToRun, 353 | string Arguments, 354 | string WorkingDir = "") 355 | { 356 | plsThrow = true; 357 | try 358 | { 359 | #region Process ExeToRun, Arguments and WorkingDir 360 | // If ExeToRun is not absolute path, then let it be 361 | ExeToRun = Environment.ExpandEnvironmentVariables(ExeToRun); 362 | if (!ExeToRun.Contains("\\")) 363 | { 364 | foreach (string path in Environment.ExpandEnvironmentVariables("%path%").Split(';')) 365 | { 366 | string guess = path + "\\" + ExeToRun; 367 | if (File.Exists(guess)) { ExeToRun = guess; break; } 368 | } 369 | } 370 | if (!File.Exists(ExeToRun)) GoComplain(ComplainReason.FileNotFound, ExeToRun); 371 | // If WorkingDir not exist, let it be the dir of ExeToRun 372 | // ExeToRun no dir? Impossible, as I would GoComplain() already 373 | WorkingDir = Environment.ExpandEnvironmentVariables(WorkingDir); 374 | if (!Directory.Exists(WorkingDir)) WorkingDir = Path.GetDirectoryName(ExeToRun); 375 | // If arguments exist, CmdLine must include ExeToRun as well 376 | Arguments = Environment.ExpandEnvironmentVariables(Arguments); 377 | string CmdLine = null; 378 | if (Arguments != "") 379 | { 380 | if (ExeToRun.Contains(" ")) 381 | { 382 | CmdLine = "\"" + ExeToRun + "\" " + Arguments; 383 | } 384 | else 385 | { 386 | CmdLine = ExeToRun + " " + Arguments; 387 | } 388 | } 389 | #endregion 390 | 391 | string obj; 392 | Log += "Running as user: " + Environment.UserName; 393 | // Set privileges of current process 394 | string privs = "SeDebugPrivilege"; 395 | obj = "OpenProcessToken"; 396 | if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, out hToken)) 397 | { 398 | GoComplain(ComplainReason.APICallFailed, obj); 399 | } 400 | foreach (string priv in privs.Split(',')) 401 | { 402 | obj = "LookupPrivilegeValue (" + priv + ")"; 403 | LUID Luid; 404 | if (!LookupPrivilegeValue("", priv, out Luid)) 405 | { 406 | GoComplain(ComplainReason.APICallFailed, obj); 407 | } 408 | obj = "AdjustTokenPrivileges (" + priv + ")"; 409 | TOKEN_PRIVILEGES TP = new TOKEN_PRIVILEGES(); 410 | TP.PrivilegeCount = 1; 411 | TP.Luid = Luid; 412 | TP.Attrs = SE_PRIVILEGE_ENABLED; 413 | if (AdjustTokenPrivileges(hToken, false, ref TP, 0, IntPtr.Zero, IntPtr.Zero) 414 | & Marshal.GetLastWin32Error() == 0) 415 | { 416 | Log += obj + ": OK!"; 417 | } 418 | else 419 | { 420 | GoComplain(ComplainReason.APICallFailed, obj); 421 | } 422 | } 423 | CloseHandle(hToken); 424 | // Open process by PID 425 | obj = "OpenProcess (PID: " + ProcessID.ToString() + ")"; 426 | hProc = OpenProcess(ProcessAccessFlags.All, false, ProcessID); 427 | if (hProc == null) 428 | { 429 | GoComplain(ComplainReason.APICallFailed, obj); 430 | } 431 | Log += obj + ": OK!"; 432 | // Open process token 433 | obj = "OpenProcessToken (TOKEN_DUPLICATE | TOKEN_QUERY)"; 434 | if (!OpenProcessToken(hProc, TOKEN_DUPLICATE | TOKEN_QUERY, out hToken)) 435 | { 436 | GoComplain(ComplainReason.APICallFailed, obj); 437 | } 438 | Log += obj + ": OK!"; 439 | // Duplicate to hDupToken 440 | obj = "DuplicateTokenEx (TOKEN_ALL_ACCESS)"; 441 | if (!DuplicateTokenEx(hToken, TOKEN_ALL_ACCESS, ref dummySA, 442 | SecurityImpersonationLevel.SecurityIdentification, 443 | TokenType.TokenPrimary, out hDupToken)) 444 | { 445 | GoComplain(ComplainReason.APICallFailed, obj); 446 | } 447 | Log += obj + ": OK!"; 448 | // Set session ID to make sure it shows in current user desktop 449 | // Only possible when SuperCMD running as SYSTEM! 450 | if (ForceTokenUseActiveSessionID) 451 | { 452 | obj = "SetTokenInformation (toActiveSessionID)"; 453 | uint SID = WTSGetActiveConsoleSessionId(); 454 | if (!SetTokenInformation(hDupToken, TOKEN_INFORMATION_CLASS_TokenSessionId, ref SID, (uint)sizeof(uint))) 455 | { 456 | GoComplain(ComplainReason.APICallFailed, obj); 457 | } 458 | Log += obj + ": OK!"; 459 | } 460 | // Create environment block 461 | obj = "CreateEnvironmentBlock"; 462 | if (!CreateEnvironmentBlock(out pEnvBlock, hToken, true)) 463 | { 464 | GoComplain(ComplainReason.APICallFailed, obj); 465 | } 466 | Log += obj + ": OK!\n"; 467 | // Create process with the token we "stole" ^^ 468 | uint dwCreationFlags = (NORMAL_PRIORITY_CLASS | CREATE_NEW_CONSOLE | CREATE_UNICODE_ENVIRONMENT); 469 | SI = new STARTUPINFO(); 470 | SI.cb = Marshal.SizeOf(SI); 471 | SI.lpDesktop = "winsta0\\default"; 472 | PI = new PROCESSINFO(); 473 | // CreateProcessWithTokenW doesn't work in Safe Mode 474 | // CreateProcessAsUserW works, but if the Session ID is different, 475 | // we need to set it via SetTokenInformation() 476 | obj = "CreateProcessWithTokenW"; 477 | if (CreateProcessWithTokenW(hDupToken, LogonFlags.WithProfile, ExeToRun, CmdLine, 478 | dwCreationFlags, pEnvBlock, WorkingDir, ref SI, out PI)) 479 | { 480 | Log += "CreateProcessWithTokenW: Done! New process created successfully!"; 481 | } 482 | else 483 | { 484 | Log += "CreateProcessWithTokenW: " + WinAPILastErrMsg(); 485 | Log += "\nTrying CreateProcessAsUserW instead."; 486 | obj = "CreateProcessAsUserW"; 487 | if (CreateProcessAsUserW(hDupToken, ExeToRun, CmdLine, ref dummySA, ref dummySA, 488 | false, dwCreationFlags, pEnvBlock, WorkingDir, ref SI, out PI)) 489 | { 490 | Log += obj + ": Done! New process created successfully!"; 491 | } 492 | else 493 | { 494 | switch (Marshal.GetLastWin32Error()) 495 | { 496 | case 3: 497 | GoComplain(ComplainReason.FileNotFound, ExeToRun); break; 498 | case 193: 499 | GoComplain(ComplainReason.FileNotExe, ExeToRun); break; 500 | default: 501 | GoComplain(ComplainReason.APICallFailed, obj); break; 502 | } 503 | } 504 | } 505 | Log += "Process name: " + Path.GetFileName(ExeToRun); 506 | Log += "Process ID: " + PI.dwProcessId; 507 | CleanUp(); 508 | EndLog(); 509 | } 510 | catch (Exception) 511 | {} 512 | } 513 | 514 | static void CleanUp() 515 | { 516 | CloseHandle(SI.hStdError); SI.hStdError = IntPtr.Zero; 517 | CloseHandle(SI.hStdInput); SI.hStdInput = IntPtr.Zero; 518 | CloseHandle(SI.hStdOutput); SI.hStdOutput = IntPtr.Zero; 519 | CloseHandle(PI.hThread); PI.hThread = IntPtr.Zero; 520 | CloseHandle(PI.hProcess); PI.hThread = IntPtr.Zero; 521 | DestroyEnvironmentBlock(pEnvBlock); pEnvBlock = IntPtr.Zero; 522 | CloseHandle(hDupToken); hDupToken = IntPtr.Zero; 523 | CloseHandle(hToken); hToken = IntPtr.Zero; 524 | } 525 | 526 | static string WinAPILastErrMsg() 527 | { 528 | int err = Marshal.GetLastWin32Error(); 529 | return new Win32Exception(err).Message + " (Error code: " + err + ")"; 530 | } 531 | 532 | 533 | } 534 | } 535 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------