This is my first question on here, so bear with me.
I'm working on a winforms GUI in C# that communicates with a RasPi running test hardware. Most of that works fine, but something new I was asked to add doesn't yet.
So, one of the forms has a button that opens another form which lets us toggle specific bits on various ICs on the hardware. Someone wrote a utility on the RasPi which displays the state of those bits in a SSH window (usually PuTTy, but also works through cmd->ssh in Win10).
(For anyone who cares, we're trying to move away from PuTTy (or any other 3rd party tool) for this so we don't have to figure out packaging it into our installer. Some of our clients have no networks beyond their PC and the test hardware.)
SSH Login
Utility, opened from File Explorer
What I was asked to do is open this utility alongside the second form. Sounds simple enough, but I can't figure out how to get it working.
I have a .cmd in a folder on my desktop that launches the utility just fine when I click to run. All it has in it is "ssh -t semitek#{ip} /usr/semitekutil/outs".
In my GUI (Running through VS 2019, with the project on a company server), I tried pointing it to that cmd file like this:
outs.StartInfo.FileName = #"C:\Users\jfink\Desktop\4xDebugLEDs\4xPiOuts_NoPutty.cmd";
outs.StartInfo.WorkingDirectory = #"C:\Users\Default\Desktop\4xDebugLEDs\";
outs.Start();
And this:
outs.StartInfo.FileName = "cmd.exe";
outs.StartInfo.WorkingDirectory = #"C:\Users\Default\Desktop\";
outs.StartInfo.UseShellExecute = true;
outs.StartInfo.Arguments = "ssh -t semitek#" + df.IPaddr + " /usr/semitekutil/outs";
outs.Start();
Both of which give me this:
Starting through GUI
Utility started through GUI
I've also tried:
Process.Start("cmd.exe", "ssh -t semitek#192.168.50.102 /usr/semitekutil/outs");
but that doesn't execute the argument.
Process.Start() with args
Can anyone help point me in the right direction? I don't understand why clicking the cmd in File Explorer works just fine, but calling it through the GUI doesn't, nor why the utility displays differently for each access method...
Thanks in advance!
Related
I'm developing a program in mono/C# which will run on a Linux embedded platform with a touch-screen.
I've installed OpenBox in top of Raspbian, because this will run in "kiosk mode" and I'm trying to keep it as simple as possible.
I was planning to have two options in the program:
option to shutdown the computer
option to close the windows manager (openbox) and return to the terminal
For the first option I've tried using:
shutdown
poweroff
systcl poweroff
commands but all require special privileges, so I'm not sure on what would be the best approach. Should I create a bash script with root privileges and run this script from the program?
For the second option, I don't even know how to start. I've configured openbox to be able to close it from the keyboard through Ctrl + Alt + Backspace, but I know how to close it from the program.
I've tried using SendKeys with that key combination but does not work.
I've also tried the solution here using DBUS for C# but I've issues compiling it.
Could you please give any advice?
You can set your sudo program up to let a user run a program without any password.
Add to your visudo file:
<username-or-ALL> ALL=(ALL) NOPASSWD:/sbin/poweroff
See this maybe
If I were you, I would reboot after setting up and before testing.
I am looking to launch an ironpython interactive window when I run a python script from my windows forms application. I am looking to redirect the python IO to the interactive window. Therefore, the script can take user input while it is running.
I have created an application in windows forms (C#) which hosts ironpython 2.7.9. I made a simple GUI which allows me to select a python script with an OpenFileDialog() and run it using an engine. Up until now, my scripts did not require user input and were completely automated from start to finish. However, now I am looking to include manual steps within these scripts which require the user to enter 'y' or 'n' to continue or abort the script. With the winforms application printing all output to the console, I am unable to interact with the python script at run time. Ideally, I was looking to launch an ironpython interactive window when I run my script and be able to interact with the python script from there. From what I was able to gather online, it seems I would have to hard-code a path to the ipy.exe file in my computers Program Files and redirect python input/output somehow but this is not ideal. I figure there has to be an easier way to do this but cannot figure out how. Ultimately, I am just trying to give user input to a python script running in C#, so if there are any other methods that can satisfy this I would be receptive to those ideas. Any suggestions would be greatly appreciated, also let me know if there is more information I need to provide!
How I created my engine:
public ScriptExecutor()
{
InitializeComponent();
myEngine = Python.CreateEngine();
}
private Microsoft.Scripting.Hosting.ScriptEngine myEngine;
I run a script with the ExecuteFile function:
myEngine.ExecuteFile(#"path to file");
Expected result would be to launch a python interactive window when a "run script" button is clicked. The user can interact with the script from this interactive window (give input/see the output)
picture of GUI: (https://imgur.com/RzzMI4N)
After alot of experimenting I found the answer to this question.
I realized that I should not use an engine for the functionality I was looking for. Instead creating a process is the best way to launch the ironPython window.
Every tutorial and question I saw was saying to redirect the output with ProcessStartInfo.RedirectStandardOutput = true
However, if you want the ipy console to act as a stand alone process, we need to allow it to receive input and output, hence these values must remain false.
UseShellExecute and CreateNoWindow must also be set to false so that the operating system shell does not start the process and a new ipy interactive window is launched.
also, since ipy.exe is installed to the System32 folder I do not need to hard code the path, rather just use "ipy.exe"
To launch the python interactive window I started a process:
var script = #"C:\path\to\script.py";
var psi = new ProcessStartInfo()
{
FileName = "ipy.exe",
Arguments = $"\"{script}\"",
UseShellExecute = false,
CreateNoWindow = false
};
Process python = new Process();
python.StartInfo = psi;
I am building a .net 4.5 (c#) app and packaging it with Squirrel for Windows.
As expected, the releasify command creates one Setup.exe file and one Setup.msi. The Setup.exe installs the app as expected on the two windows 10 computers I had access to.
On the windows 7 I used to build the app though, when I try to open Setup.exe, the window where I double clicked the icone goes in "please wait mode" (with the blue progress circle instead of the usual mouse pointer) forever. If I check the processes open at that point, I see three Setup.exe that I cannot kill with the kill process button or via Taskkill command. And all I can do at that point to kill them is pretty much rebooting.
As to the Setup.msi, it seems to do nothing I can see (tells me something like "checking requirements", and once it has, it just closes with no visible effect).
Any idea about what's going on or how I could find out?
Apparently years later this keeps hitting people so I'm posting the answer I had first put in the comments:
Deactivating my antivirus solved the issue >< I wish Avast had told me "hey I'm blocking this" and saved me a few hours
I am building a vb.net application which monitors external process and kills the process based on certain conditions. The application works great with monitoring .exe process but i m unable to use it with control pannel items.
Suppose a user launches programs and features , I want my vb.net app to detect it and kill it. Under task manager the process is shown as explorer.exe.
I can successfully launch programs and features using Process.Start(System.Environment.SystemDirectory + "\appwiz.cpl")
but i cannot kill it this way, can anyone tell me how i could kill this process??
Thanks!
You can use the following:
Process.Start("taskkill.exe /im explorer.exe")
Just replace explorer.exe with the process you wanna stop/kill...
Also works with the PID (Process ID):
Process.Start("taskkill.exe /pid /*yourPID*/")
Do not kill applications until there is other way to exit them.
It is like finishing your day by instantly turning off your computer.
First, at least ask applications to close themselves:
Please see Microsoft article How to use Visual Basic .NET or Visual Basic 2005 to close another application how to implement closing request.
Also please have a look at this Q&A how to prevent application to be uninstalled by a user (w/o admin rights)?.
a few days ago, I developed a WinForms application in C# using VC#2010 Express. After creating and saving the project, I made it a console application in the project settings, so additional to the start form, a windows command line pops up. I used the console to output debug information (simply with the Console.Write() function).
So now, my app is ready for a release. I do not want the user to see the console, for sure, but I'd like to integrate a way to show the console to interested persons. So, the best way is an argument, I think (like -console), but I dont know how to start the program as a console application only when an argument is set. I know how to handle the args[] array, for sure, but I have no idea how to show the console when there is an arg. I already tried it by simply starting the program via command line(CMD -> prog.exe), but it did not work. The program starts, but the console directly shows the current path after starting the program, as usual.
Is there any possibility for my intention?
AFAIK, there is no way to have a single binary support both console and non-console behaviour, with the choice being made on start-up. All the work-arounds I've seen use two binaries.
There's a discussion here on how Python deals with the problem (boldface mine):
The standard Python.exe that comes with Python is known as a console application (this means it has been built to interact with a Windows console, otherwise known as a DOS box or command prompt). Although you can execute your Tkinter programs using Python.exe, your program will always be associated with a Windows console. It works just fine, but has the following side effects:
If you execute Python.exe from Windows Explorer, a new empty console window is created; then the Tkinter windows are created.
If you execute a Tkinter application under Python.exe from a command prompt, the command prompt doesn't return until the Tkinter application has finished. This will be a surprise for many users, who expect that executing a GUI program returns the command prompt immediately.
To get around this problem, Python comes with a special GUI version called Pythonw.exe. This is almost identical to the standard Python.exe, except it's not a console program, so doesn't suffer the problems described previously.
You could get the command line arguments for the Winform in the forms load event and then if the argument is for the console, open the console.
private void Form1_Load(object sender, EventArgs e)
{
string[] args = Environment.GetCommandLineArgs();
foreach(string arg in args)
{
if(arg == "consoleargument")
{
// Run console
}
}
}
You can link to kernel32.dll and use the function AttachConsole.
Here's an example: http://www.csharp411.com/console-output-from-winforms-application/