From 3bcf53624caafcc6a18a8de2309822f5e2b9a230 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 21:21:26 +0300 Subject: [PATCH 01/31] version change --- Core/Properties/AssemblyInfo.cs | 4 ++-- Shell/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Core/Properties/AssemblyInfo.cs b/Core/Properties/AssemblyInfo.cs index f7e197a7..61e989d6 100644 --- a/Core/Properties/AssemblyInfo.cs +++ b/Core/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.7.2.0")] -[assembly: AssemblyFileVersion("1.7.2.0")] +[assembly: AssemblyVersion("1.7.3.0")] +[assembly: AssemblyFileVersion("1.7.3.0")] diff --git a/Shell/Properties/AssemblyInfo.cs b/Shell/Properties/AssemblyInfo.cs index 874f0e5f..8b872858 100644 --- a/Shell/Properties/AssemblyInfo.cs +++ b/Shell/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.1")] -[assembly: AssemblyFileVersion("1.9.0.1")] +[assembly: AssemblyVersion("1.9.0.2")] +[assembly: AssemblyFileVersion("1.9.0.2")] From c284a5389b77d27468471ec5d948e918bddaa729 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 21:32:12 +0300 Subject: [PATCH 02/31] wip: process fix run with different user --- Core/SystemTools/ProcessStart.cs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 34d50cf3..b79cb964 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -1,4 +1,5 @@ -using System; +using Core.Encryption; +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -48,20 +49,37 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck arguments = $@"/c start {input} {arguments}"; input = null; } + process.StartInfo = new ProcessStartInfo(input); if (asAdmin) { - process.StartInfo = new ProcessStartInfo(input); + + var secureString = new System.Security.SecureString(); if (exe) process.StartInfo.FileName = "cmd"; process.StartInfo.WorkingDirectory = GetExecutablePath(input); - process.StartInfo.UseShellExecute = true; + process.StartInfo.UseShellExecute = false; process.StartInfo.Arguments = arguments.Trim(); - process.StartInfo.Verb = "runas"; + Console.Write("User name: "); + var userName = Console.ReadLine(); + if (!string.IsNullOrEmpty(userName)) + { + process.StartInfo.UserName = userName; + } + Console.Write("Passwod: "); + var password = PasswordValidator.GetHiddenConsoleInput(); + if (password.Length > 0) + { + process.StartInfo.Password = password; + } + Console.WriteLine(); + Console.Write("Domain: "); + var domain = Console.ReadLine() ?? string.Empty; + if (!string.IsNullOrEmpty(domain)) + process.StartInfo.Domain = domain; } else { - process.StartInfo = new ProcessStartInfo(input); if (exe) process.StartInfo.FileName = "cmd"; process.StartInfo.WorkingDirectory = GetExecutablePath(input); From cfc3cfaa23775450beb34a2024e4187361673895 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 21:45:04 +0300 Subject: [PATCH 03/31] fix run new terminal with normal user --- Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs b/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs index 3ac047d1..402aa2e7 100644 --- a/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs +++ b/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs @@ -18,12 +18,6 @@ class NewTWindow : ITerminalCommand "; public void Execute(string args) { - - if (args ==Name && !args.Contains("-u")) - { - FileSystem.SuccessWriteLine($"Use -h param for {Name} command usage!"); - return; - } if (args == $"{Name} -h") { Console.WriteLine(s_helpMessage); From b1e8a18a0d88a5405ae6f3eb6ff16be3f802f6f1 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 21:45:14 +0300 Subject: [PATCH 04/31] run with different user --- Core/SystemTools/ProcessStart.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index b79cb964..ef522e28 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -62,21 +62,28 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck process.StartInfo.Arguments = arguments.Trim(); Console.Write("User name: "); var userName = Console.ReadLine(); - if (!string.IsNullOrEmpty(userName)) + if (string.IsNullOrEmpty(userName)) { - process.StartInfo.UserName = userName; + Console.WriteLine(); + FileSystem.ErrorWriteLine("User name must be provieded!"); + return; } + process.StartInfo.UserName = userName; Console.Write("Passwod: "); var password = PasswordValidator.GetHiddenConsoleInput(); - if (password.Length > 0) + if (password.Length <= 0) { - process.StartInfo.Password = password; + FileSystem.ErrorWriteLine($"Password for {userName} must be provided!"); + return; } + process.StartInfo.Password = password; Console.WriteLine(); - Console.Write("Domain: "); + Console.Write("Domain(optional): "); var domain = Console.ReadLine() ?? string.Empty; if (!string.IsNullOrEmpty(domain)) process.StartInfo.Domain = domain; + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.RedirectStandardError = true; } else { @@ -119,7 +126,10 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck } catch (System.ComponentModel.Win32Exception win) { - FileSystem.ErrorWriteLine(win.Message); + if (win.Message.Contains("The user name or password is incorrect.")) + FileSystem.ErrorWriteLine("The user name or password is incorrect!"); + else + FileSystem.ErrorWriteLine(win.Message); } catch (Exception e) { From fc94845a4439b94e856d92052751f6bfcf8b81c8 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 21:48:04 +0300 Subject: [PATCH 05/31] fix run nt -u properly --- Core/SystemTools/ProcessStart.cs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index ef522e28..7b43c93d 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -152,9 +152,30 @@ public static void ProcessExecute(string input, bool asAdmin) { process.StartInfo = new ProcessStartInfo(input) { - UseShellExecute = true, - Verb = "runas" + UseShellExecute = false }; + Console.Write("User name: "); + var userName = Console.ReadLine(); + if (string.IsNullOrEmpty(userName)) + { + Console.WriteLine(); + FileSystem.ErrorWriteLine("User name must be provieded!"); + return; + } + process.StartInfo.UserName = userName; + Console.Write("Passwod: "); + var password = PasswordValidator.GetHiddenConsoleInput(); + if (password.Length <= 0) + { + FileSystem.ErrorWriteLine($"Password for {userName} must be provided!"); + return; + } + process.StartInfo.Password = password; + Console.WriteLine(); + Console.Write("Domain(optional): "); + var domain = Console.ReadLine() ?? string.Empty; + if (!string.IsNullOrEmpty(domain)) + process.StartInfo.Domain = domain; } else { From 40a9600c37428841dc979411bab123e49efc7c21 Mon Sep 17 00:00:00 2001 From: xeL Date: Mon, 16 Sep 2024 22:36:07 +0300 Subject: [PATCH 06/31] removed use shell execute --- Core/SystemTools/ProcessStart.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 7b43c93d..a9bca1cd 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -58,7 +58,6 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (exe) process.StartInfo.FileName = "cmd"; process.StartInfo.WorkingDirectory = GetExecutablePath(input); - process.StartInfo.UseShellExecute = false; process.StartInfo.Arguments = arguments.Trim(); Console.Write("User name: "); var userName = Console.ReadLine(); @@ -69,6 +68,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck return; } process.StartInfo.UserName = userName; + Console.Write("Passwod: "); var password = PasswordValidator.GetHiddenConsoleInput(); if (password.Length <= 0) @@ -82,8 +82,9 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck var domain = Console.ReadLine() ?? string.Empty; if (!string.IsNullOrEmpty(domain)) process.StartInfo.Domain = domain; - process.StartInfo.RedirectStandardInput = true; - process.StartInfo.RedirectStandardError = true; + + process.StartInfo.RedirectStandardInput = true; + process.StartInfo.RedirectStandardError = true; } else { From 8418fd099350c7a07df2063cfe989db8e275208a Mon Sep 17 00:00:00 2001 From: x_coding Date: Tue, 17 Sep 2024 15:07:08 +0300 Subject: [PATCH 07/31] name rule --- .../TerminalCommands/ConsoleSystem/BiosInfo.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/BiosInfo.cs b/Commands/TerminalCommands/ConsoleSystem/BiosInfo.cs index a825bcee..0559e54e 100644 --- a/Commands/TerminalCommands/ConsoleSystem/BiosInfo.cs +++ b/Commands/TerminalCommands/ConsoleSystem/BiosInfo.cs @@ -1,8 +1,8 @@ using Core; using System; using System.Runtime.Versioning; -using ping = Core.NetWork; -using wmi = Core.Hardware.WMIDetails; +using Ping = Core.NetWork; +using Wmi = Core.Hardware.WMIDetails; namespace Commands.TerminalCommands.ConsoleSystem { @@ -38,7 +38,7 @@ private static void BiosInformation(string commandType) case "-r": Console.Write("Type remote PC name or IP: "); pc = Console.ReadLine(); - if (!ping.PingHost(pc)) + if (!Ping.PingHost(pc)) { Console.WriteLine($"{pc} is offline!"); return; @@ -46,12 +46,12 @@ private static void BiosInformation(string commandType) if (GlobalVariables.isPipeCommand) { if (GlobalVariables.pipeCmdCount > 0) - GlobalVariables.pipeCmdOutput = wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2"); + GlobalVariables.pipeCmdOutput = Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2"); else - Console.WriteLine(wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2")); + Console.WriteLine(Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2")); } else - Console.WriteLine(wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2")); + Console.WriteLine(Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\" + pc + @"\root\cimv2")); break; case "-h": Console.WriteLine(HelpCommand()); @@ -60,12 +60,12 @@ private static void BiosInformation(string commandType) if (GlobalVariables.isPipeCommand) { if(GlobalVariables.pipeCmdCount > 0) - GlobalVariables.pipeCmdOutput = wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2"); + GlobalVariables.pipeCmdOutput = Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2"); else - Console.WriteLine(wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2")); + Console.WriteLine(Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2")); } else - Console.WriteLine(wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2")); + Console.WriteLine(Wmi.GetWMIDetails("SELECT * FROM Win32_BIOS", @"\\.\root\cimv2")); break; } } From d5f9329c8dabaf3b860eb8c6ee00e0342564ba79 Mon Sep 17 00:00:00 2001 From: xeL Date: Tue, 17 Sep 2024 22:17:39 +0300 Subject: [PATCH 08/31] set to x64 release --- Shell.sln | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Shell.sln b/Shell.sln index 13aeac0c..d91778bf 100644 --- a/Shell.sln +++ b/Shell.sln @@ -30,8 +30,8 @@ Global {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Debug|x64.ActiveCfg = Debug|x64 {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Debug|x64.Build.0 = Debug|x64 - {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|Any CPU.ActiveCfg = Release x64|Any CPU - {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|Any CPU.Build.0 = Release x64|Any CPU + {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|Any CPU.ActiveCfg = Release|Any CPU + {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|Any CPU.Build.0 = Release|Any CPU {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|x64.ActiveCfg = Release x64|x64 {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release x64|x64.Build.0 = Release x64|x64 {3977CB5B-AE6C-443A-B005-9BE1997A0C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -42,8 +42,8 @@ Global {589BCB52-0184-4C70-BD85-095C0755F536}.Debug|Any CPU.Build.0 = Debug|Any CPU {589BCB52-0184-4C70-BD85-095C0755F536}.Debug|x64.ActiveCfg = Debug|x64 {589BCB52-0184-4C70-BD85-095C0755F536}.Debug|x64.Build.0 = Debug|x64 - {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|Any CPU.ActiveCfg = Release x64|Any CPU - {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|Any CPU.Build.0 = Release x64|Any CPU + {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|Any CPU.ActiveCfg = Release|Any CPU + {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|Any CPU.Build.0 = Release|Any CPU {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|x64.ActiveCfg = Release x64|x64 {589BCB52-0184-4C70-BD85-095C0755F536}.Release x64|x64.Build.0 = Release x64|x64 {589BCB52-0184-4C70-BD85-095C0755F536}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -54,8 +54,8 @@ Global {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Debug|Any CPU.Build.0 = Debug|Any CPU {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Debug|x64.ActiveCfg = x64|x64 {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Debug|x64.Build.0 = x64|x64 - {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|Any CPU.ActiveCfg = Release x64|Any CPU - {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|Any CPU.Build.0 = Release x64|Any CPU + {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|Any CPU.ActiveCfg = Release|Any CPU + {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|Any CPU.Build.0 = Release|Any CPU {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|x64.ActiveCfg = Release x64|x64 {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release x64|x64.Build.0 = Release x64|x64 {AE8425C8-0F5B-4D39-85EE-D12941FF4E65}.Release|Any CPU.ActiveCfg = Release|Any CPU From 5fc09d0f77a9d99e3f50b5271d86a30b40ae0dfa Mon Sep 17 00:00:00 2001 From: xeL Date: Tue, 17 Sep 2024 22:53:36 +0300 Subject: [PATCH 09/31] mor progress on open file from different user --- Core/SystemTools/ProcessStart.cs | 50 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index a9bca1cd..efdda5c6 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -10,21 +10,8 @@ namespace Core.SystemTools [SupportedOSPlatform("Windows")] public class ProcessStart { - /// - /// Process execution with arguments. - /// - /// File name. - /// Specific file arguments. - /// Check file if exists before process exection. - /// Run as different user. private static string s_currentDirectory; - /// - /// Get path of assembly. - /// - /// - /// - private static string GetExecutablePath(string executableFilePath) => Path.GetDirectoryName(executableFilePath); /// /// Execute process command. @@ -40,24 +27,21 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck { var process = new Process(); - bool exe = !input.Trim().EndsWith(".exe") && !input.Trim().EndsWith(".msi"); + bool exe = input.Trim().EndsWith(".exe") || input.Trim().EndsWith(".msi"); + string cmdPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"); // Check is execautable or not. - if (exe) - { - arguments = $@"/c start {input} {arguments}"; - input = null; - } - process.StartInfo = new ProcessStartInfo(input); + if (asAdmin) { - + arguments = $@"/c start {input} {arguments}"; + process.StartInfo.FileName = cmdPath; + process.StartInfo = new ProcessStartInfo(cmdPath); var secureString = new System.Security.SecureString(); - if (exe) - process.StartInfo.FileName = "cmd"; - process.StartInfo.WorkingDirectory = GetExecutablePath(input); + if (!exe) + process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.Arguments = arguments.Trim(); Console.Write("User name: "); var userName = Console.ReadLine(); @@ -82,15 +66,23 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck var domain = Console.ReadLine() ?? string.Empty; if (!string.IsNullOrEmpty(domain)) process.StartInfo.Domain = domain; - + if (!waitForExit) + { process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; + } } else { - if (exe) - process.StartInfo.FileName = "cmd"; - process.StartInfo.WorkingDirectory = GetExecutablePath(input); + var fileName = input; + if (!exe) + { + arguments = $@"/c start {input} {arguments}"; + process.StartInfo.FileName = cmdPath; + fileName = cmdPath; + } + process.StartInfo = new ProcessStartInfo(fileName); ; + process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.UseShellExecute = false; if (!waitForExit) { @@ -101,7 +93,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck } // Runing non executable files. - if (exe) + if (!exe) { process.Start(); if (waitForExit) From 1b68cdb58650a827e010aa88fcd873887caab76a Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 20:47:10 +0300 Subject: [PATCH 10/31] update readmed with -r param for ./ (start process) command --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 58d59140..735703e3 100644 --- a/README.md +++ b/README.md @@ -74,10 +74,12 @@ This is the full list of commands that can be used in xTerminal: Can be used with the following parameters: -h : Displays this message. -u : Can run process with different user. + -r : Can run process with RunAs parameter. -we : Disable wait for process to exit. -param: ./ process with specified parameters. Example1: ./ -u Example2: ./ -u -param + Example3: ./ -r Both examples can be used with -we parameter. pkill -- Kills a running process by name or id. Example1: pkill From 9d8959f162409081ed3329486c3d321231d76d20 Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 20:47:26 +0300 Subject: [PATCH 11/31] added verb runas --- Core/SystemTools/ProcessStart.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index efdda5c6..f3161f57 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -21,7 +21,7 @@ public class ProcessStart /// /// /// - public static void ProcessExecute(string input, string arguments, bool fileCheck, bool asAdmin, bool waitForExit) + public static void ProcessExecute(string input, string arguments, bool fileCheck, bool asAdmin, bool waitForExit, bool runAs = false) { try { @@ -43,6 +43,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (!exe) process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.Arguments = arguments.Trim(); + Console.Write("User name: "); var userName = Console.ReadLine(); if (string.IsNullOrEmpty(userName)) @@ -84,6 +85,8 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck process.StartInfo = new ProcessStartInfo(fileName); ; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.UseShellExecute = false; + if (runAs) + process.StartInfo.Verb = "runas"; if (!waitForExit) { process.StartInfo.RedirectStandardInput = true; From 4a17cabfa56d6e154cea1c39569e7599a23cfb68 Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 20:47:53 +0300 Subject: [PATCH 12/31] added param -r for runas verb --- .../ConsoleSystem/StartProccess.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index bd59714f..91b9da6c 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -16,10 +16,12 @@ public class StartProccess : ITerminalCommand Can be used with the following parameters: -h : Displays this message. -u : Can run process with different user. + -r : Can run process with RunAs parameter. -we : Disable wait for process to exit. -param: Start process with specified parameters. Example1: ./ -u Example2: ./ -u -param + Example3: ./ -r Both examples can be used with -we parameter. "; @@ -63,10 +65,19 @@ public void Execute(string args) { args = args.Replace("-u ", ""); args = FileSystem.SanitizePath(args, s_currentDirectory); - StartApplication(args, paramApp, true, !waitForExit); return; } + + if(param == "-r") + { + args = args.Replace("-r ", ""); + args = FileSystem.SanitizePath(args, s_currentDirectory); + StartApplication(args, paramApp, false, !waitForExit,true); + return; + } + + args = FileSystem.SanitizePath(args, s_currentDirectory); StartApplication(args, paramApp, false, !waitForExit); return; } @@ -78,6 +89,13 @@ public void Execute(string args) StartApplication(args, paramApp, true, !waitForExit); return; } + + if (param == "-r") + { + args = args.Replace("-r ", ""); + StartApplication(args, paramApp, false, !waitForExit, true); + return; + } StartApplication(args, paramApp, false, !waitForExit); } catch (Exception e) @@ -92,7 +110,7 @@ public void Execute(string args) /// Path to procces required to be started. /// Arguments /// Use other user for run procces. - private void StartApplication(string inputCommand, string arg, bool admin, bool waitForExit) + private void StartApplication(string inputCommand, string arg, bool admin, bool waitForExit, bool runAs=false) { try { @@ -105,10 +123,10 @@ private void StartApplication(string inputCommand, string arg, bool admin, bool } if (admin) { - Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, true, waitForExit); + Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, true, waitForExit,runAs); return; } - Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, false, waitForExit); + Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, false, waitForExit, runAs); return; } catch (Exception e) From efac0b01bd47bc695d93024eb35549cf96654754 Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 23:22:22 +0300 Subject: [PATCH 13/31] removed -r param --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 735703e3..58d59140 100644 --- a/README.md +++ b/README.md @@ -74,12 +74,10 @@ This is the full list of commands that can be used in xTerminal: Can be used with the following parameters: -h : Displays this message. -u : Can run process with different user. - -r : Can run process with RunAs parameter. -we : Disable wait for process to exit. -param: ./ process with specified parameters. Example1: ./ -u Example2: ./ -u -param - Example3: ./ -r Both examples can be used with -we parameter. pkill -- Kills a running process by name or id. Example1: pkill From 8f39d099cb05e5749a18a9e227c3b119340765e1 Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 23:22:36 +0300 Subject: [PATCH 14/31] now runas works properly --- Commands/TerminalCommands/ConsoleSystem/StartProccess.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index 91b9da6c..378f4d8d 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -16,12 +16,10 @@ public class StartProccess : ITerminalCommand Can be used with the following parameters: -h : Displays this message. -u : Can run process with different user. - -r : Can run process with RunAs parameter. -we : Disable wait for process to exit. -param: Start process with specified parameters. Example1: ./ -u Example2: ./ -u -param - Example3: ./ -r Both examples can be used with -we parameter. "; From 711398a523386dea2c0b58ce473d2ececcc0a8fa Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 23:22:51 +0300 Subject: [PATCH 15/31] now runas works properly --- Core/SystemTools/ProcessStart.cs | 74 ++++++++++---------------------- 1 file changed, 22 insertions(+), 52 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index f3161f57..da84cfca 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -1,5 +1,4 @@ -using Core.Encryption; -using System; +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -11,7 +10,7 @@ namespace Core.SystemTools public class ProcessStart { private static string s_currentDirectory; - + private static string _cmdPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"); /// /// Execute process command. @@ -28,22 +27,10 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck var process = new Process(); bool exe = input.Trim().EndsWith(".exe") || input.Trim().EndsWith(".msi"); - string cmdPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe"); - - - // Check is execautable or not. if (asAdmin) { - arguments = $@"/c start {input} {arguments}"; - process.StartInfo.FileName = cmdPath; - process.StartInfo = new ProcessStartInfo(cmdPath); - var secureString = new System.Security.SecureString(); - if (!exe) - process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); - process.StartInfo.Arguments = arguments.Trim(); - Console.Write("User name: "); var userName = Console.ReadLine(); if (string.IsNullOrEmpty(userName)) @@ -52,25 +39,19 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck FileSystem.ErrorWriteLine("User name must be provieded!"); return; } - process.StartInfo.UserName = userName; - - Console.Write("Passwod: "); - var password = PasswordValidator.GetHiddenConsoleInput(); - if (password.Length <= 0) - { - FileSystem.ErrorWriteLine($"Password for {userName} must be provided!"); - return; - } - process.StartInfo.Password = password; - Console.WriteLine(); - Console.Write("Domain(optional): "); - var domain = Console.ReadLine() ?? string.Empty; - if (!string.IsNullOrEmpty(domain)) - process.StartInfo.Domain = domain; + arguments = $"/c runas /user:{userName} {input}"; + process.StartInfo = new ProcessStartInfo(); + process.StartInfo.FileName = _cmdPath; + var secureString = new System.Security.SecureString(); + if (!exe) + process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); + process.StartInfo.Arguments = arguments.Trim(); + process.StartInfo.UseShellExecute = true; if (!waitForExit) { process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; + process.StartInfo.RedirectStandardOutput = true; } } else @@ -79,18 +60,17 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (!exe) { arguments = $@"/c start {input} {arguments}"; - process.StartInfo.FileName = cmdPath; - fileName = cmdPath; + process.StartInfo.FileName = _cmdPath; + fileName = _cmdPath; } process.StartInfo = new ProcessStartInfo(fileName); ; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.UseShellExecute = false; - if (runAs) - process.StartInfo.Verb = "runas"; if (!waitForExit) { process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardError = true; + process.StartInfo.RedirectStandardOutput = true; } process.StartInfo.Arguments = arguments.Trim(); } @@ -146,10 +126,6 @@ public static void ProcessExecute(string input, bool asAdmin) if (asAdmin) { - process.StartInfo = new ProcessStartInfo(input) - { - UseShellExecute = false - }; Console.Write("User name: "); var userName = Console.ReadLine(); if (string.IsNullOrEmpty(userName)) @@ -158,20 +134,14 @@ public static void ProcessExecute(string input, bool asAdmin) FileSystem.ErrorWriteLine("User name must be provieded!"); return; } - process.StartInfo.UserName = userName; - Console.Write("Passwod: "); - var password = PasswordValidator.GetHiddenConsoleInput(); - if (password.Length <= 0) + var arg = $"/c runas /user:{userName} {input}"; + process.StartInfo = new ProcessStartInfo(_cmdPath) { - FileSystem.ErrorWriteLine($"Password for {userName} must be provided!"); - return; - } - process.StartInfo.Password = password; - Console.WriteLine(); - Console.Write("Domain(optional): "); - var domain = Console.ReadLine() ?? string.Empty; - if (!string.IsNullOrEmpty(domain)) - process.StartInfo.Domain = domain; + Arguments = arg, + UseShellExecute = true + }; + + process.Start(); } else { @@ -180,8 +150,8 @@ public static void ProcessExecute(string input, bool asAdmin) UseShellExecute = true, WindowStyle = ProcessWindowStyle.Normal }; + process.Start(); } - process.Start(); } catch (System.ComponentModel.Win32Exception win) { From 8b08651ac6134079a367ee966277666cc88dfc17 Mon Sep 17 00:00:00 2001 From: xeL Date: Thu, 19 Sep 2024 23:29:57 +0300 Subject: [PATCH 16/31] removed -r param parser --- .../ConsoleSystem/StartProccess.cs | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index 378f4d8d..562b66a6 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -67,14 +67,6 @@ public void Execute(string args) return; } - if(param == "-r") - { - args = args.Replace("-r ", ""); - args = FileSystem.SanitizePath(args, s_currentDirectory); - StartApplication(args, paramApp, false, !waitForExit,true); - return; - } - args = FileSystem.SanitizePath(args, s_currentDirectory); StartApplication(args, paramApp, false, !waitForExit); return; @@ -88,12 +80,6 @@ public void Execute(string args) return; } - if (param == "-r") - { - args = args.Replace("-r ", ""); - StartApplication(args, paramApp, false, !waitForExit, true); - return; - } StartApplication(args, paramApp, false, !waitForExit); } catch (Exception e) From e24d1ec33a2b3fed0e78ce1866e7071a99b69444 Mon Sep 17 00:00:00 2001 From: xeL Date: Fri, 20 Sep 2024 00:04:28 +0300 Subject: [PATCH 17/31] added filter for executable files .exe and .msi, now you don't need to write this 2 extensions --- Commands/TerminalCommands/ConsoleSystem/StartProccess.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index 562b66a6..1409383f 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -100,11 +100,18 @@ private void StartApplication(string inputCommand, string arg, bool admin, bool { int _ch = Regex.Matches(inputCommand, " ").Count; + if (File.Exists(inputCommand + ".exe")) + inputCommand = inputCommand + ".exe"; + + if (File.Exists(inputCommand + ".msi")) + inputCommand = inputCommand + ".msi"; + if (!File.Exists(inputCommand)) { FileSystem.ErrorWriteLine($"File {inputCommand} does not exist!"); return; } + if (admin) { Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, true, waitForExit,runAs); From cd6556e7c595bd840903ff16947620c92973188e Mon Sep 17 00:00:00 2001 From: xeL Date: Fri, 20 Sep 2024 00:04:48 +0300 Subject: [PATCH 18/31] set to shell execute --- Core/SystemTools/ProcessStart.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index da84cfca..9f25a6b3 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -46,7 +46,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (!exe) process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.Arguments = arguments.Trim(); - process.StartInfo.UseShellExecute = true; + process.StartInfo.UseShellExecute = false; if (!waitForExit) { process.StartInfo.RedirectStandardInput = true; @@ -72,7 +72,6 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; } - process.StartInfo.Arguments = arguments.Trim(); } // Runing non executable files. From cfdd4c6e57c7e2afa084f4cf048598af0ae74dd1 Mon Sep 17 00:00:00 2001 From: xeL Date: Sat, 21 Sep 2024 15:58:42 +0300 Subject: [PATCH 19/31] fix runas --- Core/SystemTools/ProcessStart.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 9f25a6b3..2edb6ed8 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -31,17 +31,10 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (asAdmin) { - Console.Write("User name: "); - var userName = Console.ReadLine(); - if (string.IsNullOrEmpty(userName)) - { - Console.WriteLine(); - FileSystem.ErrorWriteLine("User name must be provieded!"); - return; - } - arguments = $"/c runas /user:{userName} {input}"; + arguments = $"/c {input}"; process.StartInfo = new ProcessStartInfo(); process.StartInfo.FileName = _cmdPath; + process.StartInfo.Verb = "runas"; var secureString = new System.Security.SecureString(); if (!exe) process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); From 5b5396b5175ec049f63c07891053057685c1efdb Mon Sep 17 00:00:00 2001 From: x_coding Date: Sat, 21 Sep 2024 18:32:43 +0300 Subject: [PATCH 20/31] removed unused separator --- Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs b/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs index 402aa2e7..e6aa52a3 100644 --- a/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs +++ b/Commands/TerminalCommands/ConsoleSystem/NewTWindow.cs @@ -25,10 +25,10 @@ public void Execute(string args) } if (args.ContainsText("-u")) { - Core.SystemTools.ProcessStart.ProcessExecute(Application.StartupPath + "\\xTerminal.exe", true); + Core.SystemTools.ProcessStart.ProcessExecute(Application.StartupPath + "xTerminal.exe", true); return; } - Core.SystemTools.ProcessStart.ProcessExecute(Application.StartupPath + "\\xTerminal.exe", false); + Core.SystemTools.ProcessStart.ProcessExecute(Application.StartupPath + "xTerminal.exe", false); } } } From 5f9af3e6061a41b8cc46fe966f3b7ac872c2d459 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sat, 21 Sep 2024 18:32:59 +0300 Subject: [PATCH 21/31] fix path for -u param --- Commands/TerminalCommands/ConsoleSystem/StartProccess.cs | 6 +++--- Core/SystemTools/ProcessStart.cs | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index 1409383f..c98a14aa 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -94,7 +94,7 @@ public void Execute(string args) /// Path to procces required to be started. /// Arguments /// Use other user for run procces. - private void StartApplication(string inputCommand, string arg, bool admin, bool waitForExit, bool runAs=false) + private void StartApplication(string inputCommand, string arg, bool admin, bool waitForExit) { try { @@ -114,10 +114,10 @@ private void StartApplication(string inputCommand, string arg, bool admin, bool if (admin) { - Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, true, waitForExit,runAs); + Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, true, waitForExit); return; } - Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, false, waitForExit, runAs); + Core.SystemTools.ProcessStart.ProcessExecute(inputCommand, arg, true, false, waitForExit); return; } catch (Exception e) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 2edb6ed8..037ff97f 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -20,7 +20,7 @@ public class ProcessStart /// /// /// - public static void ProcessExecute(string input, string arguments, bool fileCheck, bool asAdmin, bool waitForExit, bool runAs = false) + public static void ProcessExecute(string input, string arguments, bool fileCheck, bool asAdmin, bool waitForExit) { try { @@ -31,7 +31,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (asAdmin) { - arguments = $"/c {input}"; + arguments = "/c "+"\""+input+"\""; process.StartInfo = new ProcessStartInfo(); process.StartInfo.FileName = _cmdPath; process.StartInfo.Verb = "runas"; @@ -126,13 +126,14 @@ public static void ProcessExecute(string input, bool asAdmin) FileSystem.ErrorWriteLine("User name must be provieded!"); return; } + Console.WriteLine(input); + Console.ReadLine(); var arg = $"/c runas /user:{userName} {input}"; process.StartInfo = new ProcessStartInfo(_cmdPath) { Arguments = arg, UseShellExecute = true }; - process.Start(); } else From 92ddc13a83546fe5b30bfad79c0505c7742eddad Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 18:34:13 +0300 Subject: [PATCH 22/31] added new method for odir command --- Core/FileSystem.cs | 5 +++-- Core/SystemTools/ProcessStart.cs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Core/FileSystem.cs b/Core/FileSystem.cs index 36594a6d..e68c1dc1 100644 --- a/Core/FileSystem.cs +++ b/Core/FileSystem.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualBasic; +using Core.SystemTools; +using Microsoft.VisualBasic; using System; using System.Buffers.Binary; using System.Collections.Generic; @@ -233,7 +234,7 @@ public static void OpenCurrentDiretory(string dirPath, string currentDirectory) dirPath = SanitizePath(dirPath, currentDirectory); if (Directory.Exists(dirPath)) { - SystemTools.ProcessStart.ProcessExecute("explorer", dirPath, false, false, false); + ProcessStart.OpenDirProc(dirPath); return; } Console.WriteLine($"Directory '{dirPath}' does not exist!"); diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 037ff97f..7348827c 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -52,11 +52,10 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck var fileName = input; if (!exe) { - arguments = $@"/c start {input} {arguments}"; + arguments = $@"/c start {input} ""{arguments}"""; process.StartInfo.FileName = _cmdPath; fileName = _cmdPath; } - process.StartInfo = new ProcessStartInfo(fileName); ; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.UseShellExecute = false; if (!waitForExit) @@ -105,6 +104,19 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck } } + /// + /// Open current directory. + /// + /// + public static void OpenDirProc(string path) + { + var process = new Process(); + process.StartInfo = new ProcessStartInfo("explorer"); + process.StartInfo.UseShellExecute = false; + process.StartInfo.Arguments = path.Trim(); + process.Start(); + } + /// /// Process execution in separate window with no args. /// From 067bb113d3211c34b66c3b999f60b6b698161d8a Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 19:08:35 +0300 Subject: [PATCH 23/31] fix run on normal --- Core/SystemTools/ProcessStart.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 7348827c..7ddff42e 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -26,6 +26,10 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck { var process = new Process(); + //process.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; + //process.StartInfo.StandardInputEncoding = System.Text.Encoding.UTF8; + //process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; + bool exe = input.Trim().EndsWith(".exe") || input.Trim().EndsWith(".msi"); @@ -50,14 +54,19 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck else { var fileName = input; + if (!exe) { - arguments = $@"/c start {input} ""{arguments}"""; - process.StartInfo.FileName = _cmdPath; + if(string.IsNullOrEmpty(arguments)) + arguments = $@"/c ""{input}"""; + else + arguments = $@"/c ""{input}"" ""{arguments}"""; fileName = _cmdPath; } + process.StartInfo.FileName = fileName; process.StartInfo.WorkingDirectory = Path.GetDirectoryName(input); process.StartInfo.UseShellExecute = false; + process.StartInfo.Arguments = arguments; if (!waitForExit) { process.StartInfo.RedirectStandardInput = true; From c02103b0c6472366cb76c373d937b8b897f04385 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 19:34:47 +0300 Subject: [PATCH 24/31] fix parse argument for -u aswell --- Core/SystemTools/ProcessStart.cs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 7ddff42e..6b03843a 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -35,7 +35,15 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck if (asAdmin) { - arguments = "/c "+"\""+input+"\""; + var arg = arguments; + var inp = input; + if (!string.IsNullOrEmpty(arguments) && arguments.Contains(" ")) + { + arg = $"\"{arguments}\""; + arguments = "/c " + "\"" + input + "\""; + } + else + arguments = "/c " + "\"" + input + "\"" + $" {arg}"; process.StartInfo = new ProcessStartInfo(); process.StartInfo.FileName = _cmdPath; process.StartInfo.Verb = "runas"; @@ -54,13 +62,26 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck else { var fileName = input; - + if (!exe) { - if(string.IsNullOrEmpty(arguments)) - arguments = $@"/c ""{input}"""; + if (string.IsNullOrEmpty(arguments)) + { + if (input.Contains(" ")) + arguments = $@"/c ""{input}"""; + else + arguments = $@"/c {input}"; + } else - arguments = $@"/c ""{input}"" ""{arguments}"""; + { + var inp = input; + if (input.Contains(" ")) + inp = $"\"{input}\""; + var arg = arguments; + if (arguments.Contains(" ")) + arg = $"\"{arguments}\""; + arguments = $@"/c {inp} {arg}"; + } fileName = _cmdPath; } process.StartInfo.FileName = fileName; From fadf3f0f80d21a72367e0b7e4cf8f2e4fb3ba127 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:25:32 +0300 Subject: [PATCH 25/31] created command enc for set console input/output encoding --- .../ConsoleSystem/ConsoleEncoding.cs | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs diff --git a/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs b/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs new file mode 100644 index 00000000..d7a15ff0 --- /dev/null +++ b/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs @@ -0,0 +1,79 @@ +using Core; +using System; +using System.Runtime.Versioning; +using System.Text; + +namespace Commands.TerminalCommands.ConsoleSystem +{ + [SupportedOSPlatform("windows")] + public class ConsoleEncoding : ITerminalCommand + { + public string Name => "enc"; + private static string s_helpMessage = $@" Usage of enc command: + enc defalut : Set input/output encoding to system default .NET encoding. + enc utf8 : Set input/output encoding to system UTF8. + enc unicode : Set input/output encoding to system Unicode. + enc ascii : Set input/output encoding to system ascii. + enc -current : Show the current input/output encoding. +"; + public void Execute(string arg) + { + if (arg == Name) + { + FileSystem.SuccessWriteLine("Use -h for more information!"); + return; + } + + arg = arg.Substring(3).Trim().ToLower(); + + // Display help message. + if (arg.Trim() == "-h") + { + Console.WriteLine(s_helpMessage); + return; + } + + if(arg == "-current") + { + var encodingIn = Console.InputEncoding.EncodingName; + var encodingOut = Console.OutputEncoding.EncodingName; + var dataDisplay = $"Input encoding: {encodingIn}\nOutput encoding: {encodingOut}"; + FileSystem.SuccessWriteLine(dataDisplay); + return; + } + + if (arg == "utf8") + { + Console.InputEncoding = Encoding.UTF8; + Console.OutputEncoding = Encoding.UTF8; + FileSystem.SuccessWriteLine($"Console encoding set to: {Console.InputEncoding.EncodingName}"); + return; + } + + if (arg == "unicode") + { + Console.InputEncoding = Encoding.Unicode; + Console.OutputEncoding = Encoding.Unicode; + FileSystem.SuccessWriteLine($"Console encoding set to: {Console.InputEncoding.EncodingName}"); + return; + } + + if (arg == "default") + { + Console.InputEncoding = Encoding.Default; + Console.OutputEncoding = Encoding.Default; + FileSystem.SuccessWriteLine($"Console encoding set to: {Console.InputEncoding.EncodingName}"); + return; + } + + if (arg == "ascii") + { + Console.InputEncoding = Encoding.ASCII; + Console.OutputEncoding = Encoding.ASCII; + FileSystem.SuccessWriteLine($"Console encoding set to: {Console.InputEncoding.EncodingName}"); + return; + } + FileSystem.ErrorWriteLine("The encode type is not part of the lis. Use -h for more information!"); + } + } +} From df498e142b022b15c30fc6915d6a8e53d1ba3b14 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:26:00 +0300 Subject: [PATCH 26/31] cleanup --- Commands/TerminalCommands/ConsoleSystem/StartProccess.cs | 2 ++ Core/SystemTools/ProcessStart.cs | 5 +---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs index c98a14aa..52432755 100644 --- a/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs +++ b/Commands/TerminalCommands/ConsoleSystem/StartProccess.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Runtime.Versioning; +using System.Text; using System.Text.RegularExpressions; namespace Commands.TerminalCommands.ConsoleSystem @@ -63,6 +64,7 @@ public void Execute(string args) { args = args.Replace("-u ", ""); args = FileSystem.SanitizePath(args, s_currentDirectory); + StartApplication(args, paramApp, true, !waitForExit); return; } diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index 6b03843a..c2d8f01c 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -26,10 +26,7 @@ public static void ProcessExecute(string input, string arguments, bool fileCheck { var process = new Process(); - //process.StartInfo.StandardErrorEncoding = System.Text.Encoding.UTF8; - //process.StartInfo.StandardInputEncoding = System.Text.Encoding.UTF8; - //process.StartInfo.StandardOutputEncoding = System.Text.Encoding.UTF8; - + bool exe = input.Trim().EndsWith(".exe") || input.Trim().EndsWith(".msi"); From 3f913db5e23031eab39e0238a0677e9f16e502bd Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:26:16 +0300 Subject: [PATCH 27/31] fix input to UTF 8 --- Shell/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shell/Program.cs b/Shell/Program.cs index 86073e86..90cbafd0 100644 --- a/Shell/Program.cs +++ b/Shell/Program.cs @@ -58,8 +58,8 @@ private static void DeleteCDFIle() static void Main(string[] args) { - // confgure console - Console.OutputEncoding = System.Text.Encoding.UTF8;//set utf8 encoding (for support Russian letters) + Console.InputEncoding = System.Text.Encoding.UTF8; + Console.OutputEncoding = System.Text.Encoding.UTF8; DeleteCDFIle(); var shell = new Shell(); shell.Run(args);//Running the shell From 88800695c138f13540af83feb29b8a19d998cebe Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:29:39 +0300 Subject: [PATCH 28/31] cleanup message help --- .../TerminalCommands/ConsoleSystem/ConsoleEncoding.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs b/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs index d7a15ff0..d8a9ae9c 100644 --- a/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs +++ b/Commands/TerminalCommands/ConsoleSystem/ConsoleEncoding.cs @@ -10,11 +10,13 @@ public class ConsoleEncoding : ITerminalCommand { public string Name => "enc"; private static string s_helpMessage = $@" Usage of enc command: - enc defalut : Set input/output encoding to system default .NET encoding. - enc utf8 : Set input/output encoding to system UTF8. - enc unicode : Set input/output encoding to system Unicode. - enc ascii : Set input/output encoding to system ascii. + enc defalut : Set input/output encoding to default .NET encoding. + enc utf8 : Set input/output encoding to UTF8. + enc unicode : Set input/output encoding to Unicode. + enc ascii : Set input/output encoding to ASCII. enc -current : Show the current input/output encoding. + +Default input/output encoding for xTerminal is UTF-8. "; public void Execute(string arg) { From 8aebf47fc77e2e1c524ec4d80d170b5c0d9eba36 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:31:59 +0300 Subject: [PATCH 29/31] updated documetation and help command with enc command --- Commands/TerminalCommands/ConsoleSystem/Help.cs | 1 + README.md | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Commands/TerminalCommands/ConsoleSystem/Help.cs b/Commands/TerminalCommands/ConsoleSystem/Help.cs index eed63d78..80f8e16d 100644 --- a/Commands/TerminalCommands/ConsoleSystem/Help.cs +++ b/Commands/TerminalCommands/ConsoleSystem/Help.cs @@ -54,6 +54,7 @@ public void Execute(string arg) time -- Display current time. sc -- Manage local or remote computer services. Use -h for additional help. fw -- Manage local firewall rules. Use -h for additional help. + enc -- Set input/output encoding for xTerminal. Use -h for additional help. ---------------------- File System --------------------- cat -- Displays the content of a file. Use -h for additional parameters. diff --git a/README.md b/README.md index 58d59140..cacb1eaa 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,13 @@ This is the full list of commands that can be used in xTerminal: 58 : ICMPv6 Note: Requires administrator privileges. + enc -- Set input/output encoding for xTerminal. + enc defalut : Set input/output encoding to default .NET encoding. + enc utf8 : Set input/output encoding to UTF8. + enc unicode : Set input/output encoding to Unicode. + enc ascii : Set input/output encoding to ASCII. + enc -current : Show the current input/output encoding. + ---------------------- File System --------------------- cat -- Displays the content of a file. Use -h for additional parameters. From 3c73ac73b8b4d08c8b937dc0a02ef10452c628ca Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:38:54 +0300 Subject: [PATCH 30/31] version change --- Shell/Properties/AssemblyInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shell/Properties/AssemblyInfo.cs b/Shell/Properties/AssemblyInfo.cs index 8b872858..ce73e498 100644 --- a/Shell/Properties/AssemblyInfo.cs +++ b/Shell/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.9.0.2")] -[assembly: AssemblyFileVersion("1.9.0.2")] +[assembly: AssemblyVersion("1.9.1")] +[assembly: AssemblyFileVersion("1.9.1")] From abe08b3a2041409fbb14fb0e0a1c5f78fd033b52 Mon Sep 17 00:00:00 2001 From: x_coding Date: Sun, 22 Sep 2024 22:39:01 +0300 Subject: [PATCH 31/31] removed console.readline() --- Core/SystemTools/ProcessStart.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Core/SystemTools/ProcessStart.cs b/Core/SystemTools/ProcessStart.cs index c2d8f01c..f6813d7a 100644 --- a/Core/SystemTools/ProcessStart.cs +++ b/Core/SystemTools/ProcessStart.cs @@ -166,7 +166,6 @@ public static void ProcessExecute(string input, bool asAdmin) return; } Console.WriteLine(input); - Console.ReadLine(); var arg = $"/c runas /user:{userName} {input}"; process.StartInfo = new ProcessStartInfo(_cmdPath) {