Sign in to follow this  
Followers 0
SoulSeek

Kingston Datatraveler Macro Partitioner Optimization

1 post in this topic

First a little background: Months ago, I searched google extensively for a way to expedite the creation of SecureTraveler partitions for Kingston USB drives. To break down the process, securetraveler.exe is included on every Kingston USB drive. Running this executable gives you a GUI which takes about 10 seconds to start up. A password has to be entered (twice), followed by a password hint, and to the right is a slider for the size of the partition. (Maximum partition size is approximately 90%.) Once this form was filled and the confirmation button pressed, the program would take about a minute to write an encrypted & hidden partition. (I could not even locate this partition using popular partitioning software, so creating it manually was out of the question.) For my purposes, I then had to go in to the partition and delete 2 files which are automatically created by securetraveler.exe, and delete those same 2 files on the standard partition. Doing this by hand would all be fine and good for a few drives, but I configure hundreds at a time, a few times per month.

After exhausting other possibilities, I decided to try using AutoIt for the first time to automate the GUI process. After that worked well, I found a CLI utility called DevCon which would allow me to disable all but one drive at a time, and I got the script to configure 3 devices at once without any user intervention. (DevCon was necessary because securetraveler.exe complains when more than one kingston device is installed.) After that worked smoothly, I added a 7 port hub and upped the ante to 10 devices. Aside from minor modifications, this is the version I am now posting.

About the script:

Although I have replaced all instances of my path with @MyDocumentsDir, the script is still very much in a state which was only designed to run on my computer. The first forseeable problem is the list of drive letters which USB devices will enumerate to. My PC is set up to install the first to E:. Another issue would be the wrong type of datatraveler, as my program uses the full device name, which is model specific. This is tailored to Datatraveler 400's.

As for possible improvements, my most ambitious thought is to somehow confine the memory space of multiple instances of securetraveler.exe, only allowing them to see and configure a specific device instance. This would theoretically allow me to partition all drives in parallel, but somehow I don't think that's possible without extensive changes to the way Windows handles USB devices.

Another fix would be to somehow tie newly added devices to the drivers for existing devices. The way I handle device installation now is to disable all USB ports, plug in all USB drives, then enable all ports at once. Plugging in one device at a time has in my experience led to bluescreens, due to driver installations clashing with newly discovered devices.

In this script, I rely heavily on _RunDOS, which, although essential for DevCon, Could probably be eliminated in favor of native AutoIt functions. It was a crutch for me because all of my autoit knowledge is based on the help file, whereas I have formidable experience with the windows command prompt.

Without further ado, my masterpiece/massacre

CODE
#include <Process.au3>

#include<File.au3>

#include<Date.au3>

Dim $Count = 0

Dim $CurDriv

Dim $drv[10]

$drv[0] = "E:"

$drv[1] = "F:"

$drv[2] = "G:"

$drv[3] = "H:"

$drv[4] = "I:"

$drv[5] = "J:"

$drv[6] = "K:"

$drv[7] = "L:"

$drv[8] = "M:"

$drv[9] = "N:"

Dim $nam[10]

_RunDOS("devcon enable *DATATRAV*")

Msgbox(0x30, "Securetraveler Format", "IMPORTANT: I:, K:, L:, etc. must not conain anything other than SecureTravelers!")

Dim $ready = 3

While(1)

if $ready=3 Then

$Count = InputBox("SecureTraveler Format", "How many USB drives will be configured?")

If $count < 1 OR $count > 10 OR @error <> 0 Then

MsgBox(0x0, "Securetraveler Format", "input not valid, exiting.")

Exit

EndIf

Switch MsgBox(0x3, "SecureTraveler Format", "Start of Process. Are all drives currently installed & running?")

Case 6

$ready = 1

Case 7

$ready = 2

Case 2

Exit

EndSwitch

Else

$Count = InputBox("SecureTraveler Format", "How many USB drives will be configured?")

If Msgbox(0x1, "SecureTraveler Format", "Start of process. Press OK to disable all USB devices (requires PS2 keyboard)" & _

"Cancel if finished.") = 2 Then

Exit

EndIf

EndIf

If $ready = 2 Then

_RunDOS( "devcon disable *ROOT_HUB*")

Msgbox(0x0, "Securetraveler Format", "all USB devices disabled. Insert all USB drives, then use keyboard to hit OK")

_RunDOS( "devcon enable *ROOT_HUB*")

$t = 0

While($t < 20)

$t = $t + 1

For $w = 1 To $Count

If DriveStatus($drv[$w-1]) <> "Ready" Then

$t = 0

EndIf

Next

Sleep(1000)

Wend

Else

$ready = 2

EndIf

FileDelete(@MyDocumentDir & "\kingston\serials.txt" )

_RunDOS ( "for /f ""tokens=6 delims=&,\,:"" %i in ('devcon FIND *DATATRAVELER*') do @echo %i>>" & FileGetShortName(@MyDocumentsDir) & "\kingston\serials.txt" )

