VB Script

37K

Solutions

20K

Contributors

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

I would like to use HttpWebRequest and HttpWebResponse with ASP.NET VB.

This gives me an error:
<%

Imports System.Net

Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse

%>

Open in new window

How can I properly import System.Net?
0
Keep up with what's happening at Experts Exchange!
LVL 12
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I have the following robocopy script of which is 90 % there but just need it to delete the subfolders from "C:\CHILTERNDOWNLOADS" when the files have transferred.

Any Ideas on the command?

Thanks
Robocopy "C:\CHILTERNDOWNLOADS" "S:\CCTV Downloads\Chiltern Downloads" /S /MOV /R:10 /W:5 /V /ETA

Open in new window

0
Hi guys

I'm completely new to VLOOKUP tables and have been working on some tutorials. I have an Excel sheet that I have attached so that you can see what I am trying to do.

So basically, in worksheet 'User Details' I would like the column 'Organisation' (column C) to be filled in with the data in worksheet 'Mailbox Details' called 'Organisation A (also column )'. If you look at cell C8 in 'User Details', you will see 'contoso.com' which I have manually put in there.

Here's how I am trying to do it:

In the 'User Details' worksheet, the column A6 is the value I am looking up. As an example, my Lookup_value will be 'A8'.
The Table_array will be worksheet 'Mailbox Details' columns 'C5:D29'.
Col_index_num = 1 as that's the column I am trying to extract data from.
Range_Lookup = false

The issue I am seeing though is that in 'Mailbox Details' worksheet, in Column C there is a formula that has been dragged down and perhaps this is causing the issue?

If you're able to help me figure this out, that would be grand.

Thanks for helping
Yashy
ActiveDevicesUsageTracker-07-06-201.xlsx
0
Visual Studio Asp.net web using vb.  
I am trying to open a directory from my application.  It works perfect when  in debug mode but does not work when I publish to our intranet.  

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Process.Start("explorer.exe", "c:\")


Any help would be appreciated.  The application is published on a 2008 r2 server running IIS
0
I am using SCCM to deploy an application.  The app is old school and I have to copy a license folder to the profile of the currently logged on user.  I posted a similar question and instead of help with VBScript I only had suggestions to do it another way so...

No - I can't use AD policy.
No - I can't copy a single use license to every user profile.
No - I don't want to use a batch file because I don't know how to grab the currently logged on user with a batch file.

For the script - so far I can grab the logged on user.  I've also used FSO.CopyFolder before.  What I'm having trouble figuring out how to do is tack the contents of the Username variable (see below) to the end of C:\Users.


 Here is what I have so far....

Option Explicit
Dim FSO, 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)
strFolder = "C:\Users"
 Set FSO = CreateObject("Scripting.FileSystemObject")
 Dim UserPath : UserPath =  ????  <----- How do I make this happen - tack the contents of Username to the end of C:\Users and make UserPath = C:\Users\Username?
 Dim DataFolder : DataFolder = UserPath & "\AppData\Local\FolderA"
 
 FSO.CopyFolder "\\Server\SCCMResources\Applications\FolderA", UserPath & "\AppData\Local\FolderA",1


I'm really not experienced with VBScript but familiar …
0
I need to find a keyword in a word document title/name so that I can perform an if statement on the result

I have tried the following with a document that had the word "New" in it and this executed in the document open function:

    If ActiveDocument.Name = "New" Then
        MsgBox "New Found"
    Else
        MsgBox "New Not Found"
    End If

As you can guess...it didn't work out and that's why I am here!  :)
0
Problem:

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.

Solution:

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:

[HKEY_CURRENT_USER\Software\{08439167-4CA5-48E9-A810-A3A7C0B80B06}]

[HKEY_CURRENT_USER\Software\{08439167-4CA5-48E9-A810-A3A7C0B80B06}\Local]

[HKEY_CURRENT_USER\Software\{08439167-4CA5-48E9-A810-A3A7C0B80B06}\Local\CNS5T2Q540AHCQ6QU75GXH6DS1MCCCXFYF60W-102-292-280-A1]
"SiteMessage"="MyBusiness"
0
Hi Experts,
I am looking for a script that will read all files of a specific folder (.txt,.csv) and count how many records they're in total.
all files have fields header, however some files only contains the header and should not be count.
Thanks in advance.
0
I would like a script or program where I could specify a server and a top level share and the script will walk the entire structure including all sub directories and will generate a report as a.csv file with the information and format shown in the attached screen shot. I only want explicit permissions shown, not inherited permissions.
This doesn't have to be PowerShell. It could be .vbs or other language. I just need to get the output in the format I'm looking for.
0
Hello Experts, I am hoping you can help with my dilemma. I have a directory with about 10k + Word files and I have to go through them all and find two strings and replace them. I tried writing a VbScript , but I am stuck with it. I am wondering if anyone can help me. here is the code I have so far, but when I for loop into the directory I get an error. I can get the first string to work, but not the second one

