Can a VB.NET Windows Forms Application be configured so that when run from the command-line, the command-line waits until the application exits before showing the next prompt?
You can change the command to start your application from the command line to:
start /wait YourApplication.exe
In general the command line behavior depends on the subsystem your application is using (Console/Windows). As an Application with the subsystem Windows doesn't have standard input/output streams, there is no need for the console to wait for them.
But you can change your application to be a console app and use your existing forms as usual. This link shows an example.
The code after Application.Run(new Form1()); is only run after the application has been exited. No configuration needed.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
string s = "test string";
s.Trim();
}
I think the answer is No, but a console application can show forms.
Unless the command-line is your own console app, then no.
I suppose you could create a console app that shelled out to the windows forms app... a bootstrapper of sorts. If the console app were to be launched by command-line, it might do the trick.
Related
I'm trying to pass some arguments to an UI-based program (cocoa app) through terminal commands while the app is already in launch.
For example:
open appName.app -openUI // Shows App UI
open appName.app -forceQuit 5 // Force quit App after 5 seconds
open appName.app -sendMsg "Hello World." // Add "Hello World" to UNUserNotificationCenter
I will be very grateful if someone can guide me how to implement this, thank you.
If you specify the arguments in that way, they will be send to the open command - which does not recognize them.
You need to put a --args in front of them in order to tell open to pass all the follwing arguments to the app launched, e.g.
open appName.app --args -openUI
Update
If the app is already running, open will use the running app. If you want to create a new window, you need to provide the -n parameter:
open appName.app -n --args -openUI
I'm building a Visual Basic application in Visual Studio 2010. Some of my options can only be applied on restarting the application.
I have not gotten a single crash when application is running normally. Nor does it crash when I apply settings, manually exit and restart. On the other hand, as soon as I try to do a automatic restart from the application, I get an exception on one out of 5-10 restarts.
I've tried to run the debugger, but as soon as the application restarts, the Visual Studio debugger is turned off and does not turn back on when the application launches again. Nor does it launch again with same configurations. It seems the debugger launched application configuration and the manually launched application configuration files are different.
Is there a way I can get around this? Keep the debugger on across restarts? Or should I undertake a different strategy?
Method 1: Attaching the debugger from within the application
If the application sometimes crashes at startup add a call to Debugger.Launch() in the application's Startup event. Doing so will cause Visual Studio to open a window where you can choose to attach its debugger.
You can check the Debugger.IsAttached property in order to determine whether a debugger is already attached or not.
Steps to subscribe to the Startup event:
Right-click your project in the Solution Explorer and press Properties.
Go to the Application tab.
Press View Application Events.
Select MyApplication (events) in the left combo box.
Select Startup in the right combo box.
Code:
Imports System.Diagnostics
...
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
If Debugger.IsAttached = False Then
Debugger.Launch()
End If
End Sub
Method 2: Letting Windows start the debugger, which in turn starts your application
An alternative solution is to add your application to the Image File Execution Options registry key, which allows you to specify a debugger which should launch the application for you.
NOTE: Adding your application to Image File Execution Options causes Windows to automatically launch the specified debugger instead of your application whenever you try to open it. Your application's path is passed as a command line argument and it is then up to the debugger to launch your application, attaching itself to it.
Malwarebytes have some info about Image File Execution Options on their blog: An introduction to Image File Execution Options.
Here's how you'd do it:
Open Regedit.
Navigate to the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options key.
Locate the key with the name of your application (if it exists), or create a new one in the format of yourApplicationName.exe.
Create a new String value (REG_SZ) and name it debugger.
Set the value of debugger to vsjitdebugger.exe.
Go ahead and start debugging!
For more information see: How to: Launch the Debugger Automatically - MSDN
PHPStrom is a great IDE. I really like it. But I bumped into an issue. I can't find instructions how to configure debugging for Yii console application.
I set debugging for Yii web application and it works fine.
Any help will be highly appreciated.
Upd1: Actually I figured out that there are 3 cases of the Yii console application.
Standard Yii console application (command files in the protected/commands folder of the webapp)
Standalone Yii console application (independent console aaplication without web application)
[My case] YiiBooster console application (YiiBooster has advanced, but good structure for medium or big projects)
After some period of time I found the solution. In my case it must be split in 2 parts:
Configure XDebug in PHPStorm
Get appropriate Xdebug version. Use this wizard from official xdebug site; just copy&past your phpinfo() response into window and it will tell you which version you must download.
Install it and make sure that XDebug is activated (phpinfo() must return xdebug section in the response). Use the following link for detailed instructions
Set XDebug as debugger for PHP in Project Settings
[The steps below are specific for Yii console application debugging]
Find yiic.php file in your project and Run or Debug it first time.
After this go Run->Edit Config and set name of your command in the arguments with required parameters.
Now set breakpoints in your code and activate "Listen debugger connections” button.
Debugging Yii command actions
If you want to use actions (like actionRebuildIndexes) in the command it needs to call the parent::run method in the run() function.
public function run($args) {
parent::run($args);
return 0;
}
For debugging it needs to specify the action name in the arguments for yiic.php Run Configuration (see image above)
There is article in jetbrains blog about it.
you just set your php.ini and add an parameter in xdebug like this:
xdebug.remote_autostart = 1
then you can debug your console application.
I have a MAC OSX objective C application say first.app ,in which i use NSAppleScript with admin privileges to run a shell script.This script is indented to launch another Objective C application say second.app.
When you use open command Ex: "open second.app" in shell script it works fine .
But if you launch the second.app by calling its binary Ex: "/second.app/Contents/MacOS/second " in shell script ,then the control don't come back to first.app until second.app closes . when we close the second.app then first.app resumes .
What is the difference in launching the application from open command and calling the applications binary directly as mentioned ?
Calling
open Second.app
is the same as double-clicking the app's icon in the Finder. The application is started via LaunchServices, and the open command returns immediately.
Calling
/path/to/Second.app/Contents/MacOS/Second
starts the application directly (without LaunchServices), and returns only when the application has terminated.
I'm using c#, .net 4, WIX 3.5, Windows Vista.
I have made my application compatible with RestartManager by p/invoking the RegisterApplicationRestart method and by handling the WM_QUERYENDSESSION and WM_ENDSESSION window messages (I return new IntPtr(1);).
If I try to update my application manually, then everything works as it should:
Launch application;
Launch msi file containing new app version;
During the installation/update, I'm prompted to close the running application;
Upon continuing the running app is closed, install completes, and the app is restarted;
If I try to update my application from the application itself, then I run into problems:
1) Launch application;
2) Download the new msi file;
3) Launch msi file with:
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "msiexec";
p.StartInfo.Arguments = "/i \"" + downloadPath + "\" /passive";
p.StartInfo.UserName = "Administrator";
p.StartInfo.Password = securePassword;
p.Start();
}
4) Because I'm using passive mode, the application is closed automatically;
5) After the installation, my application is not restarted and under Event Viewer I have an
Event 10007 - Application or service 'MyApp' could not be restarted.
I have tried:
Not to use passive mode for msiexec;
Launch msiexec via cmd.exe (cmd.exe /C "msiexec /i ....") - in the hopes that launching msiexec from another process would solve the problem;
Wait for 60+ seconds before launching the msi update (shouldn't be relevant in my scenario, but MSDN documentation has something about it...)
But none of the above has worked (always the same result).
Having to launch the setup with elevated permissions might have something to do with the issue, because during the manual update I get a warning in the Event Viewer - Application MyApp (pid 3220) cannot be restarted - Application SID does not match Conductor SID.
Despite this, restarting the app still works. Googleing the warning yields no good/specific results, only that this warning is probably caused by running the msi in an elevated prompt.
How do I fix (or workaround) this issue, so that I can update my application from the application itself and restart my application afterwards?
Edit - extra testing:
There doesn't seem to be a need to respond to WM_QUERYENDSESSION and WM_ENDSESSION messages, because application restart during a manual upgrade works without them, so we can rule them out;
If I don't provide administrator credentials to the application initiated upgrade and instead I type them in during the upgrade, then app restarting works;
If I run an elevated command prompt and initiate an application upgrade from there (manually), then app restarting still works;
In order for application upgrade to work at all under Standard user accounts (so far I tested under an Administrator account with UAC), then I also have to set p.StartInfo.LoadUserProfile = true;. Otherwise nothing happens. (application restart still doesn't work though);
I tried all other process StartInfo parameters that I could set - WorkingDirectory, Redirect, Verb
(= "runas") - no change in results;
I installed Vista SP2 onto the virtual machine that I have been testing on (so far ran SP1), but no change;
I performed an "automatic" application upgrade with verbose logging. In the end there was an error message - RESTART MANAGER: Failed while restarting applications. Error: 352. That error code is very generic (http://msdn.microsoft.com/cs-cz/library/aa373665), inorder to get more detailed info I would have to write my own installer that would call RmGetList after the error, then I might get more details (this though is something I'm not willing to do);
Edit 2 - msi log file:
http://mommi.planet.ee/muu/log.txt
Assuming that the manual process indeed works without any problem it seems that your need for Administrator privileges in combination with the "updating itself" leads to these problems. I see the following options:
create a batch file to execute the update
When you want to update call this batch file (with elevated privileges), make the app close itself... the batch file should wait some seconds, then check whether the app is still running (and close it in case) and then run the commandline you need to run msiexec - don't restart the app from within msiexec but after a successfull run of msiexec from the batch file.
create a batch file which is always used to start the app
When the time comes to update you just end the app. Either the batch file check for an available update and applies it, starting the app after successfull update OR the app set some environment variable which is then accordingly processed by the rest of the batch file.