VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

What script/powershell command would be used to delete any file in a directory that starts with anything but a number (0-9) or the extension is .tmp. We have a system that only uses numbers and users copy files to the directory accidentally that need to be deleted automatically.
OWASP: Forgery and Phishing
LVL 13
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Hello experts,

The VB Script reported bellow allows me to append multiple files into a single file:

I would like to simplify  and take into account the following requirement:
1-Instead of move csv files into Archive folder, I would like to move to YYYYMMDD_HHMMSS Archive sub folder
2-Add in last available columns of appended csv name and creation date of each file involved by the append process
3-Generate appended file into a Result folder and log file into Log folder instead of InputFolder
4-Generate appended file with YYYYMMDD_HHMMSS date stamp instead of YYYYMMDD to avoid error message when execution is performed the same day

If you have questions, please contact me.

Thank you for your help.

'Create the file system object for creating folders:
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Text file I/O constants
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const TristateTrue = -1
Const TristateFalse = 0
Const TristateUseDefault = -2

' Define folders and files to work with

strScriptName = Replace(WScript.ScriptName, ".vbs", "", 1, -1, vbTextCompare)
strScriptDir = Replace(WScript.ScriptFullName, WScript.ScriptName, "")
cInputFolder = strScriptDir & "\Input"
cArchiveFolder = strScriptDir & "\Archive"
cMergedFile = strScriptDir  & "\Input\[[STAMP]]_Reported_Name.csv"
cHeaderFile = strScriptDir & "Header.csv"
cLogFile = strScriptDir  & "\Input\[[STAMP]]_[[SCRIPTNAME]].log"
cHeaderLines =1
cDelim = ";"

' Get date 

Open in new window

I am attempting to hack together a VBScript that will:

- get last logged on user
- copy a .lnk file to the logged on user's dektop.

I've got the last logged on user but I'm having trouble with the simple file copy.

 Dim filesys, FSO, WSHShell, Regkey, Username, strFile, UserPath, objShell

Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\"
Username = WSHShell.RegRead(RegKey & "LastLoggedOnSAMUser")
Username = Mid(Username,7) 

Set FSO = CreateObject("Scripting.FileSystemObject")
DesktopPath = "C:\Users\" & Username & "Desktop"

Set objShell = WScript.CreateObject("WScript.Shell")
currentFolder = objShell.CurrentDirectory
Set filesys = CreateObject("Scripting.FileSystemObject")
filesys.CopyFile currentFolder & "\IRM Training Landing Page.lnk", strDesktop, true 'boolOverwrite

Open in new window


The business i work in is using netlogon vbs scripts for each user to map drives upon login. An opportunity has presented itself where this can now be changed to group policy. I was wondering if there are best practices for deploying mapped drives through group policy? In the logon scripts i have seen that there is no consistency for drive letters for each mapped share between users and the shares which are mapped are different for each user.

Any suggestions?


Hi Experts,

I've been working on this powershell script and need some help with a couple of things.  The script will be called from this vbscript to pass the computername or listofcomputers variables.

What I'd like expertise or help with is:

1. I've tested calling this from the VBScript Code in top comments section, but didn't get the computername variable to pass down.  (this would be done from the vbscript above, but wanted just a test wrapper to test).  EDIT:  If this is too difficult, I'd like to set it up to pull from a list of computers.

2. I'm first running "Test-MyConnection" (if) the computer is online, I'm then calling a executable.exe.  This is the part I'm having issues with - I don't necessarily want to run a .exe here, but call an SCCM advert (pasted below from client center), or, I also have a vbscript that runs the advert I could call out to.  This advert would exist locally on every computer.  The part I'm unsure about, or how to code is having this advert run on each computer in the list of variables

SCCM Advert Code:
 get-wmiobject -query "SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE ScheduledMessageID='SCCM00001-SCCM00002-5D2960FE'" -namespace "ROOT\ccm\policy\machine\actualconfig"

Open in new window

Dear all Experts!
I would like to thank you all for assisting me to almost finish my task as assigned by management, and many special thanks to Mr Jim for providing the VBA code below for send & receiving data from & to RS232 com gadget
The last bit though not much is another assistance required to receive the data from RS 232 which is coming in Json format, I’m fully aware he also provided a form on the scale part, but this appear to be slightly different:
Functional VBA Code:
Option Compare Database
Option Explicit