Option Explicit

Dim fso, objWord, objDoc, objShape, strFindText, strReplaceText, strFindText2, strReplaceText2, sPfolder, sFolder, x, colFiles,myStoryRange

Const wdReplaceAll = 2
Const msoTextBox = 17




Set fso = CreateObject("Scripting.FileSystemObject")
sPfolder = "C:\Scripts"

Set sFolder = fso.GetFolder(sPfolder)
Set colFiles = sFolder.Files

strFindText = "None"
strReplaceText = "Internal Use"

strFindText2 = "COPYRIGHT (c) 2017 "
strReplaceText2 = "COPYRIGHT (c) 2018 "

For each x in colFiles
	
	Set objWord = CreateObject("Word.Application")
	objWord.Visible = false

	Set objDoc = objWord.Documents.Open("C:\Scripts\test.docx")
	
	For Each objShape In objDoc.Shapes

		If objShape.Type = msoTextBox Then
			objShape.TextFrame.TextRange.Find.Execute _
			strFindText, , , , , , , , , _
			strReplaceText, wdReplaceAll
			
		End If
	        If objShape.Type = msoTextBox Then
			objShape.TextFrame.TextRange.Find.Execute _
			strFindText2 , , , , , , , , , _
			strReplaceText2, wdReplaceAll
			
		End If	
	Next
Next

Open in new window

Any help would be most appreciated.
0
Cloud Class® Course: Ruby Fundamentals
LVL 12
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Hi guys,

I'm new to macros and I'm enhancing this report of mine for efficiency. I was able to create the 1st two modules (for formatting and some computations). This is for the 3rd module and for the final step.

The scenario goes like this:
1. I have a source file (Working file.xlsx). This would be the result from the formatting by the 1st two macros that I have.
2. Column I will be the basis of the number of new workbooks that will saved. So, column I will be filtered and whatever is in it will be saved as a new workbook.
3. The filename is custom for every filtered value. Let's say the values in column I are A, B, and C, the filenames are Apple.xlsx, Banana.xlsx, Cherry.xlsx. (wondering if I could use a lookup table for this one)
4. I'm using Excel 2016, 64-bit.

Hope you could help me with this one. Thanks in advance!
0
Hello Experts,

DocumentBeforeSave, DocumentBeforeClose, DocumentChange functionality not working in .docx, but works in .dotm.

How does one make it work?  Help!

The attached file will need its extension changed from .zip to .dotm...
ECT.zip
0
I have the following script that is supposed to delete .exe  subfolders  after a certain number of days based on date created.

I click on it and it appears to run but not deleting  subfolders.

The reason that they are .exe folders is that they are 7zip files.

I reckon that the reason could be that it trying to delete the original folder of which I dont want it to do but just delete the subfolders that are over a XX no of days after date created.

Any Ideas?
OPTION EXPLICIT
DIM strExtensionsToDelete,strFolder
DIM objFSO, MaxAge, IncludeSubFolders

' ************************************************************
' Setup
' ************************************************************

' Folder to delete files
strFolder = "S:\CCTV Downloads\Chiltern Downloads"
' Delete files from sub-folders?
includeSubfolders = true
' A comma separated list of file extensions
' Files with extensions provided in the list below will be deleted
strExtensionsToDelete = "exe"
' Max File Age (in Days).  Files older than this will be deleted.
maxAge = 01

' ************************************************************

set objFSO = createobject("Scripting.FileSystemObject")

DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders



sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders)
	DIM objFolder, objSubFolder, objFile
	DIM strExt

	set objFolder = objFSO.GetFolder(strDirectory)
	for each objFile in objFolder.Files
		for each 

Open in new window

0
I had this question after viewing Scripting to scan text file for criteria and return results.

Need to add Q-FAIL to what this script to checking for when it scans the text file. So it will check for JUMPBY or Q-FAIL matched with either COM or BTR - any combination of those.
0
I am having trouble with VB syntax for redirect url parameter.
I need the value to be EquipmentDataReservationAddAlert.asp?CustomerTableID=1000

My code:
TM_editRedirectUrl = "EquipmentDataReservationAddAlert.asp?CustomerTableID=''<%Request.Form(''CustomerTableID'')%>"

