Commit dd744261d878d8511e96873c8d2a42fbe2fe5622

Authored by Schwirg László
1 parent c8f97de8

v1.34.3.0

- RunEXEOnRemoteComputer hozzáadása; még nem OK
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
@@ -1541,17 +1541,46 @@ GO @@ -1541,17 +1541,46 @@ GO
1541 finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } 1541 finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); }
1542 } 1542 }
1543 1543
1544 - private static void RunEXEOnRemoteComputer(string servername,string username, string password, string exefilename)  
1545 - {  
1546 - var processToRun = new[] { exefilename/*"notepad.exe"*/ };  
1547 - var connection = new ConnectionOptions();  
1548 - connection.Username = username;  
1549 - connection.Password = password;  
1550 - var wmiScope = new ManagementScope(String.Format(@"\\{0}\root\cimv2", servername), connection);  
1551 - var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions());  
1552 - wmiProcess.InvokeMethod("Create", processToRun);  
1553 - } 1544 + internal static void RunEXEOnRemoteComputer(string servername,string username, string password, string sourcePath, string targetPath, bool usecopy=false)
  1545 + {
  1546 + ConnectionOptions options = new ConnectionOptions
  1547 + {
  1548 + Username = username,
  1549 + Password = password,
  1550 + EnablePrivileges = true,
  1551 + Impersonation = ImpersonationLevel.Impersonate
  1552 + };
  1553 +
  1554 + ManagementScope scope = new ManagementScope($@"\\{servername}\root\cimv2", options);
  1555 + try
  1556 + {
  1557 + scope.Connect();
  1558 +
  1559 + ObjectGetOptions objectGetOptions = new ObjectGetOptions();
  1560 + ManagementPath path = new ManagementPath("Win32_Process");
  1561 + ManagementClass fileService = new ManagementClass(scope, path, objectGetOptions);
  1562 + string com = usecopy ? "copy" : "move";//"copy"
  1563 + ManagementBaseObject inParams = fileService.GetMethodParameters("Create");
  1564 + inParams["CommandLine"] = "cmd.exe /c echo Hello from remote computer";
  1565 + //inParams["CommandLine"] = $"cmd.exe /c {com} \"{sourcePath}\" \"{targetPath}\"";
  1566 + ManagementBaseObject outParams = fileService.InvokeMethod("Create", inParams, null);
  1567 +
  1568 + Console.WriteLine("Process ID: " + outParams["ProcessId"]);
  1569 + Console.WriteLine("Return Value: " + outParams["ReturnValue"]);
  1570 + }
  1571 + catch (Exception ex)
  1572 + {
  1573 + Console.WriteLine("An error occurred: " + ex.Message);
  1574 + }
  1575 + //servername = @"ROCMP-alm01";
  1576 + //string sourcedir = @"f:\Log4ProISBackups\";
  1577 + //string sourcefile = @"Log4ProIS_ROCMP_ALMOLD_LearALM_DBBACKUP__20250514135117.zip";
  1578 + //sourcePath = Path.Combine(sourcedir,sourcefile);
  1579 + //string targetdir = @"\\"+ servername + @"\f$\log4proisbackups\";
  1580 + //string targetfile = @"aaa.bbb";
  1581 + //targetPath = Path.Combine(targetdir, targetfile);
1554 1582
  1583 + }
1555 1584
1556 /// <summary> 1585 /// <summary>
1557 /// Create SQL DB backup 1586 /// Create SQL DB backup
Vrh.Log4Pro.MaintenanceConsole/Program.cs
@@ -39,9 +39,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole @@ -39,9 +39,13 @@ namespace Vrh.Log4Pro.MaintenanceConsole
39 { 39 {
40 static void Main(string[] args) 40 static void Main(string[] args)
41 { 41 {
  42 +
  43 + //SQLDataBaseManagerCore.RunEXEOnRemoteComputer(@"ROCMP-DTM01",@"corplear\gen_vrhalmadmin", "ALMforLear@-2024Q3##", @"\\ROCMP-DTM01\f$\Log4ProISBackups\TEST.txt", @"\\ROCMP-ALM01\f$\Log4ProISBackups\TST2" + (DateTime.Now.Ticks).ToString()+@".txt", true);
  44 + //SQLDataBaseManagerCore.RunEXEOnRemoteComputer(@"DESKTOP-1RNSI2E", "lschwirg", "Slsl23142314", @"c:\TMP\TEST.txt", @"c:\TMP\TEST" + (DateTime.Now.Ticks).ToString()+@".txt", true);
42 //bool xxxx = new TimeSpan(0, 0, 15).Add(new TimeSpan(0, 0, 25).Negate()).Ticks > 0; 45 //bool xxxx = new TimeSpan(0, 0, 15).Add(new TimeSpan(0, 0, 25).Negate()).Ticks > 0;
43 - //return;  
44 - var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE); 46 + Console.ReadLine();
  47 + return;
  48 + var forcedmodulekey = CommandLine.GetCommandLineArgument(args, CLP.CMD_MODULE);
45 var commandmode = !string.IsNullOrEmpty(forcedmodulekey); 49 var commandmode = !string.IsNullOrEmpty(forcedmodulekey);
46 var silentmode = commandmode && !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, CLP.CMD_SILENT, switchtype: true)); 50 var silentmode = commandmode && !string.IsNullOrEmpty(CommandLine.GetCommandLineArgument(args, CLP.CMD_SILENT, switchtype: true));
47 ColorConsole.SilentMode=silentmode; 51 ColorConsole.SilentMode=silentmode;
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; @@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
32 // You can specify all the values or you can default the Build and Revision Numbers 32 // You can specify all the values or you can default the Build and Revision Numbers
33 // by using the '*' as shown below: 33 // by using the '*' as shown below:
34 // [assembly: AssemblyVersion("1.0.*")] 34 // [assembly: AssemblyVersion("1.0.*")]
35 -[assembly: AssemblyVersion("1.34.2.0")]  
36 -[assembly: AssemblyFileVersion("1.34.2.0")] 35 +[assembly: AssemblyVersion("1.34.3.0")]
  36 +[assembly: AssemblyFileVersion("1.34.3.0")]