Gouki Posted May 6, 2006 Share Posted May 6, 2006 The main objective of this thread is to give users a 'central' thread containing all the code they may need.You can post your code here, however, there are simple rules you must follow. This will keep this thread clean and organized, making life easier to everyone.These fields are required unless otherwise noted. All submissions without them will be deleted.Description: Give us a small description of what the code/application does.Screenshot - Optional - In case you're posting an application and not a script (where you can easily paste the code into a code box), feel free to post a screenshot if you think it would be useful.Programming Language: All programming languages are accepted. Simply specify which one you app or script uses.That's it. Now ATTACH (not post) your code.Please, only one submission per post.Don't make posts asking for help or commenting on an application/code you saw here. Instead, PM the author with the request.Posts that are not considered to be submissions will be deleted.Thank you for participating.P.S: Taking someone else's work and pretending it is your own is not something you should do. Always credit your sources. Any code here found to be plagiarized without source credits will be deleted. Link to comment Share on other sites More sharing options...
Yzöwl Posted May 8, 2006 Share Posted May 8, 2006 (edited) Have you ever wanted to pause a NT Command Script, without using the ping command, vbs or a third party utility?Here's my way of doing it! (see the bottom of this post for the attached file)This is an NT Command Script, (batch file), just place addelay.cmd somewhere in your path and call it from another script, like this:CALL ADDELAY [mins] [secs]Where [mins] is an integer representing the number of minutes you wish to delay for.and[secs] is an integer representing the number of seconds you wish to delay for.If you don't wish to have any minutes, your first parameter, [mins], should be 0Examples:CALL ADDELAY 0 15delays the running NT Command Script by 15 secondsCALL ADDELAY 1 7delays the running NT Command Script by 1 minute and 7 secondsCALL ADDELAY 3delays the running NT Command Script by 3 minutesCALL ADDELAY 0 72delays the running NT Command Script by 72 secondsAdditionally:CALL ADDELAYdisplays an error message and delays the running NT Command Script for five secondsCALL ADDELAY 0displays an error message and delays the running NT Command Script for five secondsCALL ADDELAY 0 0displays an error message and delays the running NT Command Script for five secondsThis is not intended to be a precision timepiece, so please don't start complaining about it being slightly inaccurate. I know it is, but it does the job for which I intended it. I hope it is useful!addelay.cmd Edited May 8, 2006 by Yzöwl 1 Link to comment Share on other sites More sharing options...
phkninja Posted May 23, 2006 Share Posted May 23, 2006 (edited) Program: Blowfish File Encyptor (command line) Description:This is a small application i wrote that implements the Blowfish Encryption algorythm. The archive contains a header for Blowfish Encryption/Decryption, a Header file to implement MD5 hash algorythm (required by command line program), and a command line program source file.The command line program is a fully functional file encryptor. If the supplied password is less than 128 bits [16 characters long] it uses an MD5 hash of the password as a key, as it is recommended that password be at least 128 bits to be secure, and can take password up to 56 characters long which is the limit of the Blowfish algorythm.Language: C, but will work in C++(Removed from my website)blowfish.7zorblowfish.exe Edited February 2, 2007 by phkninja Link to comment Share on other sites More sharing options...
Maelstorm Posted May 23, 2006 Share Posted May 23, 2006 (edited) Description: Function to change computer name.Language: AutoIT3 3.1.1.x betaUsage:Call function with name you want to changed the computer to.Returns 0 on success, 1 on error.Reboot computer for changes to take effect.SetSystemName.txtDescription: Function to Join a Workgroup (Windows XP Only)Language: AutoIT3 3.1.1.x betaUsage:Call function with name of desired workgroup that you want to join.Returns 0 on success, 1 on failure.Reboot computer for changes to take effect.SetNetworkWorkgroup.txtDescription: Function to join a Domain (Windows XP Only)Language: AutoIT3 3.1.1.x betaUsage:Call function with name of domain to join, a userid, and password.The UserID and Password should be an admin account on the domain controller.Reboot computer for changes to take effect.SetNetworkDomain.txtNote to Moderator:I posted these as separate posts, but for some reason the board keeps merging them into one large post. Edited May 23, 2006 by Maelstorm Link to comment Share on other sites More sharing options...
Djé Posted May 25, 2006 Share Posted May 25, 2006 Description: Substring search function that can search starting from the left or from the right.Programming Language: Visual Basic (for Applications, but I guess it works also with VB & VBS).VB functions for searching a substring in another string (like Instr()) all start from the left and search in the right direction, with an optional start parameter to start searching only from this position.No easy way to find the last occurance of the substring (like when you want to discriminate a file name from a file path searching for "\").The attached function can accept a negative 'start' argument to start the search left wise from the end of the string, with a 'start' offset (also from the end).Both the offset and the returned position still apply to the leftmost character of the substring. Example usage code provided in the attachement.The 'maths' involved to avoid an unlegant 'If start<0...' were interesting...There is also another way arround using StrReverse(), but it is in fact not much simpler.stringFindFirstLR.vb.txt Link to comment Share on other sites More sharing options...
RogueSpear Posted June 16, 2006 Share Posted June 16, 2006 Description: Generate MD5 Values of FilesLanguage: Visual Basic 2005 [Function]Usage: String = GenerateFileHash(filename)My initial search for examples on this led me to an example of using MD5 with strings. Specifically, using MD5 to secure the transmisson of passwords. You can find that article here. I spent quite some time trying to rework the example code to work with files rather than strings. Further searching yielded only a single example, in C#, at the MSDN forums. While not very helpful for VB, it did open my eyes to the BitConverter function.Private Function GenerateFileHash(ByVal SourceFile As String) As String Dim strFile As New IO.FileStream(SourceFile, IO.FileMode.Open, IO.FileAccess.Read) Dim MD5 As New MD5CryptoServiceProvider() Return BitConverter.ToString(MD5.ComputeHash(strFile)).Replace("-", "") strFile.Close() End FunctionGenerateFileHash.vb.txt Link to comment Share on other sites More sharing options...
sebbe1991 Posted June 17, 2006 Share Posted June 17, 2006 Description: Sets the computernameLanguage: C++ScreenshotSetComputerNameGUI.7z Link to comment Share on other sites More sharing options...
Djé Posted June 17, 2006 Share Posted June 17, 2006 (edited) Description: VB Array Functions.Programming Language: Visual Basic (for Applications, but I guess it works also with VB & VBS).Usage: Have the whole set in a module of your project, or just insert in your code the function(s) that you need (beware of dependancies).VB's handling of arrays is under everything. Especially when compared to other languages.Those functions will come handy to everyone seeking to make something out VB arrays.Yes, they are the same as those I'm using in my Excel ProgsLists generator.'-Double-check but most of them should work with any array, even not 0-base-indexed (no relevant for VBS).'-Arrays are normally passed ByRef, so the args are updated by the function.'-They are fairly tested, but the usual disclaimer apply.Not all array handling functionnalities of other languages are implemented here. If you have other functions that you'd like to be included in the set, PM me.Content:'* Returns true if the array has at least the specified number of elements (default to one element)Function isSetArray(anArray, Optional minSize As Integer = 1) As BooleanDim myArray(), anythingisSetArray(myArray) -->FalseisSetArray(anything) -->FalsemyArray=Array("test")isSetArray(myArray) -->TruemyArray=Array()isSetArray(myArray) -->FalsemyArray=Array("a", "b", "c")isSetArray(myArray, 3) -->trueisSetArray(myArray, 4) -->False* Drops the first element out of the array and returns it- in the array, the other elements' index is decreased by oneFunction arrayDrop(anArray())* Pops the last element out of the array and returns it- the array passed as an argument loose this elementFunction arrayPop(anArray())* adds 'avalue' as a new element at the end of the arrayFunction arrayAdd(anArray(), aValue)* Merges the 2 arrays in the 1st one and returns itFunction arrayMerge(Array1(), ByVal Array2)* Like the 'Join' function but with more possibilitiesFunction implode(anArray(), Optional separator As String = " ", Optional keepEmptyElem As Boolean = False)* Like the 'Split' function but actually working with line breaks! - Try: Split(myString, vbcrlf) -> errorFunction explode(theString As String, Optional separator As String = " ", Optional keepEmptyElem As Boolean = False)* Translates an array containing arrays [like array(i)(j)] to a bidimentional array [like array(i, j)]- The second dimension depends on the dimension of array(0)- The array passed as an argument is NOT updatedFunction arrayRect(anArray())* Similar to Splice in JS: remove/insert some elements in the array- starts operating at the 'start' position (from 1st element=0)- removes 'count' elements- inserts the elements of 'additions', which has to be an array (if passed)Function arraySplice(anArray(), start As Integer, Optional count As Integer = 1, Optional additions As Variant)Restriction: Except for 'isSetArray()' and the second arrays of arrayMerge & arraySplice, the array arguments are passed ByRef so they must be declared as arrays prior to pass them to the functions:Dim myArray()arrayAdd myArray, newValueTo change this and be able to pass anything (!), you may remove the '()' in the declaration:Function arrayAdd(anArray(), aValue)[Edits]: - v0.0.2. Improvements to isSetArray, arrayMerge, implode & arraySplice. Addition of explode.- Testing Sub() procedure at the bottom of the module.More_ArrayFunctions.bas.txt Edited June 20, 2006 by Djé Link to comment Share on other sites More sharing options...
Guest Nazi Moderation Posted July 2, 2006 Share Posted July 2, 2006 (edited) Purpose: to wait a specified number of secondsLanguage: batch script, so just stick this code inside a text file and name it .bat or .cmd@echo offset start=set secstowait=%1if defined secstowait (goto :wait)echo ììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììecho USAGE: %0 X where X is number of seconds to wait.echo EXAMPLE: %0 30echo (C) 2006 MSFN.ORGecho ììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììììgoto :eof:waitFOR /F "tokens=1-3 delims=:." %%i in ("%time%") do set hour=%%i&set minute=%%j&set seconds=%%kif not defined start set /a start=(%hour%*3600)+(%minute%*60)+%seconds%set /a current=(%hour%*3600)+(%minute%*60)+%seconds%set /a elapsed=%current%-%start%if %elapsed% LSS 0 (goto :eof)if %elapsed% GEQ %secstowait% (echo Finished! Waited %elapsed% seconds.) else goto :waiti got the idea for this off of the MSFN forums, but then i couldn't find the original program, so i created this. it is 100% my code and completely free to distribute.just updated the script so that it will exit if midnight strikes while the script is running. if you wish you could edit it to return an errorcode when that happens.wait.cmd Edited July 2, 2006 by Nazi Moderation Link to comment Share on other sites More sharing options...
cluberti Posted October 26, 2007 Share Posted October 26, 2007 Description: VBscript subroutine to run elevated on Vista/Server 2008 when UAC is enabled.Programming Language: VBScriptUsage: When a VBScript needs to run on Vista/Server 2008 and access parts of the system UAC protects when UAC is enabled, the script will simply fail. However, after calling this subfunction from your script, UAC will prompt when the script is run, and the script will continue once UAC elevation is allowed. Note that this also works on 2K3/XP when the user running the script is a non-Administrative user (a runas dialog will appear instead of a UAC prompt, obviously, but otherwise the same principles apply).VBScript_RunElevated.vbs.txt Link to comment Share on other sites More sharing options...
gunsmokingman Posted October 29, 2007 Share Posted October 29, 2007 (edited) Description: Hta that produces a Vbs Script called DeleteIt.vbs. This is places in the user SendTo Folder. Uses Wscript.arguments to pass the path of the files or folder to be deleted. This is a perminent delete and does not use the Recyle Bin or System Volume Information. Hta also has a Remove Button to remove the DeleteIt.vbs from the user SendTo Folder.Programming Language: HTML, JS script, Vbs ScriptUsage: I wrote the original script because I wanted a fast way to delete things.Note: There is a limit to how many file or folders can be deleted, 24 items is it limits at one time. This is a SFX file so it acts like a exeEditSince I made this on Vista it works fine, on XP it did not work properly, that been fixed.DeleteThis.exe Edited March 6, 2008 by gunsmokingman Link to comment Share on other sites More sharing options...
mschol Posted December 26, 2007 Share Posted December 26, 2007 because the basic GetFiles() method of VB.net wasn't good enough for me i build my own function in order to do what i neededDescription:the Getfiles() method of VB.net can only handle one fileextension and crashes when it tries to read from system volume information or a Reparsepointi thought of my own solution to that problem: build a function that searches a given directory for files that match a give Regular expression, and skip folders which you enterUsagesearchFileSystem(path As String,searchPattern As String,searchOption As IO.SearchOption) As ArrayListpath = a path (i.e. c:\)searchstring = a regular expression (i.e. .*?\.(avi|ogm|mkv|mpg|mp3|rar|mp4|mpeg|txt)$ for matching files with one of the extensions)SearchOption = wheter to search only the topmost directory or also search in the subdirectory'sinside the function it also has a reference to an array which contains the folders where NOT to search If excluded.BinarySearch(d.Name) < 0 Thenexcluded is in my function a ArraylistLanguageVB.neti included a file thats not directly usable, you have to implement it in your own code.i did include a few lines of code to show how u could use itit might not be the best code availble but since i couldnt find any function that did it this way i build it myself. (one of my very first VB.net things )SearchfileSystem.zip Link to comment Share on other sites More sharing options...
cluberti Posted December 24, 2009 Share Posted December 24, 2009 Description: VBscript to gather some basic computer information, including locale, install date, current time, etc.Programming Language: VBScriptUsage: Use cscript to launch, otherwise you'll get lots of pop-ups from wscript.Output: ------------------------------------------ System Details ------------------------------------------ Computer Name: COMPUTER Operating System Information: ============================= Operating System: Microsoft Windows 7 Ultimate 64-bit Version: 6.1.7600 Ultimate Edition Build Type: Multiprocessor Free Locale: English (United States) Serial Number: XXXXX-XXX-XXXXXXX-XXXXX Current Time Zone: Eastern Standard Time Offset from UTC: -5 hours DST In Effect: False Windows PID Key: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Office 2010 PID Key: XXXXX-XXXXX-XXXXX-XXXXX-XXXXX Install Date: 7/23/2009 4:24:52 PM Last Boot Time: 12/21/2009 4:25:21 PM Local Date/Time: 12/28/2009 6:54:42 PM System Status: OK Hardware Information: ===================== CPU: Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz (x64) Physical Memory: 7.92 GB Video Card: Radeon X1550 Series (Microsoft Corporation - WDDM) Adapter DAC: Internal DAC(400MHz) PNP Device ID: PCI\VEN_1002&DEV_7143&SUBSYS_204E17AF&REV_00\4&2FFCA7E0&0&00E1 Video RAM: 256 MB Driver Version: 8.56.1.15 Driver Date: 4/24/2009 Video Card: Radeon X1550 Series Secondary (Microsoft Corporation - WDDM) PNP Device ID: PCI\VEN_1002&DEV_7163&SUBSYS_204F17AF&REV_00\4&2FFCA7E0&0&01E1 Driver Version: 8.56.1.15 Driver Date: 4/24/2009 Video Card: ATI Radeon HD 2600 Pro (Microsoft Corporation WDDM 1.1) Adapter DAC: Internal DAC(400MHz) PNP Device ID: PCI\VEN_1002&DEV_9589&SUBSYS_E410174B&REV_00\4&324FA3B&0&0008 Video RAM: 256 MB Driver Version: 8.56.1.15 Driver Date: 4/24/2009 Sound Card: High Definition Audio Device Manufacturer: Microsoft PNP Device ID: HDAUDIO\FUNC_01&VEN_11D4&DEV_1884&SUBSYS_103C2819&REV_1001\4&2260D901&0&0001 Sound Card: USB Audio Device Manufacturer: (Generic USB Audio) PNP Device ID: USB\VID_045E&PID_070F&MI_00\6&216596F4&0&0000 Sound Card: High Definition Audio Device Manufacturer: Microsoft PNP Device ID: HDAUDIO\FUNC_01&VEN_1002&DEV_AA01&SUBSYS_00AA0100&REV_1000\5&36D18A18&0&0001 Volume: C: Compressed: False File System: NTFS Volume Size: 465.67 GB Free Space: 368.08 GB Network Adapter: Intel(R) 82566DM-2 Gigabit Network Connection MAC Address: 00:0F:FE:83:0B:63 DHCP Enabled: True IP Address: 192.168.200.100 Subnet Mask: 255.255.255.0 Default Gateway: 192.168.200.1 Lease Obtained: 12/28/2009 4:13:18 PM Lease Exipres: 12/29/2009 4:13:18 PM DHCP Servers: 192.168.200.10 DNS Server: 192.168.200.15,192.168.200.16, WINS Primary Server: 192.168.200.16 WINS Secondary Server: 192.168.200.15 Enable LMHosts Lookup: True System Information: =================== Computer: HP Compaq dc7800 Convertible Minitower Serial Number: 2UA81017DR BIOS Version: 786F1 v01.04 UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXosinfo.vbs.txt Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 8, 2010 Share Posted March 8, 2010 Here are four examples of a HTA that self closes and displays a bar graph of the count downCode Only For Count Down Fixed Sized Bar Graph<TITLE>Demo Close Graph</TITLE><HTA:APPLICATION Id="GsmCloseCntDownFixSized" APPLICATIONNAME="GsmGraphDemo3" SCROLL="no" SINGLEINSTANCE="yes" WINDOWSTATE="minimize" SELECTION="NO" CONTEXTMENU = "NO" BORDER="Thin" BORDERStyle = "Normal" INNERBORDER = "YES" NOWRAP MAXIMIZEBUTTON = "NO" MINIMIZEBUTTON = "NO" SYSMENU = "NO"> <STYLE Type='text/css'> Body { Font-Size:9.75pt; Font-Weight:Bold; Font-Family:Arial,Tahoma,Comic Sans MS,Segoe Ui; Color:#203063; BackGround-Color:Transparent; Filter:progid:DXImageTransform.Microsoft.Gradient (StartColorStr='#ece6e0',endColorStr='#c0bab4'); Margin-Top:5; Margin-Bottom:5; Margin-Left:2; Margin-Right:2; Padding-Top:5; Padding-Bottom:5; Padding-Left:2; Padding-Right:2; Text-Align:Center; Vertical-Align:Top; Border-Top:2px Solid #dbd5d1; Border-Bottom:4px Solid #c6c1ba; Border-Left:2px Solid #c1bdb9; Border-Right:3px Solid #d7d1cb; } .pgbar { filter:progid:DXImageTransform.Microsoft.Gradient (GradientType=0,StartColorStr='#44DC88',endColorStr='#005a00') }</STYLE> <script LANGUAGE='VBScript'> Dim Tx1 :Tx1 = " Seconds Remaining"'-> Controls The Loop Count Dim C1 :C1 = 100 Function Window_OnLoad() self.Focus self.resizeTo 350,125 self.MoveTo screen.availWidth / 2 - 350/2,screen.availHeight / 2 -125/2 bar.style.width = "100%" TextDsp("10") DemoSelf() End Function Function DemoSelf() If C1 = 0 Then window.close() Else Select Case C1 Case 90 :TextDsp("09") Case 80 :TextDsp("08") Case 70 :TextDsp("07") Case 60 :TextDsp("06") Case 50 :TextDsp("05") Case 40 :TextDsp("04") Case 30 :TextDsp("03") Case 20 :TextDsp("02") Case 10 :TextDsp("01") End Select If Not bar.style.width < "100%" Or bar.style.width > "0%" Then BarSize(C1) Else BarSize(C1) End If C1 = C1 - 1 End If idTimer = window.setTimeout("DemoSelf", 100, "VBScript") End Function'-> Resize The Bar Function BarSize(N) If N > 1 Then document.title = FormatPercent(N / 100 ,2) End If bar.style.width = n * 2.50 End Function Function TextDsp(NM) Txt.innerHTML= NM & Tx1 End Function </SCRIPT> <BODY Scroll='No'> <TABLE>Demo Self Close</TABLE> <TABLE Style='Margin:3pt;'> <TD><DIV ID='Txt1' Style='Font-Size:9.25pt;Font-Family:Lucida Console;Font-Weight:Bold;Color:#000047;'> This Will Close When Timer Reaches Zero</DIV></TD> </TABLE> <!-- To Make The Bar Thick Or Thinner Change Font Size The Graph Size Is Fixed And Will Alway Be Based Upon This Is Width:200pt--> <DIV Align='Left' Style="Width:200pt;Border-width:1;Border-style:solid;Border-color:#BBBBBB;Font-size:9.25pt"><!-- Position The Text In The Bar Graph Area --> <SPAN ID="bar" Class=pgbar></SPAN> <SPAN ID="Txt" Style='Position:Absolute;Top:57;Left:88;Font-Family:Lucida Console;Font-Weight:Bold;Color:#003434;'></SPAN> </DIV></BODY>There will be a error in the text display of Demo_CountUpVaribleSizeGraph.htaChange This'-> Text Display In Bar Graph Area Function TextDsp(NM) Txt.innerHTML= NM End FunctionTo This'-> Text Display In Bar Graph Area Function TextDsp(NM) Txt.innerHTML= NM & Tx1 End FunctionDemoHtaCountBarGraph.zip Link to comment Share on other sites More sharing options...
dencorso Posted June 14, 2010 Share Posted June 14, 2010 Description: VBscript to remove duplicate lines from plain text files.Programming Language: VBScriptUsage: YankLines <input_filename> <output_filename>Well, I claim no originality here at all, all I did was performing some pretty basic good housekeeping, and joining pieces of great code written by others...I needed a program to remove duplicate lines from lists which I update by appending, such as the HOSTS file and some log files. These are too long to clean up by hand. I searched and found an awesome VBScript program, by Max Damage (at MS Technet's Script Center), that does it fast and reliably (reference: Remove Duplicate Lines From a Text File)... however it's not quite user friendly, because one has to modify the code each time it's used, because the filename is hardcoded in the script. So I added some quite standard code for it to recieve the source and output filenames from the command-line, to resolve this problem, and incorporated cluberti's clever subroutine RunMeWithCScript() to avoid getting lots of pop-ups from wscript. And that was it. But it works so well that I thought I should share it with all other users needing such a program, because I really didn't find anything like it free and readily available on the net. [Later edit: Thanks to tomasz86, the code has been improved: it turns out that the first posted version was case-sensitive, which, IMO, is undesirable. So, I've updated the script to correct this (just one more line added, including a comment on how to reverse it, when necessary). One page from the MS 2k Scripting Guide (Configuring Dictionary Properties), where the subject is further discussed is the relevant reference for this. Thanks also to jaclaz, for suggesting the alternative yanklinescs.vbs (case sensitive version), now added to the attached .7z. For the source of these improvements, see this thread.]Together with yanklines.vbs, in the attached 7z file, there is also believe.txt, a nice test file I copied from How Can I Remove All Duplicate Lines From a Text File? (by the Scripting Guy), which also presents another interesting way of solving the problem of the duplicate lines (which I didn't actually test because I'd already solved my problem using yanklines.vbs).yanklines_v3.7z 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