Unable to open application by specifying it's location under App Paths - windows

I have created a key(for example myapp.exe) under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" with below values in registry.
(Default) --> C:\Program Files\folder1\folder2\myapp.exe
Path --> C:\Program Files\folder1\folder2\;
Then I opened a command prompt and tried to open my application. But I am getting an error like "'myap.exe' is not recognized as an internal or external command,operable program or batch file."
If I add the directory where my application resides to Path environment variable, then I am able to run the application successfully from command prompt.
please let me know where I went wrong.

This is another way to start an application from the command prompt.
Create a batch file similar to the following and call it FR.BAT which is short for foxit reader in this example, and store the FR.BAT file in c:\windows or another directory on the PATH.
When you open a CMD prompt and type fr then it will launch this batch file and start the application.
#echo off
start "" "c:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"
Just be careful not to use a name which is the same as an existing Windows command.

Related

Unable to launch a packaged executable as a Windows service via ProcRun

I have a requirement to launch an executable as a windows service with help of procrun.
I followed the below steps.
Created a batch-file named run.bat, to create a service.
"C:\Program Files (x86)\Test\prunsrv.exe" //IS//Test --DisplayName="Test" --Startup=auto --Install="C:\Program Files (x86)\Test\prunsrv.exe" --StartMode=exe --StartImage="C:\Program Files (x86)\Test\batchSample.exe" --LogPath="C:\Program Files (x86)\Test\logs" --StdOutput=auto --StdError=auto
Created a batch-file, batchSample.bat, to launch a URL:
start https://www.youtube.com/watch?v=q3pG6b3uI_E
Converted the batch-file to an executable, batchSample.exe, and placed it in C:\Program Files (x86)\Test.
Executed run.bat.
At this point the the windows service, Test started without giving any error, but it did not execute the batchSample.exe as used for --StartImage.
Appreciate your help.
Your batch file is not an executable, no matter what extension you give it.
Per the docs - https://commons.apache.org/proper/commons-daemon/procrun.html
--StartImage Executable that will be run. Only applies to exe mode.
++StartParams List of parameters that will be passed to either StartImage or StartClass. Parameters are separated using either # or ; character.
You need a program to execute your batch file as StartImage (sh?), and put the batch file in StartParams.

How to open a file in a specified program using window comand prompt

How can I open a file from the command prompt in a specified program rather than the default program for opening the file.
like in MAC terminal
open main.js -a "Sublime Text"
currently I only do
start filename.extension
which opens the file in the default program.
please what command can I use to achieve this?
With Windows, you type application first.
So with Notepad, which is on the Windows path, you can type
notepad filename.extension
By 'Windows Path' I mean a list of directories that Windows looks in for your application. If your app is in one of those folders, then you only have to type the application name. If your app isn't, then you need the full path to the application.
Most of the Windows native apps (like Notepad, MSPaint, etc) are automatically on the path. However apps that are installed afterwards sometimes don't update the path and you need the full path. You can usually get this by right-clicking on the application and getting properties. Often you'll need quote marks - specifically if there are spaces in the path, which there usually are because "Program Files", so:
"C:\Program Files (x86)\Notepad++\notepad++.exe" filename.extension
Note the quote marks go around the path to the application file itself - not all the way to the end of the line. An easy way to check that you've got the full path to the file is with the dir command:
dir "C:\Program Files (x86)\Notepad++\notepad++.exe"
Some applications expect instructions about what to do with the file, and you may need to figure out what else to put on the command line. Usually google will tell you this.
For example, to execute an SQL script, with one tool I use, just putting the filename on the command line won't work, you do something like:
"C:\Program Files\PostgreSQL\9.4\bin\psql.exe" -U user -d dbName -f filename.extension

Create a .bat file to run an exe as administrator

