• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Command prompt listener

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am currently doing a project which needs a way to communicate with windows command prompt, the commands entered by user have to be captured and suspended until the user allows the execution from the program again... I know this is ridiculous but this is what the project requirement, any idea will be appreciated and even better if sample source code is provided. Thanks for viewing
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can the person entered the commands into your program instead of the command prompt? Java can run OS level commands so there could be control that way.

If you have communicate with a separate window, I think you'd have to use a Microsoft language. And even then, I don't know if it is possible.
 
E. Choong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would be perfect solution if I could do that, one way I know is using batch script but I have no idea how am I going to do that. Btw how do I run user input command as administrator? Can it be done without creating a new file to store the command first?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to write a front end to the Windows shell? I'd agree with you that I don't see any reason at all to do that. But maybe there's a good reason for it -- you might find it educational to ask your superiors to explain that reason. It would also be helpful to ask if the full front-end is necessary. For example are you going to support the CD command and others which modify the shell's state?

Anyway it may be possible to run the Windows shell (cmd.exe) inside a ProcessBuilder. It wouldn't be much fun but it's probably doable.

As for running things as administrator, I think you'll find that Windows security frowns upon applications trying to run other applications as administrator. That's a classic way to try to break security. However I might be wrong, maybe the other application will throw up a dialog allowing the user to sign on with administrator credentials.
 
E. Choong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is a college project which intended to test students' capability to complete specific requirements, the closer we get to the requirements the greater mark will be awarded. But my focus now is to 'complete' the project only. One of the requirement is to detect the user action in command prompt window and suspending the command entered for security purpose (e.g virus or trojan code should be suspended). I am not sure is there any methods to do this using processbuilder.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the ProcessBuilder you have your own imitation Windows shell where the user will type commands. Then presumably you're supposed to examine the command and throw it out if it's malware (or whatever your equivalent is which doesn't require five years of research). If it's not "malware" then you'd send it to the real Windows shell via ProcessBuilder.

At least that's my interpretation of the requirements -- although I suspect I haven't seen very many of them.
 
E. Choong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I will do it your way though the full marks method is auto detect the command input...anyway thanks for your kindness
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your assignment require you to use Java? I ask because if you're really supposed to hack the Windows shell (which is what you seem to imply) then Java isn't a good choice at all.

On the other hand you haven't stated your requirements that clearly. Do you have to have a REAL Windows shell and make it behave differently than normal? Or can you have a FAKE Windows shell and make it behave like a real one, only with modifications? There's no point in asking us how to do something if we don't even understand the basics of what you're asking.
 
E. Choong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it has to be Java.
In brief the project requires a back end program which can captures whatever user entered in cmd.exe which is the one embedded in Windows and the back end program should be able to suspend the command execution.

Let's say I am the user now.
I run the back end program then I Start >> Run >> Cmd.exe and enter "netstat -b", the back end should now suspend the command and ask the user whether to continue the execution or not.
 
E. Choong
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to do it in your way and I think it can works. Just that the runas administrator part I got no idea what's going wrong...It says
Does Runtime.exec(String[]) means the input are seperated into several times?

Below is my codings for this command execution part in Java.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic