How to launch a new cmd window with the correct path from Cygwin? - windows

When I start cmd.exe from start menu, I get the registered (in registry) PATH variable, in a new window.
I want to have exactly the same effect from my cygwin+mintty, and try the followings:
Firstly I try:
bash$ cmd
This gives me a cmd shell, right inside mintty. But I want it to be in a fresh new window. emm... Perhaps I can try:
bash$ cmd /c start cmd
It nicely gives me a cmd shell in a new window. Good. However, the PATH inside that command shell is not the same as a fresh new one.
C:\>path
PATH=C:\cygwin64\usr\local\bin;C:\cygwin64\bin;C:\ProgramData\Oracle\Java\javapa
th;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\W
indowsPowerShell\v1.0;C:\opencv\myrelease\bin;C:\Qt\5.3\mingw482_32\bin;C:\Progr
am Files (x86)\Skype\Phone;C:\Program Files (x86)\Windows Kits\8.1\Windows Perfo
rmance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\cygwin64\
lib\lapack;D:\home\robin_hsu\bin
C:\>
You can see those paths with cygwin64 are not wanted. So, what can I do to get a new fresh cmd window, with correct PATH?
Note: I believe the problem is due to PATH is inheritable, from bash to cmd.
Perhaps someone can give me some hint to get the registered PATH of windows system under cygwin's bash. If that is possible, I can first change the PATH to the desired one, and then call cmd

So, this is basically a duplicate question to Start new cmd.exe and NOT inherit environment?. However, that question doesn't ask to open a new window, and at least for me the answers there didn't give me a correct path. The following command gives both (for me, on XP).
cygstart "$WINDIR\explorer.exe" "$WINDIR\system32\cmd.exe"
The only issue is that it also brings up dialog boxes 'File Download - Security Warning' AND 'Windows Explorer - Security Warning'. This link shows how you can avoid this in general, but I'm not sure if it's possible to remove the warnings for just one specific file. There are also a couple of answers here and here on superuser.com about disabling the warnings.
Hope this helps.

Related

How to run VSCode from the command prompt

I for security reasons cannot run VSCode plainly. I have opened it in the past, but now due to specific reasons, I may only run VSCode from the command prompt. I've tried
start "path/to/file" code and start code "path/to/file"
but none work I'm on Microsoft Windows [Version 10.0.17134.407]
how may I run this by going to Windows+R then 'cmd' then start/ run?
Also it would be great if I could use this for a separate user.
I'm looking for something like:
Runas /user:user\admin /savecred "C:\Program Files (x86)\vs-code.exe"
The use of start is useless if VSCode is in the environment variables.
You can use code C:\Users\%username%\Desktop\File.c for exemple.If it doesn't work, I advise you to use a vbs script instead
You also don't need to run VSCode as an administrator unless you need to edit a file in a protected folder.
Maybe not the exact answer to the question, but...
To start Visual-Studio-Code from CMD into the current folder write:
code %cd%
The environment variable cd tell VS-Code to open it with the current folder
just open a cmd terminal and type code followed by
just open a cmd terminal and type code followed by return keyborad key.
Well shoot, as it turns out that after doing some experimentation I found out that there's a way. Do this:
Simply stick this:
runas /user:Techtiger255\admin /savecred "C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code\Code.exe"
inside of a shortcut (.lnk file)
Open your command line of choice (Powershell or Cmd) and enter the exact file path of your shortcut ex:
"C:\Users\Standard\Desktop/VSCODE.lnk" and hit go, stupidly simple really, just had to find the code.exe file path.

How to launch babun in a specified directory via the command line

