Det skulle vara ifall URL-formen för Windowsenheter tillåter att man stoppar in lusername och pass. Du kan ju prova med \\luser:pass@127.0.0.1\foo men håll inte andan tills det funkar...
Har inte kommit på nåt bra sätt, men jag har testat lite med en ful-lösning som man kan göra.
Om nån är intresserad så är här lite kod:
<redigerat>
Den här sidan visas inte helt rätt i Opera 6.01.
All kod syns inte. Petar lite på den/dom som har kodat ihop showthread.php ;)
</redigerat>
import java.io.*;
import java.lang.*;
public class CheckConnection
{
public CheckConnection(String pIP, String pLocation, String pUsername, String pPassword)
{
String cmd = "net use * \\\\" + pIP + "\\" + pLocation + " " + pPassword + " /user:" + pUsername;
System.out.print("\nConnecting...");
String msg = execute(cmd);
String tmpDrive = getTmpDrive(msg);
if(tmpDrive == null)
{
for(int i = 0; i < 20000; i++)
{
String timespender = "mohaha";
}
msg = execute("net use /delete " + tmpDrive);
System.out.println(" failed");
System.out.println("Disconnecting... done");
return;
}
System.out.println(" done");
System.out.println("Tmp drive: " + tmpDrive);
System.out.println(msg);
System.out.println("CONTENT\n----------------------------------------------");
File f = new File(tmpDrive);
String[] list = f.list();
for(int i = 0; i < list.length; i++)
System.out.println("\\" + list[i]);
System.out.println("----------------------------------------------\n");
for(int i = 0; i < 20000; i++)
{
String timespender = "mohaha";
}
msg = execute("net use /delete " + tmpDrive);
System.out.println("Disconnecting... done");
System.out.println(msg);
}
private String execute(String command)
{
BufferedReader in = null;
String str = "";
Process mProcess = null;
try
{
mProcess = Runtime.getRuntime().exec(command);
in = new BufferedReader(new InputStreamReader(mProcess.getInputStream()));
String tmpStr = in.readLine();
while(tmpStr != null)
{
str += tmpStr;
str += "\n";
tmpStr = in.readLine();
}
mProcess.destroy();
}
catch(Exception e)
{
mProcess.destroy();
return null;
}
return str;
}
private String getTmpDrive(String msg)
{
String drive = null;
try
{
char first = msg.charAt(6);
char second = msg.charAt(7);
if(first == second)
return null;
drive = first + "" + second;
}
catch(Exception e)
{
return null;
}
return drive;
}
public static void main(String[] args)
{
/** Example of connection to your own c: partition */
new CheckConnection("127.0.0.1", "c$", "myusername", "mypassword");
}
}
258 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849