How do I set the path automatically on login when ssh'ing to a Windows machine? - windows

I want to set the path on a Windows server so that when I log in via SSH the directory
C:\Program Files (x86)\Git\libexec\git-core
is in my path.
I can ssh to the server, but %PATH% does not contain the directory above.
Is there are file like ".profile", ".bashrc", or ".login" where I can add a directory to the path?

You can also set your path from the command line with
setx PATH "%PATH%;C:\Program Files (x86)\Git\libexec\git-core"
I'm having the same problem as you, though, which is my path is different when I'm at a command prompt at the keyboard vs logged in remotely. Still trying to figure that one out.

Related

Setting default path with custom variable in windows 10pro

I have been trying to get windows to recognize shortcuts for developer tools. Things like adb for C:\Users\myusername\Andriod\platform-tools\adb.exe. I have tried using CMD and Powershell but they both don't add the PATH I tried the GUI and it doesn't show up.
I've tried setx path "%PATH%;C:\path\to\C:\Users\myusername\Andriod\platform-tools\adb.exe" in powershell and cmd then restarted powershell or cmd
input the variable adb but it pulls a command not recognized error.
Did you try the following?
Adding the path "C:\Users\myusername\Andriod\platform-tools" to your system/user PATH variable? You can do this by start-> environment variable -> environment variable and under system or user, edit the PATH variable and add the above link. Once you do this, restart CMD for it to work.
Add the executable in one of the already existing locations that are in the PATH variable. (Although this is one method, I would not suggest this). Again, if the executable has any dependencies, it must be in a place where the exe itself can access.

MobaXterm windows PATH variable prepends system32 directory

So launching CMD in MobaXterm you have the option to user Windows Path variable. However, rather than using the same %PATH%, MobaXterm prepends the following directories into %PATH%.
C:\Users\${USER_ID}\AppData\Local\Temp\Mxt82\bin;C:\WINDOWS;C:\WINDOWS\system32;
I wonder why it does this? This gives us inconsistent behavior as if we launched cmd directly.

"ERROR: Invalid syntax. Default option is not allowed more than '2' time(s)." using SETX

I thought I had this working at one time but recently my command quit working. My research here and abroad is not turning up anything I have not attempted already. Perhaps there is some other variable I am missing that SETX is looking at?
My command:
setx /s servername PATH "%Path%";"c:\program files (x86)\java\jre7\bin";"c:\program files (x86)\java\jre7\bin\client" /m
I have tried the same command against a couple of Win2k8 servers to no avail. This has worked but is now producing the error above. I usually run this within a batch file against a list of several servers to push Java out. (Path to java is not being set unless we manually create the entries when remotely installed.)
The existing path on the server I am attempting to update is this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\BMC\Patrol3\bin;C:\BMC\common\globalc\bin\Windows-x86;C:\BMC\common\globalc\bin\Windows-x86-64;C:\BMC\Patrol3\BEST1\9.5.00\bgs\bin
I did clean up a couple duplicate path entries. Aside from that I did not find anything unusual to me.
Edit:
Tweaking the command to remove some of the quotation marks does allow it to run but with that, it imports the path of the local system replacing the remote systems path and appends the desired path entries.
The revised command:
setx /s servername PATH "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /m
In hopes of fixing this new problem, I am attempting to run the command with psexec. Doing so brings me back to my original problem, "Default option is not allowed more than '2' time(s)". Depending on how I modify the quotes when using psexec I can get "To many Arguments" or command succeeded, path truncated which ends up being the local path being applied on the remote server once again.
The most promising of my attempts:
psexec \\servername -u domain\user -p p#ssw0rd "c:\windows\system32\setx" "Path "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /M"
Using the "-s" option on psexec produces the same error, just less detail.
I was able to update the path value on remote systems by creating a batch file to be executed remotely.
Contents of "setJava7path.cmd"
setx Path "%Path%";"%ProgramFiles(x86)%\java\jre7\bin";"%ProgramFiles(x86)%\java\jre7\bin\client" /m
To execute I utilized psexec which copied the batch file to the remote system and executed the command.
psexec \\systemname -c setJava7path.cmd
It adds / changes a line to my overall deployment script but that is livable.

Problem with relative paths(*.bat + VMWARE + Windows 2003)

This may be a question for ServerFault but I was more interested in understanding the methodology that the OS uses to resolve relative paths. I have two VMware instances of Windows 2003. I am trying to run a batch file that starts running another batch file within its folder path. The script runs fine on one VM but on the other VM it fails to execute with the error:
> The System cannot find the file specified
The script I am trying to run is script.bat:
start /d FOLDERNAME /b /WAIT AnotherScript.bat %~n0%~x0
I have put both my files within the same folder structure under the C:\ drive on both machines. The file AnotherScript.bat resides within FOLDERNAME on both the VMs.
It is not a permissions issue(?) since I show up as an administrator on both VMs.
I was wondering why would I get an unable to resolve relative paths on one machine vs. the ability to resolve it on another machine.
Thanks
First check if the folder in which both are lauching are the same. Try adding ECHO %CD% before calling the 2nd script to check the directory in which it is getting launched.
Also check if the path where the 2nd bat file resides is set in the %PATH% variable in the 1st VM.
Where does command prompt start by default in both VMs?

Commands Visibility at Command Prompty Not Using System32

Let's say I have a foo.exe file that I want to use it from windows command prompt. I will go to the folder which contains foo.exe and run it. Now, if I want global access for foo.exe from anywhere in the command prompt I will put foo.exe in System32 folder.
This process makes System32 a dump ground. I was wondering if there are any other ways of globally accessing the .exe or bat files without having to dump all of them in System32 folder.
Change your PATH environment variable. i.e. "set path=%path%;[newdir]"
where [newdir] is the new directory you want searched when you run commands.
The PATH Environment Variable
You can either do this programatically (StackOverFlow) or follow these instructions
How to set the path in Windows 2000 / Windows XP, another one.

Resources