You are here

JackKnife - convert your U3 Drive into a PA drive with autolaunch

9 posts / 0 new
Last post
ipartola
Offline
Last seen: 16 years 7 months ago
Joined: 2007-10-03 10:25
JackKnife - convert your U3 Drive into a PA drive with autolaunch

USE AT YOUR OWN RISK. The code comes under the BSD license.

I developed this using Delphi. Sorry, but that's all I had available at the time. The basic idea is that you have your U3Drive (the CD-ROM portion) and the U3Main (the main portion). The rest goes like this:

0. Compile attached code into JackKnife.exe
1. Wipe U3Main clean (BACKUP ALL IMPORTANT DATA!).
2. Download UniversalCustomizer.
3. Prepare the following files (see code below): JackKnife.exe, drive.txt, autorun.inf and jackknife.ico (optional).
4. Name your U3Main to be something meaningful to you. Don't give it a generic name likely to be already used, like 'Removable media'. Instead use a name like 'IPARTOLA_U3'.
5. Modify drive.txt to look like this:

IPARTOLA_U3
StartPortableApps.exe

6. Create an ISO of the files you prepared.
7. Burn the ISO onto the drive using UniversalCustomizer.
8. Install PortableApps onto U3Main (now named IPARTOLA_U3).
9. Now every time you insert the drive, it will find the letter assigned to U3Main and execute the command (StartPortableApps.exe in this case). One annoyance that I found is that Windows still tries to autoplay the main portion of the drive which pops up with a new window. Otherwise it works like a charm.

Please let me know how this works out for you.

Igor

autorun.inf

[autorun]
open=JackKnife.exe
icon=hackblade.ico
label=U3

JackKnife.dpf

{
* Copyright (c) 2007-2008, Igor Partola 
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*     * Redistributions of source code must retain the above copyright
*       notice, this list of conditions and the following disclaimer.
*     * Redistributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*     * Neither the name of the  nor the
*       names of its contributors may be used to endorse or promote products
*       derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY Igor Partola ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Igor Partola BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
program JackKnife;

uses
  Windows,
  Dialogs,
  ShellAPI,
  SysUtils;

{$R *.res}

function fstrVolumeName(strDrive : string) : string;
var
  blnResult           : boolean;
  strVolumeNameBuffer : string;
  chrArrayFileSystem  : array [0..MAX_PATH - 1] of char;
  dwdVolumeSerialNum  : DWord;
  dwdMaxCompLength    : DWord;
  dwdFileSystemFlags  : DWord;
  dwdSize             : DWord;
  intZeroPos          : integer;
begin
  {set up buffers}
  dwdSize := 260;
  SetLength(strVolumeNameBuffer,dwdSize);
  FillChar(chrArrayFileSystem,dwdSize,#0);
  {call function}
  blnResult := GetVolumeInformation(PChar(strDrive),PChar(strVolumeNameBuffer),
               dwdSize,@dwdVolumeSerialNum,dwdMaxCompLength,dwdFileSystemFlags,
               chrArrayFileSystem, dwdSize);
  {exit if function caused error}
  if blnResult = False then
    begin
      result := '';
      exit;
    end;
  {trim string to label only for result value}
  intZeroPos := Pos(#0,strVolumeNameBuffer);
  if intZeroPos > 0 then
    Result := copy(strVolumeNameBuffer,1,intZeroPos - 1)
  else
    Result := strVolumeNameBuffer;
end; {get the drive label}

Function findU3Main : String;
Var
  I    : Integer;
  Drives: Integer;
  Tmp   : String;
  FileHandle : TextFile;
  DriveLabel : String;
  LaunchCommand : String;
begin
  if not FileExists('drive.txt') then exit;

  AssignFile(FileHandle, 'drive.txt');
  Reset(FileHandle);
  ReadLn(FileHandle, DriveLabel);
  ReadLn(FileHandle, LaunchCommand);
  CloseFile(FileHandle);

  Drives := GetLogicalDrives;
  Result := '';
// units A=0 to el Z=25
  For I := 2 To 25 Do
    If (((1 Shl I) And Drives)0) Then
    Begin
      Tmp := Char(65+I)+':\';
      If (GetDriveType(PChar(Tmp))=DRIVE_REMOVABLE) Then
        begin
          if (fstrVolumeName(Tmp) = DriveLabel) then
            begin
              Result := Tmp + LaunchCommand;
              exit;
            end;
        end;
     End;
End;

// Main portion of the program. Find the main portion of the U3 
// drive and run the command.
var command : PAnsiChar;
begin
  command := pchar(findU3Main());

// If you so desire you can add a splash window here

  if StrLen(command) > 3 then
    ShellExecute(0, 'open', command, nil, nil, SW_SHOWNORMAL);
end.

digitxp
digitxp's picture
Offline
Last seen: 13 years 3 months ago
Joined: 2007-11-03 18:33
Heheh...

We use the AutoLauncher4u3 since it's been here longer.

Insert original signature here with Greasemonkey Script.

Zach Thibeau
Zach Thibeau's picture
Offline
Last seen: 2 years 2 months ago
Developer
Joined: 2006-05-26 12:08
Not

Not Bad, I'll try it when and I buy a new us drive

your friendly neighbourhood moderator Zach Thibeau

ZachHudock
ZachHudock's picture
Offline
Last seen: 2 years 6 days ago
Developer
Joined: 2006-12-06 18:07
Looks cool. If I get a U3

Looks cool. If I get a U3 drive, i'll certainly test it out

The developer formerly known as ZGitRDun8705

alpha1
alpha1's picture
Offline
Last seen: 9 years 8 months ago
Joined: 2007-07-08 20:02
what did you use to compile

what did you use to compile this code and how did you do that?

Lead, Follow, or get out of the way.

digitxp
digitxp's picture
Offline
Last seen: 13 years 3 months ago
Joined: 2007-11-03 18:33
It's

Delphi
I wish there was an OSS compiler.

Insert original signature here with Greasemonkey Script.

alpha1
alpha1's picture
Offline
Last seen: 9 years 8 months ago
Joined: 2007-07-08 20:02
turbo delphi? cuase i have

turbo delphi?
cuase i have that and opened the Kackknife.dpf in it but i see nothing to compile it with

Lead, Follow, or get out of the way.

digitxp
digitxp's picture
Offline
Last seen: 13 years 3 months ago
Joined: 2007-11-03 18:33
I thought you were

supposed to open JackKnife.pas

Insert original signature here with Greasemonkey Script.

alpha1
alpha1's picture
Offline
Last seen: 9 years 8 months ago
Joined: 2007-07-08 20:02
maybe i have no idea what I'm

maybe i have no idea what I'm doing (as always)

but the original post says JackKnife.dpf
I'll try .pas

if anyone has the jackknife.exe file could they please give me a copy

Lead, Follow, or get out of the way.

Log in or register to post comments