How to run cypher shell from Run dialog? - batch-file

The cypher-shell.bat is located at D:\GitHub\cypher-shell\cypher-shell.bat. Neither of these commands starts the shell when I put it in the Run dialog:
pwsh D:\GitHub\cypher-shell\cypher-shell.bat: PowerShell opens and exits immediately
pwsh -wd D:\GitHub\cypher-shell\cypher-shell.bat: PowerShell doesn't exit but shows this error: Set-Location: Cannot find path 'D:\GitHub\cypher-shell\cypher-shell.bat' because it does not exist.
pwsh -f D:\GitHub\cypher-shell\cypher-shell.bat: PowerShell opens and exits immediately
How should I do this properly?
I actually have added D:\GitHub\cypher-shell to my path. Running pwsh "& cypher-shell", pwsh ^& cypher-shell, or "%ProgramFiles%\PowerShell\7\pwsh.exe" "& 'D:\GitHub\cypher-shell\cypher-shell.bat'"in Run dialog the terminal flashes for a moment and closes. In the moment it opens I can see it messages a red error.
The reason I want to use this in PowerShell because it supports more features, like copypasting or selecting text with keyboard only. The commands are also more convenient than CMD.
FYI: about Pwsh - PowerShell | Microsoft Docs

Related

Jenkins job stuck after command start

I have a problem in my jenkins job and I isolated into one command. So I created another separate job to try to fix it.
So in this job, called "teste" I only have one single command:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
This opens a separate cmd window running my bat file, which should keep running "forever".
But the problem is when I do it, my jenkins job keeps stuck into a "exit 0" operation that I have no idea from where it came from.
Thats the console:
[EnvInject] - Loading node environment variables.
Building remotely on Machine01 in workspace C:\workspace\teste
[teste] $ cmd /c call C:\...dir\jenkins.bat
C:\workspace\teste>start cmd /k call "C:\Program Files\myDir\myBat.bat"
C:\workspace\teste>exit 0
Then it keep stuck at that point.
Example of myBat.bat content:
echo hi
pause
There's any way to make this call in another window without waiting for its finish?
I solve my problem changing the way I was calling my other .bat, calling it through powershell. But since I was from a bat file, I used the command to send a powershell command, calling my other bat file.
Also, I've added another line changing the jenkins BUILD_ID to a fake one, so it doesn't kill it.
So I changed from this line:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
To this :
set BUILD_ID=dontKillMe
powershell -Command "Start-Process 'C:\Program Files\myDir\myBat.bat'"
I hope it helps someone someday.

run wordpad print and delete tempfile in progress 4gl?

I have a rtf file with data and now I have created a temp file and batch file . Now how do I run wordpad print and delete tempfile in progress 4gl
you can use the write.exe command line options:
write.exe /pt someFile.rtf "Microsoft XPS Document Writer"
Here the "Microsoft XPS Document Writer" printer is used. You can list available printers with powershell "get-WmiObject -class Win32_printer | ft name, systemName, shareName"
You use the OS-COMMAND method. You can do that to invoke any os-command in any supported OS.
OS-COMMAND [option] VALUE("whatever command you like to run").
There are three different options
SILENT
After processing an operating system command, the AVM shell pauses. To exit the window in Windows GUI platforms, you must type exit. To exit the window in Windows character platforms, you must type exit and press RETURN or SPACEBAR. You can use the SILENT option to eliminate this pause. Use this option only if you are sure that the program, command, or batch file does not generate any output to the screen. Cannot be used with NO-WAIT.
NO-WAIT In a multi-tasking environment, causes the AVM to immediately pass control back to next statement after the OS-COMMAND without waiting for the operating system command to terminate. Cannot be used with SILENT. This option is supported in Windows only.
NO-CONSOLE While processing an operating system command, the AVM creates a console window. The console window may not be cleaned up after the command is executed. You can use the NO-CONSOLE option to prevent this window from being created in the first place.

How to keep the shell window open after running a PowerShell script?

