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 am going to be detailed as possible.  I am looking for a CSV that can list the file contents of a directory of my choosing (with the ability to specify how many sub-directories to also parse)

Let's Pretend I have the following

Example1
C:\FolderA\FolderAA\filea1.txt
C:\FolderA\FolderAA\filea2.pdf

Example2
C:\FolderB\FolderBB\fileb1.txt
C:\FolderB\FolderBB\fileb2.pdf


I would need a CSV that has the following:

EXAMPLE 1
Row 1 Column A would only list the relative directory name for the file. In this example it would be FolderAA
Row 1 Column B would be the full target path without the filename.  In this example that would be C:\FolderA\FolderAA
Row 1 Column C would be the file name without extension. In this example it would be filea1
Row 1 Column D would be the file name with the extension.  In this example it would be filea1.txt
Row 1 Column E would be the file name and extension with the full target path.  In this example that would be C:\FolderA\FolderAA\filea1.txt

Row 2 Column A would only list the relative directory name for the file. In this example it would be FolderAA
Row 2 Column B would be the full target path without the filename.  In this example that would be C:\FolderA\FolderAA
Row 2 Column C would be the file name without extension. In this example it would be filea2
Row 2 Column D would be the file name with the extension.  In this example it would be filea2.pdf
Row 2 Column E would be the file name and …
1
Hi Experts,
This is in reference of my previous question.
https://www.experts-exchange.com/questions/29131073/Function-to-return-given-records-from-multiple-files-needed.html?anchor=a42767252¬ificationFollowed=220950287#a42767252
I have now the following code
Public Function ListRecords(sFolder As String, sFile As String, sCriteria As String, sNewFile As String)
    Const ForReading = 1
    Dim objRegEx As Object, objFSO As Object, objFile As Object
    Set objRegEx = CreateObject("VBScript.RegExp")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set newFile = objFSO.CreateTextFile(sNewFile, True)
    
    objRegEx.Pattern = sCriteria
    sDir = sFolder & "\"
    StrFile = Dir(sDir & "*" & sFile & "*")
    Do While Len(StrFile) > 0
        Set objFile = objFSO.OpenTextFile(sDir & StrFile, ForReading)
            
        Do Until objFile.AtEndOfStream
            strSearchString = objFile.ReadLine
            Set colMatches = objRegEx.Execute(strSearchString)
            If colMatches.Count > 0 Then
                For Each strMatch In colMatches
                    '' Write strSearchString
                    newFile.Write strSearchString
                Next
            End If
        Loop
        'Debug.Print objFile.DateCreated
        objFile.Close

        
        StrFile = Dir

    Loop
    
    objFile.Close
    newFile.Close
End Function

Open in new window


Would like to add the below
1- function should have another param for field name, one for field name and one for criteria.
2- should auto allocate the field position in order to find the matching criteria.
3- if possible to add date/time of file created of each file into the output file.

Thanks
0
Hi Experts,

I'm looking for a function that would do the following.

Loop thru all files of a given folder.
Search for files containing some wording in their name "PatMed" for example.
All files are ".txt"
and look for PatientID = 123.

Function should return the entire record
If found more than one, should return all
This should be in order of file created.
If possible, to include in each row, the date/time of file created.

So function should Receive 4 parameters (FolderName, FileName, FieldName, Criteria)
and should either create a file with results, or just return a text delimited string.

Sample of file attached.

PS. Would prefer VBA function.

Thanks
Untitled.png
0
Greeting Experts -

I need help creating a PowerShell script to pull a list of user names from Active Directory using each client/users First, Middle, and Last names to find each user in AD.  I don't know how difficult this may be, but if somebody can help with this issue, I would appreciate it.
0
Help coming up with a standard way to name files.   I often read through help documents and see different ways in which people notate the system in name files.

is there a standard way to notate file names that i can look at.  

Example of what i am trying to accomplish.

Every month we have a  file that comes in and we store it for archiving.  People name the files differently sometimes.
A billing file comes in from an outside agency.  the parameters are date of bill, agency issued etc..

Agency Name - Route24
Billing Date - Dec 30 2017

I would name the file    Dec302017_Route24.txt    here comes my problem.   What is a standard way to notate this in an instruction book for my users.  
Currently i would write something like this.    [Date]"_"[Agency].txt       which would then allow the user to come up with Dec302017_Route24.txt

i would like a standard that is exact and a standard that is written on a wiki page or something official... lol

