Sign in to follow this  
Followers 0
mrfishopolis

Windows Command Line

6 posts in this topic

Using windows command line, I can not for the life of me remeber how to get a exectuable file to be mapped to a single command that is callable from any directory.

Ex: ftp maps to C:\windows\System32\ftp.exe

If someone has an answer this would make my day.

Edited by mrfishopolis
0

Share this post


Link to post
Share on other sites

just make a batch file and put it in the system32 folder. example, like if you want nmap but, nmap is in C:\nmap\nmap.exe, or maybe a shortcut would work, and a shortcut would be the same thing, really.

It would be great if windows had the "ln" command

-lowlevelup

Edited by lowlevelup
0

Share this post


Link to post
Share on other sites

I think what your looking for is the "set" command on Windows.

0

Share this post


Link to post
Share on other sites

on a semirelated note:

a while back i made a registry&wsh thing to start apps. It involves registering new protocols and using wsh vbscript as a handler for it to spawn the actual application.

in this example, i made a ssh protocol handler

so in a command line window, address bar in IE or firefox, or in the run command: if i type ssh://username:password@host:port then it pops up putty and logs in. This is not what you asked for, but may be of some help. Note the registry keys, that is how you would change the protocol handler for ftp for example.

run the .reg or manually edit your registry and then put the .vbs file in some known location (here c:\)

install.reg:


[HKEY_CLASSES_ROOT\ssh]
@ = "URL:ssh Protocol"
"URL Protocol" = ""
[HKEY_CLASSES_ROOT\ssh\shell]
[HKEY_CLASSES_ROOT\ssh\shell\open]
[HKEY_CLASSES_ROOT\ssh\shell\open\command]
@ = "wscript.exe c:\\putty.vbs %1"

[HKEY_CLASSES_ROOT\telnet]
@ = "URL:telnet Protocol"
"URL Protocol" = ""
[HKEY_CLASSES_ROOT\telnet\shell]
[HKEY_CLASSES_ROOT\telnet\shell\open]
[HKEY_CLASSES_ROOT\telnet\shell\open\command]
@ = "wscript.exe c:\\putty.vbs %1"

and here is putty.vbs: it is relatively complicated because it handles both telnet and ssh but you get the idea.


Set ArgObj = WScript.Arguments
path = "%PROGRAMFILES%\putty\putty.exe"
argument = ArgObj(0)
Dim proto

if right(argument,1) = "/" then argument = left(argument,len(argument)-1)
'<SomeArgumentWasPassed>
If lcase(left(argument,6)) = "ssh://" Then
   proto = "ssh"
   argument = mid(argument,7,len(argument)-6)
End If
If  lcase(left(argument,9)) = "telnet://" Then
   proto = "telnet"
   argument = mid(argument,10,len(argument)-8)
End If
If Len(proto) > 0 Then
   at = instr(argument,"@")
   if at Then
       '<UserNameAndOrPasswordSpecified>
       userhash = left(argument,at-1)
       if len(userhash) Then
           '<UserNameSpecified>
           colon = instr(userhash,":")
           if colon Then
               '<UserNameAndPasswordSpecified>
               username = left(userhash,colon-1)
               password = mid(userhash,colon + 1,len(userhash)-colon)
               '</UserNameAndPasswordSpecified>
           else
               'we have only a username
               username = userhash
           end If
           '<UserNameSpecified>
       end if
       hosthash = mid(argument,at +1,len(argument)-at)
       colon = instr(hosthash,":")
       if colon Then
           '<HostAndPortSpecified>
           host = left(hosthash,colon-1)
           port = mid(hosthash,colon +1,len(hosthash)-colon)
           '</HostAndPortSpecified>
       Else
           '<HostSpecified>
           host = hosthash
           '</HostSpecified>
       End if
       '</UserNameAndOrPasswordSpecified>
   Else
       '<NoUserNameAndOrPasswordSpecified>
       colon = instr(argument,":")
       if colon Then
           '<HostAndPortSpecified>
           host = left(argument,colon-1)
           port = mid(argument,colon + 1,len(argument)-colon)
           '</HostAndPortSpecified>
       Else
           '<HostSpecified>
           host = argument
           '</HostSpecified>
       end if    
       '</NoUserNameAndOrPasswordSpecified>
   end if
   'text = text & right(argument,len(argument)-6)
   '</SomeArgumentWasPassed>
end if
text = chr(34)&path& chr(34) & " -"&proto&" "
if len(username) then text = text & username & "@"
If len(port) then text = text & " -P " & port
text = text & " " &host
if len(password) then text = text & " -PW "& password
'WScript.Echo text
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run text,1

Edited by replax
0

Share this post


Link to post
Share on other sites
Using windows command line, I can not for the life of me remeber how to get a exectuable file to be mapped to a single command that is callable from any directory.

Ex: ftp maps to C:\windows\System32\ftp.exe

If someone has an answer this would make my day.

It sounds to me like you want the executable to be in the PATH? As you mentioned, ftp.exe is in C:\windows\System32\ which should already be part of the PATH variable so you're probably thinking of something else.

[how to suck eggs]

As riscphree mentioned earlier, you can use the SET command to mess with the PATH variable. If we assume that you want to run C:\nmap\nmap.exe from anywhere then you would ammend the path thus:

set PATH=%PATH%;C:\NMap\;

This will add the C:\NMap directory to the string of directories that Windows will search when it can't find the filename that you've entered in the current directory, nmap in our example here.

[edit]

The above post is a fine example of why NOT to post at 2 in the morning. Basically I'm a crack head.

What I mentioned above WILL work, but the changes you make with SET will only be valid for the life of the cmd.exe window. There is a resource kit tool called SETX that you can use like this:

setx PATH "%PATH%;C:\NMap\;"

This will permanantly set the current user's PATH variable. If you want to set it globally you just add a -m on the end:

setx PATH "%PATH%;C:\NMap\;" -m

Or, as the esteemed Mr mad_jimi_simi noted below, you can do it via the GUI (there's an example with pictures here).

The one thing to note with BOTH of these methods is that the changes will only come into effect next time you open a cmd.exe window.

Sorry for the confusion.

[/edit]

[/how to suck eggs]

Edited by kynan
0

Share this post


Link to post
Share on other sites

Droops had an interesting TWAT episode where he created batch files that performed Windows command line functions (dir for example), and gave the batch file the name of the linux command (C:\WINDOWS\ls.bat for example). So at the command prompt, if you typed "ls", it would execute a "dir" command. I played around, and using variables in batch files, you can accept the usual command parameters to make it even more linux-ish. I got so used to using linux commands that it made the Windows command prompt a bit more fun. However, when working at the command prompt on someone else's computer, I frequently try to type linux commands to no avail. I then bang my head against my knee out of frustration.

Not really what you were asking, but this thread just reminded me of that episode. You could do the same to launch programs. Just name the batch file to whatever you want your command to be ("mycommand.bat"), place it in a system directory or any directory specified in your environment varibles PATH (right-click My Computer -> Properties -> Advanced Tab -> Environment Variables button -> System variables listbox -> Path variable). You then just type "mycommand" at the prompt and your batch file executes.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0