Opening console applications in powershell - visual-studio

I'm currently developing a win32 console application, and wondering if there is any way to make visual studio open it in powershell instead of cmd.exe when I'm debugging it.
All I really want is a better shell, where I can copy/paste etc. without clicking.
Thanks

I think you're mixing up the NT console subsystem (an app framework offerring common services) with cmd.exe (an application consuming those services.) When visuals studio runs a console application, it's not actually running CMD. CMD is a console application itself, no different than the app you are trying to debug, therefore running your application "in powershell" is equally as mistaken a concept.
If you mean trying to run it in PowerShell ISE, this is impossible. ISE is a Windows Application (NT GUI subsystem), which is an entirely different subsystem than that of the console.
-Oisin

You can try this.
Go to properties of your console project.
In Debug tab select Start external program and enter path to powershell.exe (C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe)
Enter ".\YourApp.exe" into Command line arguments
This starts your app in powershell. However it breaks a lot of things (like debugging, ...)

In Visual Studio goto Tools > External Tools...
In this window you can change the Title to Powershell. Set the Powershell Startup to execute and the check the output window box and it will dump all the output that would typically goto cmd into Powershell.
This link will explain it a little bit more for you.

Related

golang: optional console on windows

I am writing a service program which is expected to run in background. On Windows it will open a console window when run. I want it to go to background directly without that console window, so I used the -ldconf "-H=windowsgui" option, which worked as expected.
However, there is a catch. The program has a command line option -help, which output command line usage in the console. If I use -H=windowsgui, the help text is NOT printed even I start it in cmd.exe prompt.
It seems that the windowsgui option is not what I want. Is there anyway that the -help still works at commant line, and the console window will not persist if the program runs normally. I do not care if there is a console window pops up, provided that it disappears shortly without user intervention. i.e. I want a way on windows which is similar to the & operator on Linux.
P.S. if provided solution uses any other tools, I want that tool to be a Windows component, not any 3rd-party program. Thanks.

How to Launch a Metro App from Microsoft Access VBA on Windows 10 Computer

I have a situation in which I wanted to utilize the camera app in Windows 10 from my Microsoft Access program. Normally I could just send a command to execute the program's executable, but with the metro app there is no straightforward executable.
The basic code I use is this:
Shell """" & PthToExe & """", vbNormalFocus
PthToExe is the path name for the executable.
I looked around a decent bit, but was unable to find any simple solutions and ended up coming up with my own. My solution is to make a shortcut link to the camera application and then to launch the link.
In order to make a shortcut link in Windows 10, you can click on the start button, go to "All Apps", find the app you want (in my case "Camera"), and then click and drag it to the desktop.
Now that you have a shortcut, you can launch the shortcut from a command line. (So my shortcut doesn't clutter up my desktop, I dragged it off my desktop and into a folder on the "C" drive.)
Type the path into a command prompt like this and hit enter to test launching your app: C:\GJ\Camera.lnk
So that solves the problem if you wanted to launch from a command line. For some reason, though, Access would not accept that command. The way I got around it was I put the command in a batch file (Edit: Alternatively, see HansUp's comment). To do that, you just need to open notepad, type in the same thing you typed in the command prompt, save the note pad document, and then rename the document to have a .bat extension.
You can then execute the .bat file from Microsoft Access as follows:
Shell "C:\GJ\OpenCamera.bat", vbMinimizedNoFocus
Note that normally, I use vbNormalFocus when running the shell command, but in this case, it is desirable not to see the little command prompt open before the actual program opens.

Trying to run .vbs as a startup program. Forcing to run in cscript. Want it to run in background, instead of having a script host window open

So I've done some digging to try and find a way to run a script in the background on startup. The only solution I've found is to use:
Set WinScriptHost = Nothing
Is this a reasonable way to do it? Or could it cause some issues? I mean, from what I can tell, it just stops WinScriptHost from being used to refer to an object. But I feel like that could cause trouble in some scripts. So, should I avoid using this method and do something else?
Thanks!
CScript is for console windows, consoles programs by their definitions have a console. WScript is for GUI programs, unlike console programs, windows are optional (although almost all programs will create a hidden main window if not creating a visible window, as windows are how Windows communicates with a program).
Using WshShell.Run, which has a window style parameter, you can run cmd hidden eg cmd /c cscript script.vbs.

How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window)

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?
The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.
Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.
You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

Windows PowerShell ISE doesn't promt for input

I am using console as my tool for managing mercurial repositories. Wtih classic cmd or Console2 I type:
hg in
And console prompts something like:
D:\workspace\someproject>hg in
http authorization required
realm: Bitbucket.org HTTP
user: xorty
password:
And obviously, I type password.
But when I type "hg in" in powershell console, it doesn't prompt anything. It just keeps saying this:
Running script / selection. Press Ctrl + Break to stop
Can I make PowerShell ISE behave like classic console, or this isn't the way PowerShell is meant to work?
The PowerShell ISE indeed does not support console applications that require interactive input. The linked blog entry details options how to deal with that.
Since the PowerShell ISE is not a console, normal console applications cannot do everything they're used to, while of course PowerShell cmdlets can work just fine, since several things are dependent on the PowerShell host application (you get a graphical prompt with Read-Host, for example).
Console2 emulates a normal console by keeping the actual console around in a hidden window and polling it repeatedly for changes and, correspondingly, sending input to that window.
Powershell ISE ( integrated scripting environment ) is not the standard Powershell console. The ISE, like the name suggests, is a pretty basic GUI based script writing tool and doesn't support interactive console applications ( try just cmd on the ISE console and see the error message)
Open powershell.exe, and run the command that you want. It will behave pretty much like cmd. Or alternatively, press CTRL+SHIFT+P in the ISE and run the command there.

Resources