does anyone have a link to a good document standardizing the basic notation on how to name a file?
I am interested more in the insturctions part... ie... when to use brackets, when to use apostrophe's etc...
0
i am printing barcode label on lpt3 is working fine. now I have TSC TE-244 barcode  USB printer.  Normally in VB 6 application
i make batch file

copy c:\barcdprn.prn Lpt3


this is working fine on lpt barcode printer.

now i have change batch file as

copy c:\barcdprn.prn usb003  (bar-code printer is on USB003) . It is not working.

what could be possible solution.

Thanks in advance.
0
I have a text file being created nightly in a network shared folder. That file has many lines including 3 duplicates. The line duplicated 3 times is:

ACCNT	Accounts Receivable - MU	OCASSET

Open in new window


What I need to do is, from within an Access function, delete the 2nd and 3rd dupe, leaving the first one intact.

Why the dupes exist is a rabbit hole that I don't right now have time to fix even though yes, that is the correct way to really fix this problem. But, if I can just have Access code which will delete the 2nd and 3rd entry of that line, it will suffice as a solution for now.

Thank you very much for any input.
0
Hello experts,

i am in need of a script that can copy a file on a daily basis from one directory to another based upon a changing filename. The filename's base stays the same, however the current date is appended to the end of the file.

For Example:
StaticFileName<Today's date in MM-DD-YYYY format>
or
StaticFileName12-17-2018    <-----This is the filename that needs to be copied on 12-17-2018

I am not a scripting expert so suggestion on best method (powershell, batch etc) is also appreciated.

Thanks in advance.
0
Hey,

I am trying to make a Microsoft word document that allows users not to edit content once the content controls are removed. My plan to do this was by restricting the editing to only filling in forms and then creating a code that removes the content control anywhere that there is text value. I am new to VBA and cant get the code to work properly. I can get it to remove the content controls when they are empty but when I try to remove them with content they do not disappear. I have attached the document that I cant get to work.

If anyone can help me that would be fantastic!

Thanks,

Max
Client-Journal-Template.docm
0
Every 70 seconds scrapebox inputs the good proxies into a file, any file I want, call it first.txt. So first.txt say has 5 lines of proxies.
The 70 seconds later, it copies over the previous 5 proxies and puts however many it found, say it was 10.
So first.txt has only 10 proxies, but the first 5 are gone.
So I wanted to copy those proxies every 70 seconds and add them to a second file and combine them with the first file.
So then I will have 15 proxies
0
This is intend to use a vbscript to check for the any USB attached devices. After went through few rounds of testing, found that "USB thumb drive" is appear as "removable disk". While "USB external hard disk" is appear as "local fixed disk". Coincidently, the local hard disk deployed on the PC is appear as "local fixed disk", with drive letter c:. Please see the script contents as follows. I divided the checking on 2 parts, first being the "removable disk" checking, follows by "local hard disk" for usb external hard disk.

Wscript.Echo "Security Checklist: Removable Disks - USB HardDisk & USB Thumb Drive"
Wscript.Echo "--------------------------------------------------------------------"

'for removable disk only - usb thumb drive

'bolDeviceFound = False
'strComputer = InputBox("Enter the name of the computer to Search for USB devices:")
 
 
'query the WMI service for the computer name
 
'Set objWMIService = GetObject("winmgmts:" _
'   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   
 'display the connected computer  
' WScript.Echo "You have connected to computer " & strComputer
'strComputer = "."

Set colItems = objWMIService.ExecQuery ("SELECT * from Win32_LogicalDisk WHERE Description = 'Removable Disk'")
 
For Each objItem in colItems
'      WScript.Echo "The computer " &strComputer &" has a removable USB drive connected with drive letter: " & objItem.Name
        WScript.Echo "The computer has a removable USB thumb …
0
Greeting Experts -  

I need help creating a PowerShell script to pull text document from a list of computers (1000+) using Domain Admin Credentials. The text document in question will have the same name (i.e., pc1.txt, pc2.txt, pc3.txt) as pc located in the C:\drive (i.e., C:\pc1.txt). The script needs remotely pull the text document from each pc "with the same name as the pc" and copy it to a network shared drive....  Can somebody help me with this task.....
0
This is another vbs script to find out the local computer for any shared folder. Please see the script contents,

   strComputer = "."
 
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService= objSWbemLocator.ConnectServer(".", "root\cimv2")
 
Set colShares = objWMIService.ExecQuery("Select * from Win32_Share Where Type=0")
 