I've created a batch file for running a setup.exe (code below) but I'm having issues getting the setup.exe to "run as administrator". I used this guide (shortcut trick) for aid.
start "" %CD%\Setup.exe
NOTE: My files will eventually be burnt to a DVD disk. They are currently in the directory "C:\Drivers\win8.1_x64\01a.chipset".
The batch file code runs the setup.exe (without admin privileges) fine, when running the batch file by itself (i.e. not running the shortcut).
However, when I run the batch file via the shortcut, Windows gives the error "Windows cannot find 'C:\Windows\system32\Setup.exe'".
The setup.exe directory is not in the system32 folder. Why does running the batch file find the setup.exe fine but not when I run it by the shortcut (so I can run the setup.exe as an admin)?
You can either set the working directory in the shortcut itself, or run Setup.exe not from working directory (%CD%) but from directory where script is located:
start "" "%~dp0\Setup.exe"
Difference from earlier answer is there's no need to cd to %~dp0. Just run the setup with full path.
By default admin privileged scripts are starting in C:\Windows\system32\
Try to put cd /d "%~dp0" at the beginning of your script which should change the work directory to the script's one.You can check this if you want to create a shortcut with admin permissions from the command line.

Trying to open programs with bat file but always comes back invalid

I am a streamer and I need a few programs to stream. It's annoying to open all of them so I tried putting them in a batch file. I looked up the process and followed it,but every time I run the batch file it comes back invalid.
This is what my batch file looks like:
#echo off
cd C:\Program Files "(x86)\obs-studio\bin\64bit"
start obs64.exe
#echo off
cd "C:\Program Files\HexChat"
start hexchat.exe
#echo off
cd "C:\Program Files (x86)\Nightbot"
start nightbot.exe
exit
Cmd gives me an error saying it cannot find the file. When I put this into cmd by itself it opens the program.
Also is there a way to add applications from chrome to the file?
Open a command prompt window and run from within this window start /? which outputs the help for this command and explaining all options.
Following batch file most likely works:
#echo off
start "" "%ProgramFiles(x86)%\obs-studio\bin\64bit\obs64.exe"
start "" "%ProgramFiles%\HexChat\hexchat.exe"
start "" "%ProgramFiles(x86)%\Nightbot\nightbot.exe"
This batch file starts the three applications with current directory on execution of the batch file being also the current directory for the 3 started applications.
But the following batch file should be used if it is really necessary that each application is started with the application's directory as current directory:
#echo off
start "" /D"%ProgramFiles(x86)%\obs-studio\bin\64bit" obs64.exe
start "" /D"%ProgramFiles%\HexChat" hexchat.exe
start "" /D"%ProgramFiles(x86)%\Nightbot" nightbot.exe
With parameter /D and path of application's folder the Start In directory is set first like when using command CD. So for example hexchat.exe is started with current directory being C:\Program Files\HexChat for this application.
The two double quotes after command START are necessary as this command interprets first double quoted string as title for the process. By using "" an empty title string is explicitly specified resulting in rest of command line being correct interpreted as expected. I suppose those three applications are all GUI applications and not console applications and therefore a real title string being useful on running a console application in an new command process for the console window is not really necessary.
%ProgramFiles% references the predefined environment variable ProgramFiles containing path to standard program files folder for 64-bit applications on 64-bit Windows when batch file is started with 64-bit cmd.exe as default on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files.
%ProgramFiles(x86)% references the predefined environment variable ProgramFiles(x86) containing always path to standard program files folder for 32-bit applications on 64-bit Windows and is replaced by Windows command interpreter before execution of the command line on your Windows computer by C:\Program Files (x86).
It is of course also possible to use the real paths in your computer instead of the environment variable references if this batch file is never shared with other people.
Extra hint:
Run in a command prompt window the command you want to use with /? as parameter to get displayed the help for this command. Other sources for help on commands and predefined environment variables displayed all on running in a command prompt window set are:
SS64.com - A-Z index of the Windows CMD command line
Microsoft's command-line reference
Windows Environment Variables and WOW64 Implementation Details

How to register DLL from .bat file in Windows 7

As part of a poor-mans installation (on Windows 7) I need to register a DLL from a .bat file. I provide the user with a set of files that make up the application, tell them to copy them to some (any) directory, then, as the 1st part of the install, tell them to execute my register.bat file which invokes regsvr32 on the appropriate DLL(s)
This fails with 0x80004005 (permission) error. I then try running the .bat file as an Admin. This doesn't work as it opens the command prompt in \windows\system32 which is not where the DLLs to be registered are located. As I don't know where the user has placed the register.bat file I can't put the path to the DLL files in the .bat file.
Any thoughts?
Try using %~dp0 to get the folder the batch file is stored in, like:
regsvr32 %~dp0\mylibrary.dll
You can get and use the path of the current directory like this:
set "FullPath=%cd%\Test.dll"

Resources