Result error:
Microsoft VBScript compilation error '800a0409'
Unterminated string constant
/WebApps2.0/EquipmentDataReservationAddRequest.asp, line 62
TM_editRedirectUrl = "EquipmentDataReservationAddAlert.asp?CustomerTableID=''<%Request.Form(''CustomerTableID'')
0
I have the following script but im trying to get it to look in 2 seperate locations for the base directory.

What I have so far is below but when looking in the base directory I need it to look in C:\DOWNLOADS and if nothing in there look in C:\users\public\SmartPss\Record\Download too and then carry on .

Any ideas?

@echo off
setlocal EnableDelayedExpansion

rem Define folder paths
set BaseDir=C:\DOWNLOADS
set DestDir1=C:\CCTVDOWNLOADS1
set DestDir2=C:\CCTVDOWNLOADS2
set DestDir3=C:\CCTVDOWNLOADS3

rem Quit if no files in download area to process
set Empty=Y
for %%A in ("%BaseDir%\*.*") do set Empty=N
if "%Empty%" EQU "Y" (
    echo No new files to process, quitting.
    exit /b
)

rem Prompt for reference number
set RefNum=
set /P "RefNum=Enter reference number (blank to exit):"

rem If none entered, exit script
if "%RefNum%" EQU "" exit /b

rem Make a subfolder for the reference number
md "%BaseDir%\%RefNum%"

rem Move all files to new subfolder
move "%BaseDir%\*.*" "%BaseDir%\%RefNum%"

rem Ask if BTP download to determine where to move the new folder
choice /C YN /M "Is this a BTP download (Y/N)?"

if NOT ERRORLEVEL 2 (
  move "%BaseDir%\%RefNum%" "%DestDir1%"

) else (
  choice /C YN /M "IS THIS A JAMES DOWNLOAD(Y/N)?"
  if NOT ERRORLEVEL 2 (
    move "%BaseDir%\%RefNum%" "%DestDir2%"

  ) else (
    choice /C YN /M "IS THIS A BURN TO DISK DOWNLOAD? (Y/N)?"
    if NOT ERRORLEVEL 2 (
      move "%BaseDir%\%RefNum%" "%DestDir3%"

) ) )
echo msgbox "DO NOT 

Open in new window

0
I have the following .VBS of which works if I click on it where its based but if I try to run as as a scheduled task its not having it.

Any Ideas.

Thanks

Dim objFileSys

Set objFileSys = CreateObject("Scripting.FileSystemObject")
objFileSys.GetFolder("S:\CCTV Downloads").Copy "S:\CCTV Downloads\Safety  Dept"
Set objFileSys = Nothing

Open in new window

0
hi there,

I'd like to create a VB function that automatically generates working days and days off for different shifts, but unsure of how to start.
A regular shift is 5x2 (5 days on, 2 days off). There are some shifts that are 4x3 (4 days on, 4 days off), 7x7 (7 days on, 7 days off), 14x7, 21x7, etc. The shift could start any day of the week.
For the 5x2, I used the Weekday function. But not sure about the other shifts. How do I write a function that looks into the date, and then determines if it's a working day or day off for that specific shift?

If someone can point me in the right direction, it would be much appreciated.
Thank you in advance!
0
I need to make a vbscript utility code to enumerate subobjects in a JSON.
I load the JSON as follows:
        
Set so = CreateObject("MSScriptControl.ScriptControl.1")
so.Language = "JScript"
so.AddCode( "var json = " + json_text + ";" )

Open in new window

And then accessing the objects as follows:
set subobject_ref = so.Eval("json['subobject_name']")

Open in new window

What if 'subobject_name' is unknown? How can I enumerate all child properties of the root object or a given subobject?

set json_ref = so.Eval("json")

Open in new window

actually creates an object with subobjects/properties, but "for each" can't work with it.
0
Get expert help—faster!
LVL 12
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Greeting Experts

I have PowerShell script used to reboot a list of computers with a delay of 60 seconds between each one. The script in its current state works w/o any problem but looking to add some error checking to confirm the pc did or did not reboot (i.e., completed successfully or failed)... I not for sure how to incorporate changes into the current script... Can somebody take a look and see if possible.....

Current Script:
#>
cls
write-host "Starting the Rebooting Process"
write-host "" 
write-host "" 
get-content "C:\work.txt" | % {
 write-host "Restarting $_" 
 restart-computer -ComputerName $_ -Force
$origtime=60 #match this time with $secs below to provide accurate percent complete 
for ($secs=600;$secs -gt 1; $secs--) {
 Write-Progress -id 1 -Activity "Pausing for 60 seconds between rebooting systems..." -SecondsRemaining $secs -Status "Please wait." -PercentComplete (($secs / $origtime) * 100)
 Start-Sleep 1
 } #close delay
 } #close get-content
 write-host "*** All Reboot commands have been issued ***"