For each objShare in colShares
 
    Wscript.Echo "Name: " & objShare.Name  & vbCrLf _
                       & "Path: " & objShare.Path & vbCrLf  _
                       & "Type: " & objShare.Type  & vbCrLf _
                       & "Allow Maximum: " & objShare.AllowMaximum & vbCrLf _
                       & "Maximum Allowed: " & objShare.MaximumAllowed & vbCrLf _
                       & "Caption: " & objShare.Caption  
Wscript.Echo "---------------------------------"
Next

Using this script, I manage to get the list of shared folders. How about if I want to know the share/ntfs permissions of the shared folder, what should be added into the script?

Thanks in advance
0
This is intend to use a vbs script to show the status/startup of selective list of services for Windows 7/10 machine. This script is going to be executed locally on the selected machine, and output the results to a file. Please see the vbs contents,

  Const strSVCName = "DNS Client"
  Dim objWMIService, colServices, objService, strComputer
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

  Set colServices = objWMIService.ExecQuery("Select * from Win32_Service WHERE DisplayName = '" & strSVCName & "'")

  For Each objService in colServices
   Wscript.Echo strSVCName _
   & vbcrlf & "Status: " & objService.State _
   & vbCrLf & "Startup Type: " & objService.StartMode
 Next

So far, I can only get a single service to work. However, I wanted to get an "array" of services, for example, Windows defender firewall, symantec endpoint protection, and so on. How to do it?

thanks in advance.
0
Hi Experts,

I have this question after resolving the following

https://www.experts-exchange.com/questions/29127578/script-to-convert-all-characters-in-excel-sheet-to-A.html?headerLink=workspace_answered_questions

How to modify the script in order to accomplish

1- Select which columns to get obfuscated.
2- letters should be changed with a logic, A should become B, B should become C and so on...Z should become A.
3- Same to numbers, 1 should become 2, 2 should become 3 and so on, then 9 should become 0.

Thanks
0
Hello,

I'm trying to parse out some text from a string using the Len, Right, and InStrRev function.  I just can't get it right and am asking for help.  The string would be something like this:

"My Printer Redirected (123)"

I'm trying to capture "(123)".  This line always changes.  The only text that is the same every time is the text "Redirected".  So in this case:

"blah blah blah Redirected (99)"

I would need to capture the "(99)" this time.  I basically need to capture all text on the right side of "Redirected".

Thanks for your help,
Joel
0
Hello Experts,
I there a way to send messages to WhatsApp from my vb net app?
Regards
0
Hello,

I have an Outlook custom form that uses VB Script to print a label.  This works fine.  IT has since migrated Office to a virtual server.  Because of this, the issue is that every time you log on to the server, the printer name changes dynamically, like "DYMO (redirected 99)".  The "99" is the part that changes.

Is it possible to call out a printer that contains the name "DYMO" in it?  Here is the code that I use.

Sub CommandButtonShipLabelUSPS_Click()

On Error Resume Next

Dim strCurrentPrinter

      Set objDoc2 = GetWordDocLabel("\\fireglass.com\drawing$\Jobs\Task_Templates\Ship-Ship Label USPS.dot")
          Call FillFieldsShipLabel(objDoc2)
          objDoc2.Application.Options.PrintBackground = False
          objDoc2.Application.DisplayAlerts = False
          'objDoc2.Application.ActiveDocument.AttachedTemplate = "Normal"
          'objDoc2.Application.ActiveDocument.PageSetup.Orientation = 1

if Item.UserProperties("PrintHold") = True then
        Set objDoc2 = Nothing
        Set strCurrentPrinter = Nothing
        Set objWord2 = Nothing
      Exit Sub
end if

          strCurrentPrinter = objDoc2.Application.ActivePrinter ' store the current active printer
          objDoc2.Application.ActivePrinter = "DYMO" ' change to another printer

bjDoc2.PrintOut ' print the active sheet
objDoc2.Application.ActivePrinter = strCurrentPrinter

      objDoc2.Application.DisplayAlerts = True
          objDoc2.Application.Options.PrintBackground = True

objDoc2.Close wdDoNotSaveChanges
objWord2.Quit …
0
I have a request form.  I want to let the user attach the file and send it out with the request. Please advise! Thank you!
0
Hello,

I have an Excel spreadsheet that has a date in column A and employee name in column I.  I'd like to get a macro that will identify and delete duplicates if there is a match.  For example, there are two rows on 09/01/2018 for John Doe so the first occurrence would be deleted.

