var cmdText = $"cd /d "{TvInstallDirectory}"";
cmdText += Environment.NewLine;
cmdText += $"TeamViewer.exe assign --api-token {tvApiToken} --reassign";
cmdText += Environment.NewLine;
cmdText += "exit /b %errorlevel%"; // ensure the process returns the TeamViewer command exit code
batFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".bat");
File.WriteAllText(batFilePath, cmdText);
var startInfo = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $"/c "{batFilePath}"",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
// the evaluated permission is required, or the re-assign will not work even without error (tested)
Verb = "runas",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
// TeamViewer will start a new process to do the re-assignment job, and the new process should be
// closed to release the resource after the job is done. And this will not affect the previously
// running TeamViewer process.
using (var tv = Process.Start(startInfo))
{
// ReSharper disable once PossibleNullReferenceException -- exception will be catched
tv.WaitForExit(60000);
// Check exit code of the process to ensure assignment was successful
if (tv.ExitCode != 0)
{
Log(LogLevel.Error, $"TeamViewer assignment failed. Exit code: {tv.ExitCode}");
return false;
}
}
this is my code am getting 201
do you know what is reason ?