-
Notifications
You must be signed in to change notification settings - Fork 1
/
Timer.cs
executable file
·84 lines (81 loc) · 5.14 KB
/
Timer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Timer
{
class Program
{
public static Char cQuote;
private static System.Timers.Timer oTimer;
public static String sExecLine;
public static String sExecArgs;
public static Boolean bOnlyOneTime;
public static Boolean bUnhide;
static void Main(string[] args)
{
bUnhide = false;
bOnlyOneTime = false;
cQuote = Convert.ToChar(34);
System.Console.WriteLine("*******************************************************************************");
System.Console.WriteLine("* *");
System.Console.WriteLine("* Timer v0.0.1 *");
System.Console.WriteLine("* *");
System.Console.WriteLine("* Runs a hidden command after a timer has expired. *");
System.Console.WriteLine("* *");
System.Console.WriteLine("* use: Timer iTimer1 sExecutable [sArguments] [--unhide] *");
System.Console.WriteLine("* iTimer1 runs the executable after this timer in miliseconds *");
System.Console.WriteLine("* sExecutable executable file *");
System.Console.WriteLine("* sArguments argument string *");
System.Console.WriteLine("* --unhide show the console for debugging purposes. *");
System.Console.WriteLine("* *");
System.Console.WriteLine("* Example: *");
System.Console.WriteLine("* Timer 3600000 " + cQuote + "cmd.exe" + cQuote + " " + cQuote + "/C copy /b Image1.jpg + Archive.rar Image2.jpg" + cQuote + " *");
System.Console.WriteLine("* *");
System.Console.WriteLine("* Copyright (c) 2014 Geert-Jan Uijtdewilligen *");
System.Console.WriteLine("* This is free open source software that comes with no warranty, and you are *");
System.Console.WriteLine("* welcome to redistribute it under the terms of the GNU General Public License*");
System.Console.WriteLine("* as published by the Free Software Foundation https://www.gnu.org/licenses/ *");
System.Console.WriteLine("* *");
System.Console.WriteLine("*******************************************************************************");
if (args.Length != 4 && args.Length != 3 && args.Length != 2)
{
System.Console.WriteLine("Please enter arguments: time(ms), executable to run, arguments");
}
else
{
// Create a timer with a x millisecond interval.
int iMiliSec = 0;
sExecLine = args[1];
if (iMiliSec == 0) { bOnlyOneTime = true; iMiliSec = Int32.Parse(args[0]); }
if (args.Length == 4) if (args[3] == "--unhide") { bUnhide = true; sExecArgs = args[2]; } else { sExecArgs = args[2]; }
if (args.Length == 3) if (args[2] == "--unhide") { bUnhide = true; sExecArgs = ""; } else { sExecArgs = args[2]; }
oTimer = new System.Timers.Timer(iMiliSec);
// Hook up the Elapsed event for the timer.
oTimer.Elapsed += oOnTimedEvent;
oTimer.Enabled = true;
Console.WriteLine("Press the Enter key to exit the program... ");
if (bOnlyOneTime) while (oTimer.Enabled) { }
else Console.ReadLine();
Console.WriteLine("Terminating the application...");
}
}
private static void oOnTimedEvent(Object source, ElapsedEventArgs eElapsed)
{
Console.WriteLine("The Elapsed event was raised at {0}", eElapsed.SignalTime);
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
if (bUnhide) startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
startInfo.FileName = sExecLine;
startInfo.Arguments = sExecArgs;
process.StartInfo = startInfo;
process.Start();
if (bOnlyOneTime) oTimer.Enabled = false;
}
}
}