Getting the Username from the HKEY_USERS values

If you look at either of the following keys: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist You can find a list of the SIDs there with various values, including where their “home paths” which includes their usernames. I’m not sure how dependable this is and I wouldn’t recommend messing about with this unless you’re really sure what you’re doing.

How do I include a common file in VBScript (similar to C #include)?

You can create a (relatively) small function in each file that you want to include other files into, as follows: sub includeFile (fSpec) dim fileSys, file, fileData set fileSys = createObject (“Scripting.FileSystemObject”) set file = fileSys.openTextFile (fSpec) fileData = file.readAll () file.close executeGlobal fileData set file = nothing set fileSys = nothing end sub and … Read more

Add item to array in VBScript

Arrays are not very dynamic in VBScript. You’ll have to use the ReDim Preserve statement to grow the existing array so it can accommodate an extra item: ReDim Preserve yourArray(UBound(yourArray) + 1) yourArray(UBound(yourArray)) = “Watermelons”

Does VBScript have a substring() function?

Yes, Mid. Dim sub_str sub_str = Mid(source_str, 10, 5) The first parameter is the source string, the second is the start index, and the third is the length. @bobobobo: Note that VBScript strings are 1-based, not 0-based. Passing 0 as an argument to Mid results in “invalid procedure call or argument Mid”.

Creating and writing lines to a file

Set objFSO=CreateObject(“Scripting.FileSystemObject”) ‘ How to write file outFile=”c:\test\autorun.inf” Set objFile = objFSO.CreateTextFile(outFile,True) objFile.Write “test string” & vbCrLf objFile.Close ‘How to read a file strFile = “c:\test\file” Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine= objFile.ReadLine Wscript.Echo strLine Loop objFile.Close ‘to get file path without drive letter, assuming drive letters are c:, d:, etc strFile=”c:\test\file” s … Read more

Getting current directory in VBScript

You can use WScript.ScriptFullName which will return the full path of the executing script. You can then use string manipulation (jscript example) : scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) Or get help from FileSystemObject, (vbscript example) : scriptdir = CreateObject(“Scripting.FileSystemObject”).GetParentFolderName(WScript.ScriptFullName)

Get the type of a variable in VBScript

Is VarType what you need? Returns a value indicating the subtype of a variable. +————–+——-+———————————————+ | Constant | Value | Description | +————–+——-+———————————————+ | vbEmpty | 0 | Empty (uninitialized) | | vbNull | 1 | Null (no valid data) | | vbInteger | 2 | Integer | | vbLong | 3 | Long integer … Read more