' modCOMM - Written by: David M. Hitchner
' This VB module is a collection of routines to perform serial port I/O without
' using the Microsoft Comm Control component.  This module uses the Windows API
' to perform the overlapped I/O operations necessary for serial communications.
' The routine can handle up to 4 serial ports which are identified with a
' Port ID.
' All routines (with the exception of CommRead and CommWrite) return an error
' code or 0 if no error occurs.  The routine CommGetError can be used to get
' the complete error message.

' Public Constants

' Output Control Lines (CommSetLine)
Public Const LINE_BREAK = 1

Open in new window

Excel Search Cells by Format [Fill Color] follows no discernible directional pattern: across column, across column, down columns, down columns, across columns.

Attached is an example sheet.  If I run the Format Fill search for yellow fill, I get this series of results:
Z5, AH11, X25, X26, AX26, AX28, K34, O37, X60, AZ61, V62, BO36

I need the search to go down each column so that the cells would appear in this order:
K34, O37, V62, X25, X26, X60, Z5, AH11, AX26, AX28, AZ61, BO36

Have group of extracted quotes arranged thematically in columns.  Have highlighted some that I that I want to quickly review.  Need to be able to focus to each highlighted cell down the columns and then move over to the next column with a highlighted cell at the lowest number / nearest-to-the-top cell.  Continue down.  Move to the top of the next column with a highlighted cell.  

So, left to right, down, over and up columns, according to cells with the fill color in question.

Any way to do that?

Many thanks,

Hello, I have a line of VBScript that I performing weird on us.
Set obj = Browser("Haworth Lynx Order_1").Page("Haworth Lynx Pre-Order_2").WebTable("2660908").ChildItem(2,2,"Link",0)

Open in new window

I was wondering if I can do the same thing, by using the following:
GetValuesFromRow=Browser("Haworth Lynx Order_1").Page("Haworth Lynx Pre-Order_3").WebTable("2014485").GetROProperty("column names")
strParts = Split(GetValuesFromRow, ";")

Open in new window

The array that is returned is a dynamic array.  Is there a way to Set an item in an array so it can be clicked on?
In my example, I would like to click on array item 2, whick is a link in a WebTable.  Is this possible?   Please advise and thanks.
I have a list of usernames/passwords that were the initial passwords given, but should have been changed. I've been told that some of the users used the same password and we want to make sure the password has been changed. We now have a password policy in place for the group, but how can I check if the password has changed? Please note that users did enter a new password, but because a password policy was not in place at the time, some entered the original password as the new password.

I have a file in the following format of username,password:

How can I test the credentials in this file against AD to see what users entered the same password?  I was thinking I would probably use either PowerShell, VBScript, C# or VB.net.
long time I created a project in VB 6. everything was great with the different operating system, it was XP, then Windows 7 and now I have Windows 10

for windows 7 the connection string was:

adoconn.Open="Provider=Microsoft.ACE.OLEDB.12.0;data source="App.PATH & "\MYDB.accdb"

now we have Windows 10 and some controls stop working, like calendar... looks like the problem is now we have 64 bit vs 32 bit system. Is anything possible to modify/change to make it work?
Bootstrap 4: Exploring New Features
LVL 13
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

When I execute the following VBScript with existing URL.  Send command returns 200 OK.

set oHttp=CreateObject("MSXML2.XMLHTTP")
oHttp.Open "GET","https://www.google.co.jp",False

If oHttp.Status <> 200 Then
   MsgBox "Status is" & oHttp.Status
   MsgBox oHttp.Status
End If

However, When I execute the following VBScript with URL which does not exist, it does not return status code. It crushes at oHttp.Send.
How to get status code when Open GET fails?  

set oHttp=CreateObject("MSXML2.XMLHTTP")
oHttp.Open "GET","https://www.doesnotexistURL.co.jp",False

If oHttp.Status <> 200 Then
   MsgBox "Status is" & oHttp.Status
   MsgBox oHttp.Status
End If

The attachments are VB scripts. Please change the extension as vbs.

It's appreciate if I can get any advises.
I asked this but did not see it in my "Questions" so I am thinking I may not have submitted it?

I have a dynamic string produced from a .GetROProperty("AllItems")  One time it could return "var1;var2;var3;var4;var5;"  next time"  "var1;var2;var3;var4;var5;var6;var7;var8;"  and another time "var1;var2;"  each time different depending on other conditions.  Each var is separated by a semi-colon ;