Open in new window

2
I have legacy VB 6 application
I have a laptop running windows 10 32 bit operating system and my Visual Basic 6 application running on it
I deliberately installed the 32 bit version  of windows 10 because some of my development software require this environment

While attempting to build my installer i got the error that MERGEMOD COM SERVER is not installed (See attached)
I have downloaded the Windows SDK  Kit for windows 10 and installed it

When i tried to register the dll i got the error attached

What do i need to do to register mergemod.dll in my environment

Oluwole
MERGEMOD-COM-SERVER-on-WINDOWS-10.PNG
regsvr32-error-27-06-2018.PNG
0
Recently received assistance with VBScript to merge XML documents from a folder into a single, new XML document.

The critical element in that discussion was that I needed to add an element to each node in the new XML document which contains the name of the file that the original node was found in.  Now I have found that occasionally, the original XML file might contain more than one node (order).  But I've found that in these instances, although all of the nodes from the original file are present in the new XML file, only one of them contains the new "FileName" element.

My modifications to Bill Prew's code look like:

Public Sub MergeOrders()
	Dim oFileSys
	Dim oFolder
	Dim aFiles
	Dim file
	Dim xmlPath1
	Dim xmlPath2
	Dim xmldoc1: Set xmldoc1 = CreateObject("MSXML2.DomDocument")
	Dim xmldoc2: Set xmldoc2 = CreateObject("MSXML2.DomDocument")
	Dim Orders
	Dim Order
	Dim NodeToRemove
	Dim strZeroLenFiles
	Dim NodeFileName
	Dim node
	Dim D2 
	
	Set NodeToRemove = xmldoc1.selectNodes("/OperatorName/FileName")
	
	Set oFileSys = WScript.CreateObject("Scripting.FileSystemObject")
	Set oFolder = oFileSys.GetFolder(ftpLocalDir)
	Set aFiles = oFolder.Files
	strZeroLenFiles = ""
	
	For Each file In aFiles

		If file.size = 0 then
		
			if strzerolenfiles <> "" then strZeroLenFiles = strZeroLenFiles & vbCrLf
			strZeroLenFiles = strZeroLenFiles & File.Name
			
		Else 
	
			If

Open in new window

0
Hi

After lots of reading online it seems as though there is no easy way to take contacts either from the GAL or a shared mailbox or a public folder or anywhere really and have them sync up with a user's local contacts. The reason for wanting this is active sync on mobile phones, keeping everyone's contacts up to date with the organization as people come and go / switch numbers.

The best thing I have found so far and tested on my machine was here:

https://www.experts-exchange.com/questions/28355578/Script-Outlook-to-Update-GAL-Contacts.html#a39833716

The problem I see with this is not everyone in our organization is on a PC daily and some of our techs never. Ideally a more advanced version of this, if possible where one script goes out and does this to each user's local contacts all at once would be perfect. I unfortunately do not have the scripting skills.

Any help would be greatly appreciated. Is this possible? Other suggestions on how to accomplish what I am looking for?

Thanks!
0
Good morning experts : )
I have the wonderful task of updating to the current era a database started at the beginning of Lotus123, and I am just hoping for some confirmation/advise on the path I think it should go. I have dabbled with Access for many years, but by no means would I call myself an expert. I can put together basic linked tables and easily build queries and reports, but have only dipped little toe into VB and macro side of this tool.

This is a manufacturing database with history back to the 60's that has been poked and prodded for many years but never cleaned up properly. Currently it is giving the old "Property value is too large" error when you try to make any changes. After many google searches I have determined it is due to the width of the main table (200+ columns). For IP reasons I don't want to give away too much direct information or post any copies of database so hoping the below brief gives enough info. Lets say we are manufacturing a widget that is run by an electric motor and can have various attachments/configurations and technical info.

The main "index" table contains all manufacturing data on our widgets that I believe now needs to be broken down to individual multiple tables. As mentioned there are 200+ columns with individual row data indexed by a serial number of manufactured item. The columns could be broken into 3 - 4 groups, for example there is customer info including order numbers, there is motor info min max RPM's, kWs etc , widget …
0
Trying to get a complete list of installed programs.
Using this command gives me partial list: wmic /output:"C:\software.csv" product get "Description","InstallDate","Name","Vendor","Version"
Using this gives another partial list: reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Uninstall /s | find "DisplayName" > C:\InstallList.txt

Also "reg query" won't seem to get all the values desired as in the "wmic" command.
0

VB Script

37K

Solutions

20K

Contributors

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.