cmd filename as command in cmd.exe - windows

I am probably missing some lingo to find the answer to a question which I believe has probably been posted already, hence my apologies beforehand.
I wrote a cmd script (myCmdFileName.cmd) that changes some IP configurations using netsh. To run it from cmd, I have to be in the same folder of the script and write in the console myCmdFileName.cmd.
As you know, netsh is a commandline application itself, as I would use it like:
netsh [-flags] [-configs]
What I would like to do is to have my cmd file be called just like as if it was an application like netsh, not worrying about whether I am in the file folder, so like this:
myCmdFileName [-flags] [-arguments]
How would I go about doing that in Windows cmd?
Thanks a lot in advance!

In order to run myCmdFileName from anywhere, either it's parent folder needs to be added to %PATH%, or you can move it / create a symbolic link to it in a folder that already is in %PATH%.

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.

installed program "cppcheck" but command "where cppcheck" (on windows command line) can't find anything

I downloaded and installed the program "cppcheck" (http://cppcheck.sourceforge.net/).
This program has both a GUI (which I can access without problems) and a command line interface.
However, when I go to the windows command prompt and type "where cppcheck", nothing can be found.
Am I crazy? Or is the command line interface for cppcheck only accessible on Unix systems?
Since I usually don't work with Windows, I didn't realise that the "where" command just looks in the current folder and child folders of the current folder. That's why I didn't get any results.
You have to add it in the environment variables since the cppcheck installer does not add it automatically. This way you can use the where command from any folder as it also checks the environment variables too.

copy exe file while it's running?

This following code in my bat file copy's the bat file while it's running into a correct directory in windows 7 but when I convert it to a exe script it no longer works.
Can any one suggest a alternative ? Or any suggestions to why?
if not exist "%programfiles%\toolset\" (
md "%programfiles%\toolset\"
copy "%~f0" "%programfiles%\toolset\"
)
can any one else help I'm pretty sure it's not my converter tool I use as I have tried all the ones listed below but I think the script needs editing for it to function as exe application?
You can try the following nice tool
http://www.battoexeconverter.com/
since you are accessing programfiles you need to be admin
To do this run the cmd in admin mode and try to execute in command line
Download this tool. It works well.
Bat2Exe
You can add administrator manifest to run as administrator when opening the exe file.
I am a batch programmer just like you.
Personally I use this tool;
http://www.f2ko.de/programs.php?lang=en&pid=ob2e
Nice tool, only requires a download, used it multiple times, never dissappointed me, and it is very legit, have no doubts about it!
Pringles

Files with "sh" extension on windows

Our Apache web server works in a Linux environment.
The cgi executables are called via a sh file (for example /cgi-bin/iwsblogin.sh).
The call "/cgi-bin/iwsblogin.sh" is in an html file.
Now I want to make a development and testing environment for this web server on windows.
I do not want to change the calls in the html files from "iwsblogin.sh" to "iwsblogin.bat" just for testing purposes.
Is there a way to configure windows in such a way, that files with the extension ".sh" are treated as executables the same way as ".bat" and ".exe" files?
The contents of this .sh file is for example:
- ms dos commands for setting some environment variables.
- Path of an exe file which should be called.
I know that there exist similar questions on stackoverflow where user suggest using cygwin, but this is NOT an option for me!
Thanks alot in advance
There are some ways to do this.
If the .sh file works when you rename it to .bat, you can use "run as" and select C:\Windows\System32\cmd.exe as default program
Use a sh emulator. For example, msysgit includes one or you can use cygwin (possibly the same source?).
I know you don't want to use cygwin, but why not? Please explain why this isn't an option. It is hard to look for an answer if we don't know why regular answers won't work.

Batch Scripts - Need to specify to use an ANSI console and execute a command

This is a noob question at its best but Google isn't finding what I need.
I have a ruby script that I need to fire off via task scheduler. I thought I did it right by using the following:
cmd /k ruby test.rb
This works when starting the .bat file from the folder. However, if it runs from taskeng.exe it fails because its looking in my system32 folder. I don't want it to run from system32 so how do i format this to run from say, c:/dev/
Again, sorry for the extremely noob question.
You can leave out cmd of that and just use
ruby test.rb
or rather (in your case):
ruby C:\Users\Foo\test.rb
or something like that. Giving the complete path to the script usually helps in finding it ;-)
In any case, if you need the working directory you can set it in the scheduled task itself. Something akin to the following:
       
Likewise, if you actually need cmd in there. Just fill out the Start in field and you have a working directory.

Resources