Thanks
0
How to move files from sub folders to a single folder?
0
Cleaning up an environment for a client and found this VB script. No one i've spoken with knows how it works or what it does.
Could someone help translating this into English?


Option Explicit

' Variables.
Dim strCalendarURI           ' As String
Dim reqDoc                   ' As Msxml2.DOMDocument
Dim resDoc                   ' As Msxml2.DOMDocument
Dim pi                       ' As IXMLDOMProcessingInstruction
Dim strPassword              ' As String
Dim strUserName              ' As String
Dim searchrequestNode        ' As IXMLDOMNode
Dim sqlNode                  ' As IXMLDOMNode
Dim strQuery                 ' As String
Dim queryNode                ' As IXMLDOMText
Dim req                      ' As MSXML2.XMLHTTP
Dim objSubjectNodeList       ' As IXMLDOMNodeList
Dim objLocationNodeList      ' As IXMLDOMNodeList
Dim objuidNodeList      ' As IXMLDOMNodeList
Dim objStartTimeNodeList     ' As IXMLDOMNodeList
Dim objEndTimeNodeList       ' As IXMLDOMNodeList
Dim objFacilityNodeList       ' As IXMLDOMNodeList
Dim objdtstampNodeList       ' As IXMLDOMNodeList
Dim objBusyStatusNodeList    ' As IXMLDOMNodeList
Dim objInstanceTypeNodeList  ' As IXMLDOMNodeList
Dim objtextdescriptionNodeList  ' As IXMLDOMNodeList
Dim objNode                  ' As IXMLDOMNode
Dim i                        ' As Integer
Dim strInstanceType          ' As String
Dim objFileSystem, objOutputFile
Dim strOutputFile
Dim MyTimeStart1
Dim MyTimeStart2
Dim MyTimeStart3
Dim MyTimeEnd1
Dim MyTimeEnd2

Open in new window

0
Hi

Please can you help me convert a file call distlistcontacts.xlsx to distlistcontacts.csv located in c:\o365update\ via command prompt.  I have tried a scripts on the web and cant get them to run. Excel is not installed on the pc where the batch file will be scheduled to run from .

Regards


Simon
0
add function to classic asp page with vb script.
Is it possible to save a file temporarily and then attach it to an email in vbscript ?

If I split the code below into two distinct pages, both functions work. I can create the Vcard file and it opens to the user.  Or I can create the email.
But I want to add the vcard file to the email.  Is this possible ?
<% 
if (cStr(Request("SubmitHere")) <> "") Then

	Dim DTSTART, DTEND, SUMMARY, LOCATION, EVENT_DESCRIPTION, PRIORITY, UID, CalendarEvent
	
	DTSTART = DateAdd("h",+5, (rsSaleCallDataNewID.Fields.Item("FollowupDate").Value))
	DTEND = DateAdd("h",+5, (rsSaleCallDataNewID.Fields.Item("FollowupDate").Value))
		
	DTSTART = 	Right("0000" & Year(DTSTART), 4) & _
				Right("00" & Month(DTSTART), 2) & _
				Right("00" & Day(DTSTART), 2) & _
				"T13000" & _
				"Z"
	
	DTEND = 	Right("0000" & Year(DTEND), 4) & _
				Right("00" & Month(DTEND), 2) & _
				Right("00" & Day(DTEND), 2) & _
				"T130000" & _
				"Z"
 
	SUMMARY = (rsSaleCallDataNewID.Fields.Item("VisitType").Value)
	LOCATION = (rsSaleCallDataNewID.Fields.Item("Company").Value)
	EVENT_DESCRIPTION = (rsSaleCallDataNewID.Fields.Item("Comments").Value)
	PRIORITY = "0"
	UID = (rsSaleCallDataNewID.Fields.Item("ID").Value)
	
	CalendarEvent = "BEGIN:VCALENDAR" & vbCrlf & _
	"VERSION:1.0" & vbCrlf & _
	"BEGIN:VEVENT" & vbCrlf & _
	"DTSTART:" & DTSTART  & vbCrlf & _
	"DTEND:" & DTEND  & vbCrlf & _
	"SUMMARY;ENCODING=QUOTED-PRINTABLE:" & SUMMARY & vbCrlf & _
	

Open in new window

0
I'm having trouble using double quotes in vbscript within asp web page.  I get various errors but I'm sure it's my syntax on the quote marks:

objCDO.AttachFile "ContactManagementActivityEditVCal.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "varVcal=yes&" & "var_SaleCall_ID=" &  rsSaleCallDataNewID.Fields.Item("ID").Value %>"
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.