I have a very short PowerShell script that connects to a server and imports the AD module. I'd like to run the script simply by double clicking, but I'm afraid the window immediately closes after the last line.
How can I sort this out?
You basically have 3 options to prevent the PowerShell Console window from closing, that I describe in more detail on my blog post.
One-time Fix: Run your script from the PowerShell Console, or launch the PowerShell process using the -NoExit switch. e.g. PowerShell -NoExit "C:\SomeFolder\SomeScript.ps1"
Per-script Fix: Add a prompt for input to the end of your script file. e.g. Read-Host -Prompt "Press Enter to exit"
Global Fix: Change your registry key by adding the -NoExit switch to always leave the PowerShell Console window open after the script finishes running.
Registry Key: HKEY_CLASSES_ROOT\Applications\powershell.exe\shell\open\command
Description: Key used when you right-click a .ps1 file and choose Open With -> Windows PowerShell.
Default Value: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "%1"
Desired Value: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "& \"%1\""
Registry Key: HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\0\Command
Description: Key used when you right-click a .ps1 file and choose Run with PowerShell (shows up depending on which Windows OS and Updates you have installed).
Default Value: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & '%1'"
Desired Value: "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoExit "-Command" "if((Get-ExecutionPolicy ) -ne 'AllSigned') { Set-ExecutionPolicy -Scope Process Bypass }; & \"%1\""
See my blog for more information and a script to download that will make the registry change for you.
Errr...
I should have known:
powershell -noexit <path\script>
and that's all there's to it :)
The solution below prevents the script from closing when running Powershell ISE and allows the script to close otherwise.
# If running in the console, wait for input before closing.
if ($Host.Name -eq "ConsoleHost")
{
Write-Host "Press any key to continue..."
$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp") > $null
}
Just add pause on a new line at the bottom of the script, as in a batch file.
In my own case, I wanted to add powershell to context menu on windows 7. That is right clicking on a folder or inside a folder to get a menu to launch Powershell window without it closing after launch. The answers here helped me do just that and I want to share it here incase it helps someone else.
Launch registry editor by pressing WIN + R
type regedit.exe and hit enter
Navigate to HKEY_CLASSES_ROOT\Directory\Background\shell
Right click on shell and create a key give it a name e.g PowershellHere
On the right pane, double click on Default and provide a descriptive name e.g Powershell Here
Right click on the PowershellHere key you created earlier and create a new key and name it "command" please make sure you name it exactly so but without the quotes.
On the right pane, double click on Default and then type the command below
C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit -Command CD '"%1"'
-noexit flag makes sure that the Powershell windows does not close again immediately after launch
'"%1"' flag represents the folder you right clicked
-Command CD '"%1"' will ensure the Powershell changes into the right clicked directory.
To make the right click work inside a folder meaning right clicking an empty space inside a folder, repeat the steps but this time, the registry location is:
HKEY_CLASSES_ROOT\Directory\shell
And the command is:
C:\Windows\system32\WindowsPowerShell\v1.0\PowerShell.exe -noexit
Tested on windows 7 ultimate sp1 but I think I might work for later versions of Windows as well
You can add pause at the end of your script if you just want the window to stay open, or you can add powershell if you want to be able to run commands afterwards (obviously don't do the second option if anyone else will use your code).

Open application with hidden cmd.exe

To open an Android Virtual Device, I was recommended to add a shortcut or a batch file with the next line:
C:\android-sdk\tools\emulator.exe -avd MyAVD
Nevertheless, when I do so, this opens with a command line window, which if I close by error (Something frequently since I work with many command line windows for debugging the apps), It also closes the AVD emulator.
I want to open the AVD without the command line window, to prevent this, I was recommended to do so with cmd /c or with start at the beginning, but it isn't working either. Anyone can tell me how should I do this?
You can use a VBScript to open the command prompt window hidden
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\batchfile.bat"), 0, True
If you save that as .vbs and make sure to replace C:\batchfile.bat with the location of yours, this will run the command hidden.
This should do it, it should run as a subprocess of taskeng.exe in Task Manager.
schtasks -create -tn foo -tr <command> -sc once -st 00:00 -ru system
schtasks -run -tn foo
schtasks -delete -tn foo -f
ref

Prevent batch file in CMD from closing without using Pause

Currently I want to run a batch file that fires the command git log and show me that log.
After that I need to be able to commit and view the status so this prompt may not disappear after a key press.
I've searched the net and the only answer people have is pause which close the prompt after a keypress.
Does anyone have the solution for me? Currently I made a shortcut to cmd.exe and made the target my folder, but I want to execute some commands also.
Thanks in advance.
This (below) tested OK in Windows 7. To exit the window it creates, type "exit" when done.
start cmd /K "cd \[the-target-folder] && git log"
Where:
[the-target-folder] you replace with your target folder
Note:
&& lets you run two commands on one line
/K is a parameter to the cmd shell program which which carries out the command specified by string and remains.

Resources