For $m = 1 To $Count

$nam[$m-1] = FileReadLine(@MyDocumentsDir & "\kingston\serials.txt", $m)

If $m > 1 Then

If $nam[$m-1] = $nam[$m-2] Then

Msgbox(0x0, "SecureTraveler Format", "Duplicate serial numbers detected. Program exiting.")

Exit

EndIf

EndIf

Next

$Now = _Date_Time_GetLocalTime()

_RunDOS("@echo " & $count & " Datatravelers configured on " & _Date_Time_SystemTimeToDateTimeStr($Now) & " >>" & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

_RunDOS("devcon disable *DATATRAVELER*")

For $iter = 1 To $Count

_RunDOS("devcon enable @*PMAP\" & $nam[$iter-1] & "*")

_RunDOS("devcon enable @*1.00\" & $nam[$iter-1] & "*")

Sleep(6000)

$x = 0

For $v = 1 to 10

If $x = 2 Then

$v = 1

$x = 0

EndIf

If DriveStatus($drv[$v-1]) = "READY" Then

$x = $x+1

$CurDriv = $drv[$v-1]

EndIf

Next

For $i = 1 To 20

Sleep(1500)

if Drivestatus($CurDriv)="READY" THEN ExitLoop

if $i = 19 Then

if Msgbox(0x1, "No drive found", $CurDriv & " is empty, Serial " & $nam[$iter-1] & " Drives detected: " & $Count & " press OK to abort program") = 1 Then

Exit

EndIf

$i = 1

Endif

Next

Run($CurDriv & "/SecureTraveler.exe")

Sleep(9500)

If WinExists("Error") Then

Send("{Enter}")

Sleep (1000)

If WinExists("SecureTraveler") Then

Send("{ENTER}")

EndIf

Sleep(4000)

Run($CurDriv & "/SecureTraveler.exe")

EndIf

If WinExists("SecureTraveler Login") Then

_RunDOS("@echo Drive already completed:" & $CurDriv & " >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

Else

WinWaitActive("SecureTraveler Welcome")

Send("{ENTER}")

WinWaitActive("SecureTraveler Format")

Sleep(3000)

Send("{TAB}{TAB}passwd{TAB}passwd{TAB}call xxx for the standard password")

MouseClickDrag("left", 750, 435, 750, 621)

Send("{TAB}{ENTER}")

WinWaitActive("SecureTraveler Format Warning")

Send("{ENTER}")

Sleep(5000)

If WinExists("System Settings Change") Then

If WinActive("System Settings Change")Then

Send("!n")

Else

Send("!{TAB}!n")

EndIf

EndIf

WinWaitActive("Format completed")

Send("{ENTER}")

WinWaitActive("SecureTraveler Login")

Send("{ENTER}")

WinActivate("SecureTraveler Login")

Send("passwd{ENTER}")

WinWaitActive("PrivacyZone (" & $CurDriv & ")")

FileDelete($CurDriv & "/migo.exe")

FileDelete($CurDriv & "/migosync.exe")

FileDelete($CurDriv & "/Quick_Start.pdf")

Run(@UserProfileDir & "\Application Data\Kingston\SecureTravelerPhi.exe")

WinWaitActive("Kingston (" & $CurDriv & ")")

FileDelete($CurDriv & "/migo.exe")

FileDelete($CurDriv & "/migosync.exe")

FileDelete($CurDriv & "/Quick_Start.pdf")

If FileExists($CurDriv & "/SecureTravelerPhi.exe") Then

FileDelete($CurDriv & "/SecureTravelerPhi.exe")

FileCopy(@UserProfileDir & "\Application data\Kingston\SecureTraveler.exe", $CurDriv & "/")

EndIf

Sleep(1000)

_RunDOS("@echo Drive: " & $CurDriv & " Device ID: " & $nam[$iter -1] & " Count: " & $Iter & " Size: " & " >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

FileDelete(@MyDocumentsDir & "\kingston\currentsize.txt")

_RunDOS("diskpart /s " & FileGetShortName(@MyDocumentsDir) & "\kingston\sizeprint.txt >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\currentsize.txt")

_RunDOS("for /f ""skip=10 tokens=7"" %i in (" & FileGetShortName(@MyDocumentsDir) & "\kingston\currentsize.txt) do @echo %i >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

Sleep(200)

EndIf

_RunDOS("devcon disable *DATATRAV*")

Sleep(1000)

If WinExists("SecureTraveler") Then

Send("{ENTER}")

EndIf

Next

_RunDOS("devcon enable *DATATRAV*")

_RunDOS("@echo. >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

_RunDOS("@echo --- >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

_RunDOS("@echo. >> " & FileGetShortName(@MyDocumentsDir) & "\kingston\verify.txt")

Msgbox(0x0, "SecureTraveler Format", $count & " devices configured, please verify.")

$Count = 0

WEnd

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0