Find a program and run it through command prompt - windows

I want to be able to locate where the exe of a (third-party) program I remember from only its name. (say photoshop.exe) Is that possible?
Like you can call taskmrg.exe

try this to find:
dir /s c:\photoshop.exe
..and also to run:
for /f "delims=" %a in ('dir /b /a-d /s "c:\photoshop.exe"') do "%~fa"

Yes you can do that of course, but it involves searching for the file recursively in every folder of your hard drive partition(s).
Another way is to add the folder containing the .exe you want to execute in the PATH environment variable but it's not recommended to add every program you own to the PATH. (It's meant to remain quite small in size).

Here's the syntax of FIND command in dos.
http://www.computerhope.com/findhlp.htm

taskmgr.exe can be executed from any path at the command prompt, because its location falls within the directories listed in the %PATH% variable. You can potentially add any additional folders you would like to this variable to make any applications within follow the same behavior. Caveat: Some applications do not run properly unless started from within their home directory.
Editing the %PATH% variable via the GUI varies between versions of Windows, or you can edit it from the command prompt.

Related

Self-extracting executable do not recognize an existing command in System32

I'm developing a stack of Windows Batch scripts (.bat) which are subsequently converted to self-extracting executabled.
Currently I'm facing a really strange problem. I create this self-extracting executable, which, after extracting all the files, will launch the main wrapper, (SETUP.bat). The whole stack of the scripts gets running and everything goes right until some point.
One part of the stack has to commit some files with UWFMGR, and I have a loop for like this:
SETLOCAL EnableDelayedExpansion
FOR /F usebackq "tokens=*" %%F IN ("DIR /S /B /A-D") DO (
uwfmgr file commit "%%F"
)
If I run the executable, the execution of the stack does not recognize the command UWFMGR
I stopped the execution of the script, and went with the same CMD, (which it's launched by the executable), to the System32 folder to check if the UWFMGR is there. I did a DIR "uwfmgr.exe", and it's not there. But if I go with another CMD (a new one) the command is there. I even went with a file explorer to verify it and it's completely there but somehow the CMD which it's being launched by the executable cannot recognize it.
I have tried to specify the whole path in the loop like this "C:\Windows\System32\UWFMGR.exe" and it doesn't even work.
The funny thing is that if run this script it works and commits all the files required.
SETLOCAL EnableDelayedExpansion
FOR /F usebackq "tokens=*" %%F IN ("DIR /S /B /A-D") DO (
uwfmgr file commit "%%F"
)
Does anyone have any idea of why this is happening?
Check the output of the command and the errorlevel, it's 9009 (the file/command does not exist)
Do an echo to check the command I'm passing through the loop, the command is OK
I expect the executable to do the whole stack and commit the files but the executable does not recognize UWFMGR command. I use other commands in my stack and I didn't have any problem.
64-bit Windows has two system32 folders. Windows\system32 is the real folder used by 64-bit applications. 32-bit applications are automatically redirected to Windows\Syswow64 when they access system32. There is a backdoor you can use to access the real system32 folder.
You should use if exist and set to find and store a usable path:
#echo off
set app=%windir%\system32\UWFMGR.exe
set appalt=%windir%\sysnative\UWFMGR.exe
if not exist "%app%" if exist "%appalt%" set app=%appalt%
echo.I will use %app%
UWFMGR seems to be an optional feature and is probably not present by default on most machines.
I solved it after finding out the exe was created as 32bits. I had to create as 64 bits in order to make it work. Now the executable is able to use the UWFMGR.
Thank you everyone for your answers and have a nice day.
I'm using this 7sfx module, just in case anyone's wondering: "7zsd_All_x64.sfx"

How do you run an executable file whose name and location could vary with the Windows command prompt?

I am trying to create a script that will repair and reinstall a program. The problem is that the only place I can find an installer for the program is in C:/ProgramData. The folder name that it is saved in is randomly generated and the actual name of the file will vary depending on which version of the program they have installed 1.1, 1.5.1, etc. I need to create a command that will search for the executable file and run it. An example of what the installer might look like is program1.5.1.exe.
I have already tried using findstr, dir, etc., but I have not had any luck.
Here are some of the commands that I have tried.
cd C:/ProgramData
findstr /s program*.exe
cd C:/ProgramData
dir /s program*.exe
When I use the findstr command, it keeps running and never finds the executable. When I run the dir command, it tells me that "Volume in drive C has no Label", tells me my serial number, and then it says "File Not Found."
I figured out how to run an executable that is in a folder with an unknown name and that has a file name that will be different depending on the version of the program. I was trying to find and run a test file that I called "program1.3.0.exe". Note, I ran this in a batch file so if you are running this directly in the command prompt you will need to type %i instead of %%i.
for /r C:/ProgramData %%i in (program*.exe) do start %%i
The for command searches through the directory
/r tells it to search within the subdirectories
C:/ProgramData is the directory that it will search within
%%i is a variable that holds each file that it finds
in (program*.exe) tells it to only use results that start with program and end with .exe
do start %%i will run each executable that it finds

VB script to list folders and contents

I would like to write a VB script that will:
List all folders named "abc", and also there contents, in share drive \share1
Currently these folders named "abc" are located all over the place in \share1, but they all have the same name.
The issue I have is that some of these paths are long paths, hence getting this working through PowerShell has been very difficult, as it keeps hitting the 260 limit.
Prefixing a path with \\?\ allows paths up to 32,000 odd characters. This allows apps to opt in to very long file names as they crash most programs. Now it depends on how you access the file functions if the component will allow you. CMD does support this.
so a command line
for /f %A in ('dir c:\windows\abc /s /b /ad') do dir "\\?\%A"
\\?\ works with unc paths too.
for /f %A in ('dir \\?\c:\windows\abc /s /b /ad') do dir "%A"
I think that RoboCopy (the Windows utility) is your best bet. This can handle long path names, and it can actually be used to just list files, rather than copy them, by using the
/L option (: List only - don’t copy, timestamp or delete any files.)
http://ss64.com/nt/robocopy.html provides a good summary of all the options.
You can also download a GUI for it which might make it a bit easier to work with.
Another option is to shorten the path via subst:
subst X: C:\very\...\long\...\path

Windows xp: roll my own desktop tool to copy list of directory names

Many times I have found the need to copy directory names from one directory into another, creating a list of empty directories in the later.
I have achieved this task using the following command:
for /F "usebackq" %i IN (`dir /b C:/backups/sites/24/01/2012`) DO makdir C:\fabio_temp\test\%i
Now i would like to create a reusable and friendly tool so that i don't have to be typing this all the time on the command line.
Example of what I want in pseudo-language:
$dir = PROMPT('Type in the name of the directory containing the list of directories to clone:');
$dir_dest = PROMPT('Type in the destination directory:');
FOREACH LIST_DIRNAMES($dir) AS $dirname DO
MKDIR CONCAT($dir_dest,$dirname)
ENDFOREACH;
Then, it would be nice to have this function appearing in the right-click context menu. It doesn't matter what language is going to be used for this. It could be vbscript, or whatever, I don't know.
Thanks to the tutorial that #AlbertoSolano suggested, I was able to write a simple script named mkdirs_from_list.bat with the following content:
for /F "usebackq" %%i IN (`dir %1 /b`) DO mkdir %2\%%i
That does exactly what I was asking for, and, to make things easier, I'm adding the script to the path environment, so it can be invoked like this on the command line:
mkdirs_from_list C:\dir_to_list C:\dir_dest
I wanted something more friendly, like a prompt popping up, being able to browse the directories, or something alike, but I think this will suffice.

Window shell - list of file as a command input

In Unix, I can provide a command with a list of files by doing that:
mycommand folder/*
The argc will then be equal to the number of files in the directory and argv to the name of each files in the directory.
However, this doesn't seem to be the same on Windows. Is there a way to emulate this without listing all the files of the folder as argument to the command?
Thanks.
Windows command prompt does not natively support wildcard expansion.
If "myprogram" is an application build with Visual C++ and you have control over how it is built, you can add support for wildcards to the application itself, as described in MSDN article Expanding Wildcard Arguments
From here:
To delete every .bak file in every subfolder starting at C:\temp
C:\>FOR /R C:\temp\ %%G IN (*.bak) DO del %%G
Also take a look on FORFILES.

Resources