I have created a batch file to run an application automatically but it seems my CMD does not run it. I typed this (using notepad as an example):
CMD /C "C:\notepad2\notepad2.exe"
If I run this from Windows Vista it worked. But running this from Windows Server 2008 (64-bit) it just doesn't work. I even try using that line from the Run menu but no go.
What do I do? My aim is to run a scheduled task that runs the batch file every now and then.
Stupid question, but does the program you're trying to run actually exist on the Server 2k8 machine?
There are no differences in cmd between Vista and Server 2k8 whatsoever.
Besides, why do you need to execute it via cmd? Can't you just run the application directly? Using cmd /c is only necessary for shell built-ins, such as dir or start.
Also remember that there is no NTVDM on 64-bit Windows—you can't run 16-bit programs. I doubt one would still use them nowadays but it may be the only thing I can think of why it doesn't work in 64-bit.
Related
I have a couple command line apps (launch4j + java.exe) I use.
I'd like to run them on Windows Terminal instead of cmd.exe. But, even after installing Windows Terminal, when I execute the launch4j exe, it still runs on cmd.exe.
If I run wt myapp.exe -oneinput it works, but I'd like to run myapp.exe directly.
Is there any setting I must do so that Windows Terminal is used in place of cmd.exe?
The Windows Terminal team are working to enable Windows Terminal to become the default command-line user experience on Windows.
Stay tuned to the Windows CommandLine Blog for news and updates on up-coming features.
I have spent a lot of hours trying to figure out this simple thing I want to accomplish. I have a .cmd file with one line: sfc /scannow
I wrapped this into a package with the command line as a program at: cmd /c sfc.cmd and this is set to install as required and hidden. (I can look at the cbs log if this actually did run).
So then it get's deployed and downloaded to the test machines and i see it in ccmcache folder. Looking at execmgr.log it executed the following:
"C:\Windows\system32\cmd.exe" /c sfc.cmd, Working Directory = C:\Windows\ccmcache\g\
Running "C:\Windows\system32\cmd.exe" /c sfc.cmd with 32bitLauncher
Those two indicators were noted around 4:43PM. I don't see exit code 0 or any other code. Then looking at cbs.log the last write time was 4:19PM. What am I doing wrong?
If I try to run sfc /scannow from a 32Bit cmd in 64Bit Windows I get an error so you probably have to use a trick to run the 64bit sfc.
Instead of the commandline
cmd /c sfc.cmd
use
C:\windows\sysnative\cmd /c sfc.cmd
Sysnative is an alias that you can unfortunately not see but if a program is started as 32bit process it can access it. What it does is avoiding the WoW64 redirection that intercepts every call to system32 and sends it to syswow64 which in your case leads to a problem.
I am running Windows 7x64 and Excel 2010x32. I call 32bit dos programs (written in Fortran) via vba using ExecCmd (a Microsoft function that waits for a command prompt process to finish). I send a command line to this function that explicitly contains the program path and the paths of the input file and output file.
This runs fine on my PC and also on a company PC running the same software (OS and Office) and for which I have general access to the C: drive.
On other company PCs, where there is not general access to the C: drive, this does not work - i.e. the dos programs do not produce an output file. On these PCs, I can still run the program at the command prompt manually. It is just that calling this command prompt does not work via Excel VBA.
Now the strange thing is that I can successfully run one of these programs by adding "cmd.exe /c" at the beginning of the command line. That would appear to be running a command prompt within a command prompt (!). The other program (which, incidentally, is quite a bit bigger) does not work at all via vba on these PCs. I need to be able to provide other employees with something that works.
Can anyone shed some light on what is happening here and suggest a work around? I could past some code, but I think the above should be self explanatory.
You're confusing the command shell with the console window. In this context, the distinction is critical.
Console-mode programs (aka "command-line programs") require a console window to provide input and output. When a console-mode program is launched from a GUI program, Windows automatically creates a console window for it (unless instructed otherwise).
The command shell (aka "Command Prompt") is cmd.exe, a console-mode program.
The important point here is that not every console window has an instance of cmd.exe running in it. When a console-mode program is launched from a GUI program, Windows automatically creates a console window but does not automatically create an instance of cmd.exe. If you want to pass a command to cmd.exe you have to do so yourself, or use a run-time library routine that does it for you.
ExecCmd does not do this; it runs the program directly. So passing cmd /c <command> to ExecCmd is not "running a command prompt within a command prompt" at all. Without the cmd /c you aren't running a command shell command, you're just launching an executable.
There are any number of reasons why the command you're passing might need to be given to the command shell. For example:
it might be a built-in command like dir or type which only exists within the command shell;
it might include redirection or pipelining operators, or environment variable substitution;
it might be a script rather than an executable.
There are other cases. If you show us the command line being passed to ExecCmd we may be able to provide more specific advice. (The fact that the same command line is apparently working on some machines is puzzling, but can't be addressed without more information.)
I am looking for the shortest command that would download a file (http) and execute it on Windows.
We assume that the user executing the command is local Administrator and that you cannot use any tools that are not available by default on Windows.
It must work with: Windows 7 and Windows 2008. Extra kudos if someone gives a solution that also works with Windows XP and Windows 2003.
Reasoning: that for deploying stuff on different Windows machines. Using WMI or other methods is not an option because these are not enabled by default and also because machines can be inside our outside a domain, which makes the problem more complex, especially.
Note: If this cannot be done in a command line, a script will do. Let's assume that the file to be downloaded is located at "http://example.com/setup.exe" and that you want to run it with "-y" parameter after it is downloaded.
You specified http, so using ftp command in command line would not be ok? Maybe cscript + VB then?
To download file:
https://serverfault.com/questions/29707/download-file-from-vbscript
To run file:
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run (strHDLocation & "-y")
Whenever I run a batch file on my comuter (64 bit architecture running 64 bit windows 7), the console window that is opened is running in 32-bit mode, and checking the task manager confirms I am indeed running everything as a 32-bit process. I want to run the batch file under a 64-bit process, not a 32-bit process. I have changed the comspec environment variable to point to the proper variable, to no avail. Does anyone know how to fix this so that when I click on the batch file, it everything is run in 64-bit mode.
I realize I could simply open the 64 bit command window and run my batch file. However, this is a workaround and doesn't get at the root of the problem, and won't help when I give file to others.
Thanks,
MM
Are the file associations for .cmd associated with the 32bit cmd.exe or the 64bit cmd.exe?
Can you run the scripts with the full path name to the executable?
"C:\Windows\System32\cmd.exe" /c <batch_name> should run 64-bit
"C:\Windows\SysWOW64\cmd.exe" /c <batch_name> would run in 32-bit
Otherwise, you could change the associations to run the extension .cmd with 64-bit (ftype cmdfile=C:\Windows\System32\cmd.exe /c "%1" %*) and .bat with 32-bit (ftype cmdfile=C:\Windows\SysWOW64\cmd.exe /c "%1" %*).