Greetings SO Community
I'm writing a c# program to manage the uwfmgr registry exclusions.
I execute the following command.
uwfmgr registry get-exclusions.
Afterwards, when I want to read the registry, I get an exception with the message:
No more data is available.
This problem persists until the next reboot.
I suspect, that uwfmgr does not release the registry key properly.
I've made a minimal example to demonstrate the error.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32;
namespace WindowsFormsApplication2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
try
{
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = "C:\\Windows\\Sysnative\\uwfmgr.exe";
proc.StartInfo.Arguments = "registry get-exclusions";
proc.Start();
proc.WaitForExit();
string output = proc.StandardOutput.ReadToEnd();
string[] subkeys = Registry.LocalMachine.GetSubKeyNames();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
}
}
}
}
Info:
CLR is ".Net Framework 4.5".
Target is "Any CPU".
The executing system is "Windows Embedded 8.1 Industry Pro".
The architecture is 64bit.
Now, is there any possible way to force uwfmgr to release the registry?
PS: This is my first post. I tried to post according to the rules, but if I forgot something, please kindly remind me. Thanks.
Related
i have two WPF Application say WPFApplication1 and WPFApplication2 , WPFApplication1 has reference of WPFApplication2 , now i am calling one class of WPFApplication2 in WPFApplication1 using reference, and from WPFApplication2 class creating App class instance of WPFApplication2 , so i am facing issue like below
Error
Please help me out with this, THanks in Advance
Look at Process.Start and ProcessStartInfo
Here is an example for Console application. But there are not different how to start other application.
By ProcessStartInfo you can specify many things like Are you has to wait it? Or run without waiting. Is you want to redirect output? And so one.
using System.Diagnostics;
class Program
{
static void Main()
{
LaunchCommandLineApp();
}
/// <summary>
/// Launch the application with some options set.
/// </summary>
static void LaunchCommandLineApp()
{
// For the example
const string ex1 = "C:\\";
const string ex2 = "C:\\Dir";
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch
{
// Log error.
}
}
}
I want to make an updating exe that when i click on it either it will download or uploads data. The problem is that whenever i execute git pull origin master i have to enter the password.
This is what i tried:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace GitUpdate
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("GIT updating");
Process cmd = new Process();
cmd.StartInfo.FileName = "git";
cmd.StartInfo.Arguments = "git pull origin master";
cmd.StartInfo.RedirectStandardInput = true;
cmd.StartInfo.RedirectStandardOutput = true;
cmd.StartInfo.CreateNoWindow = true;
cmd.StartInfo.UseShellExecute = false;
cmd.Start();
cmd.StandardInput.WriteLine("MY_PASSWORD_HERE");
cmd.StandardInput.Flush();
cmd.StandardInput.Close();
cmd.WaitForExit();
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
Console.WriteLine("GIT updated ...");
Console.Read();
}
}
}
What am i doing wrong?
Also i know that there are git libraries for C# and options to remember the password, but i want to make it exe style, really need this.
Good day guys.
Currently, I am developing a code to execute a Teraterm macro which I had saved as a *.ttl file. The name of the file is "new.ttl" and the content is as below:
showtt 0
filedelete 'a.txt'
pause 5
:Close
closett
So, the logic is just to delete "a.txt" file, wait for 5 seconds and close Teraterm. This new.ttl works perfectly when I run it manually using Teraterm, where I load the macro in the tab control>macro. This simple .ttl file is just for some trial for me before I start to write a more complex code.
Now, I tried to launch the .ttl file using C#. The code is as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading;
using System.Diagnostics;
namespace TeraTermConnect
{
class Program
{
static void Main(string[] args)
{
//Declare process for .ttl
Process process = new Process();
ProcessStartInfo start = new ProcessStartInfo();
//variables
string ttlpath = #"C:\TeraTermConnect\TeraTermConnect";
string ttl = "new.ttl";
string ttpHidden = #"/V";
//start the .ttl file
start.FileName = ttlpath;
start.Arguments = ttpHidden + ttl;
start.UseShellExecute = false;
//Tried a lot of thing here, not sure how to run the .ttl
Process.Start(start);
Thread.Sleep(5000);
Console.WriteLine("The process is over");
Console.WriteLine();
Console.WriteLine("Check the text file...");
Console.WriteLine();
Console.WriteLine("Hit enter to exit...");
Console.ReadKey();
}
}
}
The execution runs without any error, but, the result is not as expected. After the execution, I can see "a.txt" is still inside the mentioned path as in the code. I am not sure where I went wrong. This is just a starting step for me before I develop a more complex .ttl file and execute it through c#.
Your help is deeply appreciated. Thank you very much.
Good day guys,
After 2 days of struggle, I managed to get the answer.
using System;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace TeraTermConnect
{
class Program
{
static void Main(string[] args)
{
//Declare process for .ttl
Process process = new Process();
ProcessStartInfo start = new ProcessStartInfo();
//variables
string ttlpath = #"C:\Program Files (x86)\teraterm\" + #"TTPMACRO";
string ttl = "new.ttl";
string ttpHidden = #"/V ";
ProcessStartInfo start = new ProcessStartInfo();
//start the .ttl file
start.FileName = ttlpath;
start.Arguments = ttpHidden + ttl;
start.UseShellExecute = false;
process.StartInfo = start;
try
{
Process.Start(start);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Console.WriteLine("The process is over");
Console.WriteLine();
Console.WriteLine("Check the text file...");
Console.WriteLine();
Console.WriteLine("Hit enter to exit...");
Console.ReadKey();
}
}
}
The version of Teraterm that i am currently using is 4.94 and I had also installed TTLEditor version 1.5 to create the .TTL file. It seems that the problem was,
1) To execute a .TTL file programmatically from C#, I need to place the .TTL file in the same folder where TTPMACRO.EXE and TTERMPRO.EXE is located in my system. This is shown by the string value ttlpath in my code.
2) In the ttlpath, the string value #"TTPMACRO" need to be added to the folder as this will make the .TTL file to be executable.
And, for your info, in my system, the text file a.txt that will be deleted if the logic of the .TTL file is executed is located at:
C:\Users\Admin\AppData\Local\VirtualStore\Program Files (x86)\teraterm
For more info on how to run teraterm macro files, refer to this link;
https://ttssh2.osdn.jp/manual/en/macro/howtorun.html
have a nice day..
Hari
As I aksed in another post, I am trying to automate running processing ide from c#. Finally I found the way to run the processing sketch via cmd, with setting the installed processing folder in the path of evironment variable.
I find it works with inputting command directly in cmd.exe, but when I want to do the same thing through some c# code in Visual Studio, it doesn't run the .pde file.
Here is the code,
using System;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Runprocessing
{
static void Main()
{
Process process = new Process();
ProcessStartInfo stinfo = new ProcessStartInfo();
stinfo.FileName = "cmd.exe";
stinfo.Arguments = "/c"+"processing-java --run --sketch=D:\\pw --output=D:\\pw\\output";
stinfo.CreateNoWindow = true;
stinfo.UseShellExecute = false;
process = Process.Start(stinfo);
process.WaitForExit();
process.Close();
process.Dispose();
}
}
}
My question is, how should I properly use processing-java to activate the sketch. because here I am stating
stinfo.FileName = "cmd.exe";
stinfo.Arguments = "/c"+"processing-java --run --sketch=D:\\pw --output=D:\\pw\\output";
Is this the right way to use processing-java in cmd?
I am testing a C# WPF program that requires elevated privileges, that loads without any delay if I am logged on as an admin, but if I am logged on as a standard user (99% of time) then there is a delay of about 30 seconds before the UI appears.
Using the same elevation code in a C# console app and in a c# Winforms app, there is no delay in loading, so I know that the code works.
So, can anyone explain to me why is there a delay associated with WPF; and is there a workaround?
Here is the code from app.xaml.cs ( the remainder of the project is as genereated by VS2010)
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Security.Principal;
using System.Diagnostics;
using System.Reflection;
using System.ComponentModel;
using MyNewServiceLib;
using System.Runtime.InteropServices;
namespace WhySoSlow
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (!IsAdmin())
{
StartAsAdmin(e);
Application.Current.Shutdown();
}
else
{
MainWindow = new MainWindow();
MainWindow.SizeToContent = SizeToContent.WidthAndHeight;
MainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
MainWindow.Show();
}
}
bool IsAdmin()
{
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal p = new WindowsPrincipal(id);
return p.IsInRole(WindowsBuiltInRole.Administrator);
}
private void StartAsAdmin(StartupEventArgs e)
{
string[] args = e.Args;
try
{
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.UseShellExecute = true;
startInfo.WorkingDirectory = Environment.CurrentDirectory;
Uri uri = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase);
startInfo.FileName = uri.LocalPath;
startInfo.Arguments = String.Join(" ", args);
startInfo.Verb = "runas";
Process p = Process.Start(startInfo);
}
catch (Win32Exception exception)
{
MessageBox.Show(exception.Message);
}
}
}
}
Further info
Weirdly, if I start the program from a cmd prompt running under NT Authority\System, there is no delay starting up the UI. After that one successful start, every further start, from whatever prompt, be it standard user prompt, run as administrator, the program starts without delay; UNTIL that is, I log off from the session.
After logging on again to a new (standard user) session, all attempts to start the program result in the 30 second delay before showing the UI.
I can only think that this is some kind of UAC bodge by Microsoft, that is hindering the startup of wpf.
Instead of using this code, have you tried utilizing a manifest file? Running an application as admin is one of the things you can do with it.
this might help https://msdn.microsoft.com/en-us/library/ms742884.aspx