in case anybody has the same problem i did, i found code that made shortcuts for me... i seem to only have problems setting the icons, but i can live with it... either way, this is it...
import java.io.*;
import java.util.ArrayList;
public class shortcut extends iconSelect {
private byte answer[];
private int offset;
private byte buf[];
private ByteArrayOutputStream bytestream;
/** Creates a new instance of pscc */
public shortcut() {
}
public void WindowsShortcut(
String fulllinkpath, String fulltargetpath, String arguments, String workingdirectory, String iconfile)
throws IOException
{
answer = new byte[1024];
offset = 1024;
buf = new byte[8];
bytestream = new ByteArrayOutputStream(125);
buildLink(fulltargetpath, arguments, workingdirectory, fulllinkpath, setIcon(fulltargetpath));
File linkfile = new File(fulllinkpath);
mkpath(linkfile);
writeFile(linkfile);
}
private final void buildLink(String fulltargetpath, String arguments, String workingdirectory, String fulllinkpath, String iconfile)
throws IOException
{
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
if(iconfile != null)
{
int iconfilelen = write(iconfile);
writeBackward(iconfilelen, 2);
}
if(arguments != null)
{
int argumentslength = write(arguments);
writeBackward(argumentslength, 2);
}
if(workingdirectory != null)
{
int tplength = write(workingdirectory);
writeBackward(tplength, 2);
}
File destf = new File(fulltargetpath);
File linkf = new File(fulllinkpath);
String rp = getRelativePath(linkf.getParent(), destf.getParent());
if(rp != null)
{
if(rp.length() > 0)
{
rp = rp + File.separator + destf.getName();
}
else
{
rp = destf.getName();
}
int rplen = write(rp);
writeBackward(rplen, 2);
}
int postfileoff = offset;
buf[0] = 0;
write(buf, 0, 1);
int finalpathoff = offset;
buf[0] = 0;
write(buf, 0, 1);
write(fulltargetpath);
int localpathoff = offset;
buf[0] = 0;
write(buf, 0, 1);
buf[0] = 16;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 3;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int voltablen = (localpathoff - offset) + 4;
writeBackward(voltablen, 4);
int fileinfooff = offset - 28;
int tmp = finalpathoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
tmp = localpathoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 28;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 1;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 28;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
tmp = postfileoff - fileinfooff;
writeBackward(tmp, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 1;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int filelen = (int)destf.length();
writeBackward(filelen, 4);
buf[0] = 0;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
write(buf, 0, 8);
write(buf, 0, 8);
buf[0] = 32;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
int flags = 2;
if(rp != null)
{
flags += 8;
}
if(workingdirectory != null)
{
flags += 16;
}
if(arguments != null)
{
flags += 32;
}
if(iconfile != null)
{
flags += 64;
}
writeBackward(flags, 4);
buf[0] = -64;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 70;
write(buf, 0, 8);
buf[0] = 1;
buf[1] = 20;
buf[2] = 2;
buf[3] = 0;
buf[4] = 0;
buf[5] = 0;
buf[6] = 0;
buf[7] = 0;
write(buf, 0, 8);
buf[0] = 76;
buf[1] = 0;
buf[2] = 0;
buf[3] = 0;
write(buf, 0, 4);
bytestream.close();
}
private final int write(byte source[], int srcoffset, int length)
{
int newoffset = offset - length;
if(newoffset < 0)
{
length += newoffset;
srcoffset -= newoffset;
newoffset = 0;
}
int atbuff = newoffset;
int atsrc = srcoffset;
for(int i = 0; i < length; i++)
{
answer[atbuff] = source[atsrc];
atbuff++;
atsrc++;
}
offset = newoffset;
return length;
}
private final int write(String text)
throws IOException
{
OutputStreamWriter writeout = new OutputStreamWriter(bytestream);
writeout.write(text, 0, text.length());
writeout.close();
byte bytes[] = bytestream.toByteArray();
bytestream.reset();
return write(bytes, 0, bytes.length);
}
private final int write(byte abyte)
{
int rc = 0;
if(offset > 0)
{
offset--;
answer[offset] = abyte;
rc = 1;
}
return rc;
}
private final int writeForward(int value, int length)
{
int i = 0;
int rc = 0;
for(; i < length && i < 4; i++)
{
byte abyte = (byte)value;
rc += write(abyte);
value >>>= 8;
}
return rc;
}
private final int writeBackward(int value, int count)
{
int rc = 0;
byte tmp[] = new byte[count];
int i;
for(i = 0; i < count && i < 4; i++)
{
tmp[i] = (byte)value;
value >>>= 8;
}
return write(tmp, 0, i);
}
private final String getRelativePath(String from, String to)
{
int flen = from.length();
int tlen = to.length();
char sep = File.separatorChar;
int prevsep = -1;
int sepcount = 0;
StringBuffer fromb = new StringBuffer(from);
StringBuffer tob = new StringBuffer(to);
int i = flen - 1;
if(fromb.charAt(i) != sep)
{
fromb.append(sep);
flen++;
}
i = tlen - 1;
if(tob.charAt(i) != sep)
{
tob.append(sep);
tlen++;
}
i = 0;
for(boolean ok = true; ok && i < flen && i < tlen; i++)
{
char achar = Character.toLowerCase(fromb.charAt(i));
if(achar == Character.toLowerCase(tob.charAt(i)))
{
if(achar == sep)
{
prevsep = i;
sepcount++;
}
}
else
{
ok = false;
}
}
if(sepcount == 0)
{
return null;
}
if(i == flen && i == tlen)
{
return "";
}
prevsep++;
fromb.delete(0, prevsep);
tob.delete(0, prevsep);
int state = 0;
for(i = 0; i < fromb.length()
{
char achar = fromb.charAt(i);
if(achar == sep)
{
state = 0;
i++;
}
else
if(state < 2)
{
fromb.setCharAt(i, '.');
state++;
i++;
}
else
{
fromb.deleteCharAt(i);
}
}
i = fromb.length() - 1;
if(i > 0 && fromb.charAt(i) != sep)
{
fromb.append(sep);
}
fromb.append(tob.toString());
flen = fromb.length();
i = flen - 1;
if(fromb.charAt(i) == sep)
{
fromb.delete(i, flen);
}
return fromb.toString();
}
private final void mkpath(File file)
throws IOException
{
ArrayList need = new ArrayList();
File check = file.getParentFile();
int max = 0;
for(; !check.exists(); check = check.getParentFile())
{
max++;
need.add(check);
}
for(int i = 0; i < max; i++)
{
check = (File)need.get(i);
check.mkdir();
need.set(i, null);
}
check = null;
need = null;
}
private final void writeFile(File dest)
throws IOException
{
int len = answer.length - offset;
FileOutputStream ds = new FileOutputStream(dest);
ds.write(answer, offset, len);
ds.close();
}
//public static void main(String args[])
//{
//(String fulllinkpath,String fulltargetpath,String arguments,String workingdirectory,String iconfile)
//try{
//WindowsShortcut a=new WindowsShortcut("c:/a.lnk","c:/sandro/winhelp.exe","","c:/","c:/icon.ico");
//}
//catch(Exception e){}
//}
}