now I'm currently using Visual Studio Code and I wanted to make the terminal use babun instead of the default cmd.exe
In fact, I have already managed to do that in theory - the problem is that, unlike with cmd.exe, the directory that I'm in upon starting the terminal is no longer the currently open project, it's just simply /home/myusername (i.e. a path in babun's directory tree).
This kinda sucks, since I don't really want to navigate to my directory every time.
Next, I also found out how to tell babun (in my case, zsh.exe) to use a default directory such as C:/ by adding cd /cygdrive/c to the end of .zshrc - Unfortunately, that's not what I want either, since I don't want babun to always use the same directory.
Now I figured that, seeing as this would be the most comfortable option with VSC*, there might be some console argument that tells zsh.exe to use a specific directory. Sadly, I couldn't find anything, hence this question.
Weirdly enough
Anyone know how to help me out? Appreciate the help :)
*VSC allows you to specify the path to your shell, as well as an array of arguments that will be passed.
You could place your directory into a cmd file and run it as a shell:
d:
#rem note that's important to change the drive 'permanently'
cd d:\home
zsh.exe
And then specify this cmd file as shell to invoke.
Open the desired directory in a file explorer, right click, then select Open Babun here.
Babun currently does not natively support a command line parameter specifying the directory to launch in.
However, there is a pull request in the Babun GitHub which solves the issue. Unfortunately, it doesn't seem to be likely to be accepted anytime soon, though.
To gain access to the feature manually, check out the pull request.

adding a shell context menu item so that I can add folder to path by right clicking

Often at work I have to install new frameworks etc which do not add themselves to path and I have to go through the tedious process of adding the exectuables to path. I therefore decided to add a shell context menu item so that I can add any given folder to the path just by right clicking it and selecting "add to path".
I went through the normal routine of creating a context menu item and I used the following command to add the folder to path:
setx PATH "%PATH%;%1%"
This seems to not evaluate the PATH-variable, and instead replaces my PATH with something like this:
PATH;C:\Program Files (x86)\Android\android-sdk\platform-tools
Is there a way to make the context menu item evaluate %PATH% instead of just ignoring the percentage signs?
I've read about using \,^ and just adding an additional % but none of these approaches seem to work.
In case it matters, this is on a Windows 7 Enterprise computer
Managed to find a permanent solution.
Since setx sets the user path and not the system path, the command mentioned in my question will add all elements in the combined userpath + system path to PATH, effectively doubling its size every time you run the script.
This can either be fixed by removing user path, or as I did, add another user variable and append that to path. I then ended up with the following script afterwards to set the path correctly:
cmd /k setx UPATH "%%UPATH%%;%1%" && exit
This way I don't need to use a bat-file. Using double %s and &s seem to work as a way to escape the character, thus making it look like this to cmd:
setx UPATH "%UPATH%;drive:/theFolderYouRightClicked" & exit
I am still not sure why you have to pass this through cmd in order to see the PATH-variable, but at least this is a semi-clean way of solving my problem
Wowwwwww! I just spent the last 6+ hours of my life trying to be able to add a directory to my path (permanently) from the context menu. Well done Windows!
nircmd.exe elevate "cmd.exe" /k "setx /M PATH %%PATH%%;%1" && exit
Big thanks to #Metareven for some crucial bits (the double %s). Failed a few years back. Links below for related info and hopefully a reg file. AddToPath.reg
Wiped all my paths in the process! Totally worth it! :)
You need nircmd.exe in your C:\windows\system32 folder (or in your path!). The "/k" is necessary for god only knows why. "/M" is for machine, for system, for permanente. (I was like two attemps from giving up and wasting all these hours).
Use RapidEnvironmentEditor (in admin mode) to check, the cmd prompt that opens will not have the current PATH info. Get double ;s for some reason. Still doesn't work by reg file below (anyone know why??) You'll have to use regedit or AdvancedRegistryEditor to make an entry manually (see link below). Use EcMenu.exe to erase context menu mistakes (and other crud).
Windows Registry Editor Version 5.00 **doesn't work**
[HKEY_CLASSES_ROOT\Folder\shell\AddToPath]
"Add To Path"
[HKEY_CLASSES_ROOT\Folder\shell\AddToPath\command]
nircmd.exe elevate "cmd.exe" /k "setx /M PATH %%PATH%%;%1"
This did actually work for me (without the double %s) but only to User PATH:
cmd /k setx PATH "%PATH;"%1 && pause
How add context menu item to Windows Explorer for folders
How to Run a Program Elevated via the Right-Click Menu in Windows ...
This might also work instead of nircmd somehow: https://superuser.com/a/938121 "C:\Windows\System32\cmd.exe"="~ RUNASADMIN"
Tried this, didn't work: https://superuser.com/questions/266974/any-freeware-program-for-adding-editing-path-from-context-menu

