78 lines
2.8 KiB
C#
78 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NX_Installation
|
|
{
|
|
class Task
|
|
{
|
|
public void CreateLoginTask(string Platform)
|
|
{
|
|
//Abfragen ob Scheduled Task schon existiert
|
|
//bool taskAlreadyExist = TaskAlreadyExist("3DconnexionSkipUAC");
|
|
if (TaskAlreadyExist("3DconnexionSkipUAC"))
|
|
{
|
|
//Console.WriteLine("\nScheduled task already exists.");
|
|
}
|
|
else
|
|
{
|
|
CreateNewTask("3DconnexionSkipUAC", Platform);
|
|
}
|
|
}
|
|
|
|
//Abfragen ob Scheduled Task schon existiert
|
|
private bool TaskAlreadyExist(string taskname)
|
|
{
|
|
ProcessStartInfo start = new ProcessStartInfo();
|
|
start.FileName = "schtasks.exe"; // Specify exe name.
|
|
start.UseShellExecute = false;
|
|
start.CreateNoWindow = true;
|
|
start.WindowStyle = ProcessWindowStyle.Hidden;
|
|
start.Arguments = "/query /TN " + taskname;
|
|
start.RedirectStandardOutput = true;
|
|
// Start the process.
|
|
using (Process process = Process.Start(start))
|
|
{
|
|
// Read in all the text from the process with the StreamReader.
|
|
using (StreamReader reader = process.StandardOutput)
|
|
{
|
|
string stdout = reader.ReadToEnd();
|
|
if (stdout.Contains(taskname))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//Scheduled Task anlegen, welcher den Spacemouse Server beim Einloggen mit Administrator Rechten starten
|
|
private void CreateNewTask(string taskname, string Platform)
|
|
{
|
|
string program = Environment.GetEnvironmentVariable("ProgramFiles");
|
|
if (Platform == "64bit" & program.Contains("x86"))
|
|
{
|
|
program = program.Replace(" (x86)", "");
|
|
}
|
|
program = program + @"\3Dconnexion\3Dconnexion 3DxSoftware\3DxWare64\3dxsrv.exe";
|
|
|
|
ProcessStartInfo start = new ProcessStartInfo();
|
|
start.FileName = "schtasks.exe"; // Specify exe name.
|
|
start.UseShellExecute = false;
|
|
start.CreateNoWindow = true;
|
|
start.WindowStyle = ProcessWindowStyle.Hidden;
|
|
start.Arguments = "/create /TN " + taskname + " /TR '\"" + program + "\"' /RL highest /SC onlogon";
|
|
start.RedirectStandardOutput = true;
|
|
// Start the process.
|
|
Process process = Process.Start(start);
|
|
}
|
|
}
|
|
}
|