Zimmy Posted April 9, 2010 Share Posted April 9, 2010 So apparently I can't post in the examples forum because I'm a new member and I need to have 10 posts first. LOL took me a while to figure that one out. I also can't post in the chat forum, again because I'm a new member. I didn't have any specific questions at this time, I just wanted to share a script. I know this is probably not a good way to start off, but come on guys. Don't you think that might throw off new members just a bit? It might at least be useful to have a forum where newbes can at least say hello and introduce themselves. Link to comment Share on other sites More sharing options...
Yoriz Posted April 9, 2010 Share Posted April 9, 2010 It might at least be useful to have a forum where newbes can at least say hello and introduce themselves.Hi and welcome to the forum, i'm sure it wont take long before you have 10 posts rather then allowing fresh accounts to spam everywhere , Some new people can take 10 posts just to get there first problem they are having across GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
kaotkbliss Posted April 9, 2010 Share Posted April 9, 2010 Welcome to the forums. 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Zimmy Posted April 9, 2010 Author Share Posted April 9, 2010 Hi and welcome to the forum, i'm sure it wont take long before you have 10 posts rather then allowing fresh accounts to spam everywhereTrue enough, but if someone is really determined to spam, all the other forums are available for this purpose.Thanks for the welcome guys. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 9, 2010 Share Posted April 9, 2010 You could create a thread here, then press report on your own post and ask for it to be moved .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
jchd Posted April 9, 2010 Share Posted April 9, 2010 @Zimmy, Welcome here! Just curious: what do you want to share with us? @Admiral, Funny, I just read the topic while you were probably in the process of changing your avatar. The old one appeared, but shrunk down to the size of the new one. That made you appear much, much smaller than you really are This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Zimmy Posted April 9, 2010 Author Share Posted April 9, 2010 (edited) I have known about AutoIt for quite some time now, although this is my first time posting on the forum. This is also my first serious attempt at writing a script. I wanted a command line utility that could retrieve the drive letter of a given hardware serial number which I could then copy into a variable for usage in my backup scripts. Since I could find no such thing, I turned to AutoIt and wrote my own. As I'm sure most of you know, the letter of USB removable/fixed drives can often change for various reasons. Initially I designed the script to work with volume labels/serial numbers instead since I knew of no way to retrieve the hardware serial number at the time, but these are unreliable as they will change after formatting. Then I found the functions generously provided by Janneman in this thread http://www.autoitscript.com/forum/index.php?showtopic=87919&st=0&p=631248&hl=serial&fromsearch=1&#entry631248 and I adapted my script. I noticed that this subject has come up a few time so I decided to share in case anyone else might find it useful. I can't take full credit for the completed product since without these functions this would not even be possible, but I did write the rest of the script. I only had to tweak them slightly to fit my requirements. I'm sure it could probably be cleaned up a bit. I don't even use any of the exit codes for example so they could probably be removed, but it works as is and I'm not familiar enough with the functions so I won't risk breaking them. Usage of volume labels is probably redundant at this point, but it was part of the initial script so what the hell. It will retrieve the hardware serial numbers for fixed and removable drives. Card readers will not be detected if they do not contain media. In order for this to work as intended it must be compiled as a console application. I intentionally kept the output simple when there are no errors to make parsing the result unnecessary when copying it into a variable. Sorry if the indentation is bad, but since I'm totally blind it's difficult for me to visualize how it might look. Usage is pretty straight forward. HID [option] [target] Options: /? shows the help screen. /LD <Label> Returns the drive letter of the specified volume label. /SD <SerialNumber> Returns the drive letter of the specified hardware serial number. /DL <DriveLetter> Returns the volume label of the specified drive letter (without colon). /DS <DriveLetter> Returns the hardware serial number of the specified drive letter (without colon). The result can be copied into a variable for usage in a batch script. For example: FOR /F "tokens=*" %%A IN ('HID /SD 357196F34612') DO (SET DRIVE=%%A) expandcollapse popup#cs ---------------------------------------------------------------------------- Description: Retrieve changing drive letters by specified volume label or hardware serial number AutoIt Version: 3.3.6.0 Author: Zimmy AKA Carlos Credits go to janneman for sharing his useful functions. Post #6 in this thread: http://www.autoitscript.com/forum/index.php?showtopic=87919&st=0&p=631248&hl=serial&fromsearch=1&#entry631248 #ce ---------------------------------------------------------------------------- #NoTrayIcon #NoAutoIt3Execute Global $Result, $Target If $CmdLineRaw = "" Then ConsoleWrite("No parameters specified."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf If $CmdLine[0] = 2 Then $Target = $CmdLine[2] If $CmdLine[1] = "/LD" Then If $Target = "" Then ConsoleWrite("Check the command line for errors."&@CRLF&"The /LD parameter should be proceeded by a drive label."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf $Drive = DriveGetDrive("ALL") For $L In $Drive $Label = DriveGetLabel($L) If $Label = $Target Then $Result = StringTrimRight($L, 1) $Result = StringUpper($Result) ExitLoop EndIf Next If $Result = "" Then ConsoleWrite("No drive letter with the specified label was found."&@CRLF) Exit 1 EndIf ElseIf $CmdLine[1] = "/SD" Then If $Target = "" Then ConsoleWrite("Check the command line for errors."&@CRLF&"The /SD parameter should be proceeded by a hardware serial number."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $Drive = DriveGetDrive("ALL") For $L In $Drive $DriveLetter = $L $diskno = GetDiskNo($DriveLetter) $serialno = GetSerial($diskno) If $serialno = $Target Then $Result = StringTrimRight($L, 1) $Result = StringUpper($Result) ExitLoop EndIf Next If $Result = "" Then ConsoleWrite("No drive letter with the specified hardware serial number was found."&@CRLF) Exit 1 EndIf ElseIf $CmdLine[1] = "/DL" Then If $Target = "" Then ConsoleWrite("Check the command line for errors."&@CRLF&"The /DL parameter should be proceeded by a drive letter."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf If Not FileExists($Target&":") Then ConsoleWrite("Drive letter does not exist or contains no media."&@CRLF) Exit 1 EndIf $Result = DriveGetLabel($Target&":") If $Result = "" Then ConsoleWrite("No label for the specified drive was found."&@CRLF) Exit 1 EndIf ElseIf $CmdLine[1] = "/DS" Then If $Target = "" Then ConsoleWrite("Check the command line for errors."&@CRLF&"The /DS parameter should be proceeded by a drive letter."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf If Not FileExists($Target&":") Then ConsoleWrite("Drive letter does not exist or contains no media."&@CRLF) Exit 1 EndIf $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") $DriveLetter = $Target&":" $diskno = GetDiskNo($DriveLetter) $serialno = GetSerial($diskno) $Result = $serialno If $Result = "" Then ConsoleWrite("No hardware serial number for the specified Drive was found."&@CRLF) Exit 1 EndIf ElseIf $CmdLine[1] = "/?" Then Help() Else ConsoleWrite("Invalid option."&@CRLF&"Type /? for help."&@CRLF) Exit 1 EndIf ConsoleWrite($Result&@CRLF) Exit Func Help() ConsoleWrite("HID version 1.0"&@CRLF&@CRLF) ConsoleWrite("Program for retrieving information of a drive by specified label/letter/hardware serial number."&@CRLF) ConsoleWrite("Author: Zimmy AKA Carlos, Apr, 2010"&@CRLF) ConsoleWrite("Credits go to Janneman for sharing his useful functions at the AutoIt forums."&@CRLF) ConsoleWrite("Post #6 in this thread:"&@CRLF) ConsoleWrite("http://www.autoitscript.com/forum/index.php?showtopic=87919&st=0&p=631248&hl=serial&fromsearch=1&#entry631248"&@CRLF) ConsoleWrite("Usage:"&@CRLF) ConsoleWrite("HID [option] [target]"&@CRLF&@CRLF) ConsoleWrite("Options:"&@CRLF) ConsoleWrite("/? shows this help screen."&@CRLF) ConsoleWrite("/LD <Label> Returns the drive letter of the specified volume label."&@CRLF) ConsoleWrite("/SD <SerialNumber> Returns the drive letter of the specified hardware serial number."&@CRLF) ConsoleWrite("/DL <DriveLetter> Returns the volume label of the specified drive letter."&@CRLF) ConsoleWrite("/DS <DriveLetter> Returns the hardware serial number of the specified drive letter."&@CRLF) EndFunc Func GetDiskNo($DriveLetter) $colRows = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition") For $row In $colRows $array = StringSplit($row.dependent, '"') if $array[0] < 2 Then ErrorExit("no dependent", 5) if $DriveLetter = $array[2] Then $i = StringInStr($row.antecedent, "Disk #") if $i = 0 Then ErrorExit("antecdent - unexpected format", 6) $j = StringInStr($row.antecedent, ",", 0, 1, $i) if $j = 0 Then ErrorExit("antecdent - unexpected format (2)", 7) $diskno = StringMid($row.antecedent, $i + 6, $j - $i - 6) return $diskno EndIf Next return -1 EndFunc Func GetSerial($diskno) $colRows = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive WHERE Index = " & $diskno) For $row In $colRows if StringLeft($row.PNPDeviceID, 3) <> "USB" Then return GetSerialNonUsb($diskno) EndIf $array = StringSplit($row.PNPDeviceID, '\') $i = $array[0] if $i < 1 Then ErrorExit("PNPDeviceID, unexpected format", 8) $serno = $array[$i] $i = StringInStr($serno, '&') if $i > 0 Then $serno = StringLeft($serno, $i - 1) EndIf if StringLen($serno) < 3 Then ; If the device doesn't have a serial number, windows manufactures a unique ID that the above code will parse as a 1 digit number. Admit defeat rather than mislead. $serno = "" EndIf return $serno Next return "" EndFunc Func GetSerialNonUsb($diskno) $colRows = $objWMIService.ExecQuery("SELECT * FROM Win32_PhysicalMedia WHERE Tag = '\\\\.\\PHYSICALDRIVE" & $diskno &"'") For $row In $colRows $serno = StringStripWS($row.SerialNumber, 3) return $serno Next return "" EndFunc Edited April 11, 2010 by Zimmy Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 9, 2010 Share Posted April 9, 2010 @Admiral,Funny, I just read the topic while you were probably in the process of changing your avatar. The old one appeared, but shrunk down to the size of the new one. That made you appear much, much smaller than you really are Yeah I saw that too, it's because the new pic has a different aspect ratio than the one your browser had cached. But that aside, it's a nice avatar, isn't it? I stole it right from the SDL website Maybe I should crop out the smaller text, it's not readable on the avatar anyway. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
jchd Posted April 9, 2010 Share Posted April 9, 2010 Stealing logos? Gonna end to jail buddy! Zimmy, Congratulations, that's pretty impressive for a start, especially given your blindness. I hope more people could follow your tracks. Welcome again and kudos. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Zimmy Posted April 10, 2010 Author Share Posted April 10, 2010 Zimmy,Congratulations, that's pretty impressive for a start, especially given your blindness. I hope more people could follow your tracks.Thanks. In a couple of days when I have enough posts I will move it to the examples forum. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now