This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

run windows command line statement from java  RSS feed

 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i wanted to build a simple java desktop app where on button click event, some lines of code execute in windows Command Prompt and display the output in a textbox.
I have to run commands as below in administrative privilage and display the output message in a textbox.

netsh wlan set hostednetwork mode=allow ssid=NAME key=PASSWORDis@HARDTOBREAK;
netsh wlan start hostednetwork


I have saved this code in a start.bat file.
i have tried




i have also tried ,,,, but it also doesn't work.


 
Amarjeet Anand
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have tried the code below. It runs correctly and gives output also.


But command doesn't execute and noting comes to output when i change the command from dir to netsh wlan show hostednetwork because this command requires administrative privilage.
 
Campbell Ritchie
Sheriff
Posts: 55292
156
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don&aps;t even think of using processes until ylu have read the classic article which you can find by searching When Runtime.exec won't by Michael Daconta.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!