For a final project, I need to create my own hotspot, using a Java application developed by me, but to execute the CMD command I need administrator privileges, but as I could do it from Java
This is the code I'm using to execute the CMD commands
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
public class Test {
public static void main(String[] args) {
try {
Process proceso = Runtime.getRuntime().exec("netsh wlan set hostednetwork mode=allow ssid=miHotspot key=12345678");
InputStream inputstream = proceso.getInputStream();
BufferedInputStream bf = new BufferedInputStream(inputstream);
byte[] contents = new byte[1024];
int bytesRead = 0;
String cmdContent="";
while ((bytesRead = bf.read(contents)) != -1) {
cmdContent += new String(contents, 0, bytesRead);
}
System.out.println(cmdContent);
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
}
This is the result I get when I run it