windows 7 does not activate the path for powershell.
1) C:\Windows\System32\WindowsPowerShell\v1.0 exsists in my path
C:\GitRepository>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0;
2) can't run powershell from cmd implicitly
C:\GitRepository>powershell
'powershell' is not recognized as an internal or external command, operable program or batch file.
3) but it runs explicitly
C:\GitRepository>c:\Windows\System32\WindowsPowerShell\v1.0\powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\Users\user\Androidwork\WebDevelopment\GitRepository> exit
C:\Users\user\Androidwork\WebDevelopment\GitRepository>
Any idea?
Your problem are the spaces in front of the path to PowerShell. Just remove them, i.e.:
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;
I found that one of the programs I installed removed the ; in the path separating the Powershell path from the next path. ;C:\Windows\System32\WindowsPowerShell**v1.0\c:**\program files\other program. Once the semi-colon was put into place, powershell.exe launched successfully.
Related
In my Visual Studio Pre-built command line I have a newly created line
Powershell.exe -file "$(SolutionDir)Folder1\MyPowerShell.ps1"
And in this PowerShell script, it runs an .exe with some parameters
.\MyProgram.exe .\SomeFileArg.xml
When I run just the PowerShell script locally, either as ./MyPowerShell.ps1 or copy pasting the command into my PowerShell, it works.
But when I build my Visual Studio, this doesn't occur. I get the error .\MyProgram.exe.exe : The term '.\MyProgram.exe' is not recognized as the name of a cmdlet, 2> function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the 2> path is correct and try again. If I include the absolute path instead in my PowerShell script, then it works.
How can I achieve this with local paths? Or is there a variable so I don't have to hardcode the absolute path?
You can declare the local path (where the script file resides) as a variable in your code using:
$PSScriptRoot
https://riptutorial.com/powershell/example/27231/-psscriptroot
I am experiencing a very strange behavior, old batch file works well under windows XP. Why doesn't it work when compiling a simple file like hello.c under (Vs2017 + Win10) by a batch file in cmd window?
When realizing that Win10 has new security policy,,I read some articles on Microsoft's website. They recommend using the developer command-line window for command-line compilation.
Indeed, manual operation works well. But when I logged on Win10 as a super administrator and tried to run everything via a batch file,
it didn't work, just finished the environment configuration.
When running the commands in the batch file manually, everything works as expected (executable file successfully generated).
What is wrong with that?
Here is the content of the batch file:
%comspec% /k "C:\Program Files(x86)\Microsoft Visual Studio\2017 \Community\VC\Auxiliary\Build\vcvars64.bat"
cd g:\testdir
g:
cl TestBatFileCompile.c
Preliminary Notes:
vcvars64.bat simply calls vcvarsall.bat and it passes the x64 argument to it, followed by its own (if any)
vcvarsall.bat mainly sets some env vars (set VSCMD_DEBUG=3 prior running it, for verbose output) required for the VStudio build tools to work. Check [MS.Docs]: Build C/C++ code on the command line for more details
I enhanced / simplified your example for more clarity:
script.bat:
#echo off
echo Running vcvars...
%comspec% /K "c:\Install\x86\Microsoft\Visual Studio Community\2017\VC\Auxiliary\Build\vcvarsall.bat" x64
echo Ran vcvars: %ERRORLEVEL%
echo Running cl...
cl /nologo dummy.c /link /NOLOGO
echo Ran cl: %ERRORLEVEL%
dummy.c:
int main() {
return 0;
}
Output:
e:\Work\Dev\StackOverflow\q053523085>dir /b
dummy.c
script.bat
e:\Work\Dev\StackOverflow\q053523085>script.bat
Running vcvars...
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.2
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
e:\Work\Dev\StackOverflow\q053523085>rem HMMM, SOMETHING DOESN'T SEEM QUITE RIGHT. LET'S TRY EXITING CMD...
e:\Work\Dev\StackOverflow\q053523085>exit
Ran vcvars: 0
Running cl...
'cl' is not recognized as an internal or external command,
operable program or batch file.
Ran cl: 9009
What happened?
cmd /K ([MS.Docs]: Cmd) opened a new cmd instance, on top of the existing one (using the same window)
vcvarsall was called in this (2nd) instance, did its job and finished, and things seem to have been left in the air
But after typing exit, it turns out that cl did run, but in the 1st cmd instance (in the background, if you will), and since the variables were not previously set by vcvarsall, it failed
To make things work, invoke vcvarsall using [MS.Docs]: call:
call "c:\Install\x86\Microsoft\Visual Studio Community\2017\VC\Auxiliary\Build\vcvarsall.bat" x64
Output (in a new cmd window):
e:\Work\Dev\StackOverflow\q053523085>dir /b
dummy.c
script.bat
e:\Work\Dev\StackOverflow\q053523085>script.bat
Running vcvars...
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.2
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Ran vcvars: 0
Running cl...
dummy.c
Ran cl: 0
e:\Work\Dev\StackOverflow\q053523085>dir /b
dummy.c
dummy.exe
dummy.obj
script.bat
I have folder run in folder system32. When I run cmd from within Total Commander opening a command prompt window with C:\Users\admin as current directory and want to go into that folder, the following error message is output:
System cannot find the path specified.
When I open cmd directly in folder run, it works perfect. Why?
The command prompt window on opening in C:\Windows\System32\run:
C:\Windows\System32\run>cd..
C:\Windows\System32>cd run
C:\Windows\System32\run>
The command prompt window on simply running cmd:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. Všetky práva vyhradené.
C:\Users\admin>cd..
C:\Users>cd..
C:\>cd windows
C:\Windows>cd system32
C:\Windows\System32>cd run
Systém nemôže nájst’ zadanú cestu.
The following worked for me:
Open the Registry Editor (press windows key, type regedit and hit Enter) .
Navigate to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun and clear the values.
Also check HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun.
There is not only 1 %SystemRoot%\System32 on Windows x64. There are 2 such directories.
The real %SystemRoot%\System32 directory is for 64-bit applications. This directory contains a 64-bit cmd.exe.
But there is also %SystemRoot%\SysWOW64 for 32-bit applications. This directory is used if a 32-bit application accesses %SystemRoot%\System32. It contains a 32-bit cmd.exe.
32-bit applications can access %SystemRoot%\System32 for 64-bit applications by using the alias %SystemRoot%\Sysnative in path.
For more details see the Microsoft documentation about File System Redirector.
So the subdirectory run was created either in %SystemRoot%\System32 for 64-bit applications and 32-bit cmd is run for which this directory does not exist because there is no subdirectory run in %SystemRoot%\SysWOW64 which is %SystemRoot%\System32 for 32-bit cmd.exe or the subdirectory run was created in %SystemRoot%\System32 for 32-bit applications and 64-bit cmd is run for which this directory does not exist because there is no subdirectory run in %SystemRoot%\System32 as this subdirectory exists only in %SystemRoot%\SysWOW64.
The following code could be used at top of the batch file in case of subdirectory run is in %SystemRoot%\System32 for 64-bit applications:
#echo off
set "SystemPath=%SystemRoot%\System32"
if not "%ProgramFiles(x86)%" == "" if exist %SystemRoot%\Sysnative\* set "SystemPath=%SystemRoot%\Sysnative"
Every console application in System32\run directory must be executed with %SystemPath% in the batch file, for example %SystemPath%\run\YourApp.exe.
How it works?
There is no environment variable ProgramFiles(x86) on Windows x86 and therefore there is really only one %SystemRoot%\System32 as defined at top.
But there is defined the environment variable ProgramFiles(x86) with a value on Windows x64. So it is additionally checked on Windows x64 if there are files in %SystemRoot%\Sysnative. In this case the batch file is processed currently by 32-bit cmd.exe and only in this case %SystemRoot%\Sysnative needs to be used at all. Otherwise %SystemRoot%\System32 can be used also on Windows x64 as when the batch file is processed by 64-bit cmd.exe, this is the directory containing the 64-bit console applications (and the subdirectory run).
Note: %SystemRoot%\Sysnative is not a directory! It is not possible to cd to %SystemRoot%\Sysnative or use if exist %SystemRoot%\Sysnative or if exist %SystemRoot%\Sysnative\. It is a special alias existing only for 32-bit executables and therefore it is necessary to check if one or more files exist on using this path by using if exist %SystemRoot%\Sysnative\cmd.exe or more general if exist %SystemRoot%\Sysnative\*.
You just need to:
Step 1: Go home directory of C:\ with typing cd.. (2 times)
Step 2: It appears now C:\>
Step 3: Type dir Windows\System32\run
That's all, it shows complete files & folder details inside target folder.
Details: I used Windows\System32\com folder as example, you should type your own folder name etc. Windows\System32\run
*create a folder in desktop
*open its properties and check the location path as below
properties shows the location
we can find OneDrive(it can be something else in your pc) before the desktop
*Open cmd and run that before calling desktop
Loading OneDrive Before desktop
*Than We can call desktop and create directory without error
opening desktop and creating directory properly
First I start up eshell then I enter the command cd /plink:<user>#<host>:/home/
then I get this error message
Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft
Corporation. All rights reserved.
The command prompt has been disabled by your administrator.
Press any key to continue . . .
I am trying to connect with plink (which is in my path), also after going through the *Messages* buffer I found this.
Couldn't find local shell prompt for (C:\Windows\system32\cmd.exe)
I'm 90% sure that this is because the cmd has been disabled on my machine, because when I try the same setup on a different computer, where I know the cmd is enabled, everything works.
I've modify my .emacs file to have
(require 'tramp)
(set 'tramp-encoding-shell "C:/Windows/System32/WindowsPowershell/v1.0/powershell.exe")
(set 'tramp-encoding-command-switch "-Command")
I get different results, however the results appear to be scrambled nonsense (the third line looks like it could be a prompt, the \ and > characters are in the correct places...).
I managed to dig up a pretty good description of what tramp-encoding-shell is, there's also a related SO question, and here is the tramp-encoding-shell source/documentation on github.
Update
Here is what my screen looks like after trying to unsuccessfully open a plink connection with powershell set as the tramp-encoding-shell.
So I dont know TRAMP but the explanation of what you get is that Windows PowerShell send you back unicode (UTF16), each character is 16 bits in this case the letter an a zero, plus the fact that the End Of Line is carriage return / line feed (0xa, Oxd).
Now for "emacs could not find local shell prompt for PowerShell" error according to TRAMP documentation #Michael Albinus advice seems to be promising.
6.4.2 Running shell on a remote host
Calling M-x shell in a buffer related to a remote host runs the local shell as defined in shell-file-name. This might be also a valid file name for a shell to be applied on the remote host, but it will fail at least when your local and remote hosts belong to different system types, like ‘windows-nt’ and ‘gnu/linux’.
You must set the variable explicit-shell-file-name to the shell file name on the remote host, in order to start that shell on the remote host.
6.4.6 Running remote processes on Windows hosts
With the help of the winexe it is possible tu run processes on a remote Windows host. TRAMP has implemented this for process-file and start-file-process.
The variable tramp-smb-winexe-program must contain the file name of your local winexe command. On the remote host, Powershell V2.0 must be installed; it is used to run the remote process.
In order to open a remote shell on the Windows host via M-x shell, you must set the variables explicit-shell-file-name and explicit-*-args. If you want, for example, run cmd, you must set:
(setq explicit-shell-file-name "cmd"
explicit-cmd-args '("/q"))
In case of running powershell as remote shell, the settings are
(setq explicit-shell-file-name "powershell"
explicit-powershell-args '("-file" "-"))
I am calling .exe file with giving a directory. This directory includes three files and my .exe is executing these three files. Everything works perfect in my computer in the command prompt. The command is :
c:\myfolder\myexe.exe "c:\users\administrator\desktop\proj"
'proj' is my folder which includes three files.
But when I use windows 2008R2, this command does not work. Is there a special command for Windows 2008 R2?
Have you tried to run as administrator? right click and "run as admin", give that a shot and let me know