Windows CMD: How to create symbolic link to executable file?

My goal is to add a few executables to my PATH (for example, chrome), so that I can call
> chrome
from the command prompt and it will launch Chrome.
I know I could add Chrome's containing directory to my path (set PATH=%PATH%<chrome_path_here>;), but since I have a few executables I want to add, I'd rather make a new bin directory that contains symbolic links to the actual executables and just add that single directory to my PATH.
The Chrome executable is located at
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
So I tried
> mklink chrome.exe "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
That successfully creates a symbolic link for the files (says so in output, and upon examining with > dir). I know my PATH is set up correctly, b/c when I run > where chrome it finds my new symbolic link.
However, when I try to execute chrome with my new link, nothing happens. A new empty window should appear, but nothing happens. No error message in the command prompt or anything.
What am I doing wrong? Am I misunderstanding symlinks in Windows? This is the approach I use in Linux all the time, but I'm new to Windows Cmd.
Thanks!
Most programs will not run from places other than they install location - which is exactly what happens when you try to run it from symlink.
It would be much easier to create CMD/BAT files in that folder with matching names which will launch programs from locations you want:
REM chrome.cmd
start /b cmd /c "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" %*
With Windows 7 I confirm that symlinks do not work, are simply ignored as reported in the original question.
As Harry states in his comment, shortcuts do work, and to me are simpler and easier than writing a separate script for each new command I want to enable under CMD.
He states that you need to add .lnk to your PATHEXT variable in order to do this. I affirm that this does work, and with .lnk added to PATHEXT I can simply enter the name portion of the shortcut to run the command. For example if my shortcut is named "sublime.lnk" and PATHEXT includes .lnk, I can execute the link with the simple command "sublime". Nice!
As an alternative I found that PATHEXT need not be modified if I simply type in the full name of the shortcut, including the .lnk, at my CMD prompt. E.g., I created a shortcut named "sublime.lnk" under %HOMEPATH%/bin, pointing to "C:\Program Files\Sublime Text 2\sublime_text.exe".
Now by placing %HOMEPATH%\bin in my %PATH% I can run sublime via the command "sublime.lnk".
Either of the above are the best way I know of giving access to various commands from around Windows' filesystem from a CMD prompt. I'm not a Windows expert though, and welcome a better or more standardized solution to this problem.
P.S.: I just found out the hard way that you need to ensure the "Start in:" property of any shortcut you use in this fashion is blanked out, or your program will not start in the directory you invoke the shortcut from.
P.P.S.: On a related note, I discovered how to run Windows Explorer (or its replacement) on the directory your CMD session is logged in to: start ..

How to launch a program from perl?

How do i launch firefox from perl? i just need to launch the browser so WWW::Mechanize::Firefox can manipulate it. Searching around stackoverflow ive seen a few solutionsl like system('start cmd.exe /k $cmd) where $cmd is arguments to throw as input once cmd is started.
However, these have not helped me to solve my problem at all.
solutions ive tried
system("start cmd.exe /k start firefox");
system("firefox");
system("cmd","start","firefox");
system("cmd start firefox");
Basically a lot of the alternatives ive found, but i could not launch Firefox browser at all.
You're on the right track. Your second line is almost correct. If firefox is not in your PATH environment variable, you need to supply the complete path.
Click on the Firefox icon on your desktop, open the properties and check where the firefox executable is located. Then use that with your system call.
For me, it looks like this (the ' are for Perl's string, the " are for the Windows shell, because the path has spaces in it):
system('"C:\Programme\Mozilla Firefox\firefox.exe"');
You can test it by opening a new command line (win + r, cmd), cding to the directory where your Perl program is run from, and just entering the command:
C:\Dokumente und Einstellungen\simbabque>"C:\Programme\Mozilla Firefox\firefox.exe"
It will not print anything, but just open a new Firefox window after a couple of seconds. So you'd probably need to hold your program execution in Perl while the browser is starting up.
WWW::Mechanize::Firefox will launch firefox for you but you can use
system 1, qq{$ENV{PROGRAMFILES}\\Mozilla Firefox\\firefox.exe}

Resources