Is there a way to make every var it's own variable?  Like as follows:
Value1 = var1
Value2 = var2
Value3 = var3  etc.

I will need to use each var, later in another procedure that need to loop through each var that was returned.

Please advise and thanks.
Hello experts,

I have:
-SourceFolder and DestinationFolder
I would like to copy files located in SourceFolder which don't exist in DestinationFolder.
What is the most straightforward approach to do this?
Windows batch through robocopy & Powershell or VBS ?

Thank you for your help.

I need your help to put together Powershell script to

Script 1 - BAK extension file Audit

1. Script needs to be able to use input server file (server bulk)
2. Scan servers drives (E:\, F:\, G:\ or I:\) or be able to select drives
3. Look for  “*.bak” extension files.
4. Generate CSV output files with
       a. server name
       b. Bak file name and path
       c. File Size
       d. Dates temp of the file.
       3. hash
5. Email report to specific email address

I have a Audit script but it doesn't work correctly. It scans all drives, doesn't provide date of BAK file creation. It doesn't sent email with report

$ExtensionList = @('.bak')
Get-PSDrive -PSProvider FileSystem |
    ForEach-Object  {
        Get-ChildItem -Path $_.Root -Recurse -ErrorAction SilentlyContinue |
            Where-Object { $ExtensionList -eq $_.Extension } |
            ## ForEach-Object { $_.Name, $_.FullName, $_.GetHashCode() }
            Select-Object @{Name="Name";Expression={$_.Name}}, @{Name="Hash";Expression={$_.GetHashCode()}}, @{Name="FullName";Expression={$_.FullName}} |
            Export-Csv -Path C:\Temp\BAKAudit\BAKAuditReport.csv -NoTypeInformation -Append

I don't have BAK deletion script, which should do as follows

Script 2 - BAK Deletion
1. Use generated output file (from script 1) and remove"Bak" file older then 3 days.
2. Once the deletion is completed another report should be created showing what bak files from which server and from …
I need to add a fourth key to this simple sorting macro but it bugs when I add a fourth key. Is there a way around that?

Sub SortSelection()
Selection.Sort key1:=[A3], Order1:=xlAscending, _
               key2:=[B3], Order2:=xlAscending, _
               key3:=[C3], Order3:=xlAscending ', _
               'key4:=[L3], Order4:=xlAscending
End Sub

Open in new window

Hello experts,

I have the following ahk file attached.
I am looking for a procedure that covers the following needs:
-Read ahk file
-Generate an Output-(file-name-of-ahk-file)_yyyymmdd_hhmmss.csv file with headers: Item; Hotkeys and the following
     -Based on information read of ahk file, report the second text line after the following line: ";===================================
      Instructions & Variables information should not be reported in the csv file
     -Based on information read of ahk file, report the right after line which finish & or contains with ::
I attached dummy-file and output-file as I expect that the procedure generate csv file.

Windows Batch & Powershell & VB Script approaches are more than welcome.
If you have questions, please contact me.

Thank you for your help.
I am trying to create an xml file via vbscript.  I can create the file but it inserts xmlns="" on each child element and it is all on one line when you open it with notepad.

I would like the output to look like the attached picture

 Here is my code:

scriptDir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
Set objRoot = xmlDoc.createElement("CloudEditSettings")
Set xmlns = xmlDoc.createAttribute("xmlns")
xmlns.text = "http://springcm.net/schemas/cloudedit/config/v1"
Set xmlnsxsd = xmldoc.createAttribute("xmlns:xsd")
xmlnsxsd.text = "http://www.w3.org/2001/XMLSchema"
Set xmlnsxsi = xmldoc.createAttribute("xmlns:xsi")
xmlnsxsi.text = "http://www.w3.org/2001/XMLSchema-instance"

objroot.setAttributeNode xmlnsxsi
objroot.setAttributeNode xmlnsxsd
objRoot.setAttributeNode xmlns
xmlDoc.AppendChild objRoot

Set objAuto = xmlDoc.createElement("AutomaticUpdates")
objAuto.text = "true"
objRoot.appendchild objAuto

Set objDiag = xmlDoc.CreateElement("IsDiagnosticLoggingEnabled")
objDiag.text = "false"
objRoot.appendchild objDiag

Set objEmail = xmlDoc.CreateElement("Email")
objEmail.text = "emailaddress.com"
objRoot.appendchild objEmail

Set objAccountID = xmlDoc.CreateElement("AccountID")
objAccountID.text = "11111"
objRoot.appendchild objAccountID

Set objUseSpringCM = xmlDoc.CreateElement("UseSpringCM")
objUseSpringCM.text = "false"
objRoot.appendchild objUseSpringCM


Open in new window

I don't know why there is "Type mismatch" error when I run 1st Macro (pressing Alt-F8), vs attached Excel file.
Hello experts,
I am looking for a script to replace single space or multiple spaces at files and folders located in a root folder by "-" characters
The idea is to have as variables:
      The character that is going to replace single or multiple spaces
      Drill down mode flag
Powershell & VB Script & Windows Batch approaches are more than welcome.
Thank you for your help.
OWASP: Avoiding Hacker Tricks
LVL 13
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

In the attached Excel file, I am trying to get it for the drop downs on the left of the pipe circles, we have RCP and SR26  which reference the tables on the second sheet named Pipe Materials. The issue is that they are only referencing the one column in each table called Pipe Size. I am trying to find how by choosing table and row (RCP or SDR) to have the row information, which is the Thickness and Feet show up in output.

For example if the user choses RCP 15, the output would show Pipe Thickness which is 0.190 and the Pipe Size which is 1.250 in that corresponding row. LOOKUP seems to only do one column.

Any help would be appreciated.
See attached spreadsheet. It is MAC ExcelSample-Equipment-Hunt.xlsx

In the Jobs ws in Column A are a list of jobs. In the List ws is a named range called EQUIP.

In Job ws, column B, is a formula that checks each cell against EQUIP and returns the number of occurrences from the list that are in the cell.

Job ws, column C shows the results I want; Display the actual text (could be more than one) that is in the cell and matches EQUIP.

Solution can be a MAC-compatible Excel formula or a VB macro.

Thanks for your help!
I am looking for a solution to search and replace environment variables, either to run locally on each machine, or remotely to achieve the following:-

Each machine may have a number of the following entries in either the system, or user environment variables :
xxx_LM_LICENSE_FILE: 1660@server1
yyy_LICENSE_FILE: 2101@server1
zzz_LICENSE_FILE: C:\LIC\LICENSE.TXT;2100@server1;1655@server1

I need to replace "server1" to licsvr.domain.com, and the xxx, yyy, zzz could be any text
Each machine may have none, some, or all of the above examples
Also as shown there could be multiple entries per line that would need replacing

Therefore the resulting output would be
xxx_LM_LICENSE_FILE: 1660@licsvr.domain.com
yyy_LICENSE_FILE: 2100@licsvr.domain.com
zzz_LICENSE_FILE: C:\LIC\LICENSE.TXT;2100@licsvr.domain.com;1655@licsvr.domain.com

Can someone offer some scripts that might be suitable
Thanks in advance
I save a class with various properties into a the current user session like this :
    Public ReadOnly Property UserSession As cUserSession
            If HttpContext.Current.Session("UserSession") Is Nothing Then
                HttpContext.Current.Session.Add("UserSession", New cUserSession)
            End If
            Return DirectCast(HttpContext.Current.Session("UserSession"), cUserSession)
        End Get
    End Property

Open in new window

I would like to save details in the class to a database before the session is lost.  If I rely upon Session_End in global.aspx, the object is already lost when I go to save it.  I tried to implement idisposable in the cUserSession but this didn't fire.  Whilst I can see how I can manually save the contents of the session by user action or property change, I would like to only do that when the session is about to be lost.

Is this achievable?

Thank you,
I have an older Access database (probably created in 2003) that I am opening in newer versions (tried 2010 and 2016). It is a rather complex database. Everything works except one button that calls a vbscript to update data using delete, update, and insert into statements. I cannot say for certain that it worked perfectly in previous versions as I inherited this from a former employee.

The vbscript concatenates data based on information it receives from the queries. The problem I am encountering is that after I click the button, the query inserts special characters instead of the text that it is supposed to grab from one of the other tables.

The fields that are showing correctly in the source table are Long Text data types with Plain Text text format.

I attached a screenshot of a brief sample of the problem I am experiencing.

Special Characters
can we use advanced threat protection ( ATP)  from azure AD in order to stop macro and vbs related attacks . through my search i found ATP can be used safe attachments purpose through email.

we have users using on premise active  directory and mailboxes in office 3 65., we dont have on premise exchange server

VB Script





VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.