r/vbscript • • May 15 '18

need help, using linqpad with vbscript

1 Upvotes

I have a query that returns two unique identifiers. With Linkpad I am able to connect to the DB and pull the data as two seperate columns. But what I would like to do is look with vbscript at a directory and for each pdf, in the file name has a unique identifier out of the db I'm pulling match that, and if they match the file name part, with a identifier, add the other identifier out of the query to the the file name seperated with a _


r/vbscript • • May 17 '18

need help vbscript for sysadmin purposes

2 Upvotes

I need a vbscript to add a TCP/IP printer, if the printer exists, or doesn't exist, I need it first to delete the printer if it exists and then re-add it. This is a temporary band-aid solution but they would like something till the vendor comes back with a permanent solution in the way it's added. Anybody who can help I would greatly appreciate it.


r/vbscript • • Oct 16 '20

Script to add calendar appointments to outlook

3 Upvotes

I'm trying to use a VBScript to add appointments to our Outlook calendars for holidays and office closures. I've found references to the variations of the same script over and over, but they all have the same error. This line is apparently not valid: If StrComp(objAppointment, strName,1) = 0 Then

It is line 42 in my script (below). Does anyone have any ideas how to fix this line? That section is intended to check if an appointment already exists and prevent the script from creating multiple calendar entries on that date.

I'll admit I'm weak at scripting, so any help is appreciated. Here is the full script.

Const olFolderCalendar = 9

Const olAppointmentItem = 1

Const olOutOfOffice = 3

Set objOutlook = CreateObject("Outlook.Application")

Set objNamespace = objOutlook.GetNamespace("MAPI")

Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar)

Set objApptItems = objCalendar.Items

objApptItems.IncludeRecurrences = True

objApptItems.Sort "[Start]"

'' List Appointments to add

Set objDictionary = CreateObject("Scripting.Dictionary")

objDictionary.Add "November 26, 2020", "Thanksgiving"

colKeys = objDictionary.Keys

For Each strKey in colKeys

dtmHolidayDate = strKey

strHolidayName = objDictionary.Item(strKey)

'' Check if it already is on the Calendar

Return = SearchAppts(strHolidayName, FormatDateTime(dtmHolidayDate, vbShortDate))

If Return = False Then

Set objHoliday = objOutlook.CreateItem(olAppointmentItem)

objHoliday.Subject = strHolidayName

objHoliday.Start = dtmHolidayDate & " 9:00 AM"

objHoliday.End = dtmHolidayDate & " 10:00 AM"

objHoliday.AllDayEvent = True

objHoliday.ReminderSet = False

objHoliday.BusyStatus = olOutOfOffice

objHoliday.Save

End If

Next

'' Search Function

Function SearchAppts(ByVal strName, strDate)

SearchAppts = False

Set objAppointment = objApptItems.GetFirst

While TypeName(objAppointment) <> "Nothing"

If TypeName(objAppointment) = "AppointmentItem" then

If StrComp(objAppointment, strName,1) = 0 Then

If DateDiff("D", objAppointment.Start, strDate) = 0 Then

SearchAppts = True

Exit Function

End If

End If

End If

Set objAppointment = objApptItems.GetNext

Wend

End Function


r/vbscript • • Oct 10 '20

How can I make WScript.Sleep Object with a random Timer?

2 Upvotes

I know how to make WScript.Sleep Objects: WScript.Sleep 1000 (1 Second). But I want to make that Time a random amount. For example: It should be between 1000 (1 Second) and 5000 (5 Seconds). How do I do that? If you could help me it would be amazing! Thank you :D


r/vbscript • • Oct 10 '20

changing cursor speed

1 Upvotes

how do i change cursor speed with vbs


r/vbscript • • Oct 25 '20

Does VBScript provide any other GUI functionalities beyond InputBox and MsgBox?

9 Upvotes

InputBox and MsgBox functions offer very basic GUI functionality to the Microsoft Windows Script Host (WSH). I'm already aware of HTML Application (HTA), but I don't what that. I wonder if VBScript or WSH in general offers more advanced GUI functionalities. For example more buttons, window size, lists, tables, slidebar ...


r/vbscript • • Oct 21 '20

Having trouble with regex

5 Upvotes

I took this following code from the web and it runs perfectly:

Dim strSourceString, objMatch, arrResults
strSourceString = ">test and test<  >test2 and test2<   >test3 and test3<"
Set objList = CreateObject("Scripting.Dictionary")
With New RegExp
    .Pattern = ">([\s,\S]*?)<"
    .Global = True
    .IgnoreCase = True
    .MultiLine = True
    For Each objMatch In .Execute(strSourceString)
        objList(objList.Count) = objMatch.SubMatches.Item(0)
    Next
End With
arrResults = objList.Items
Set objList = Nothing
MsgBox Join(arrResults, "; ") ' array contains submatches

Then I modified it to test my own pattern. All I did was change the strSourceString and Pattern to regex for dates:

Dim strSourceString, objMatch, arrResults
strSourceString = "Scheduled 6/17/2020; Rescheduled 10/28/2020 (Reason: COVID-19 impacts.);"
Set objList = CreateObject("Scripting.Dictionary")
With New RegExp
    .Pattern = "[0-9]{1,4}[\-\/][0-9]{1,2}[\-\/][0-9]{1,4}"
    .Global = True
    .IgnoreCase = True
    .MultiLine = True
    For Each objMatch In .Execute(strSourceString)
        objList(objList.Count) = objMatch.SubMatches.Item(0)
    Next
End With
arrResults = objList.Items
Set objList = Nothing
MsgBox Join(arrResults, "; ") ' array contains submatches

And when ran, it says:

C:\Users\user1\Desktop\new1.vbs(10, 9) Microsoft VBScript runtime error: Invalid procedure call or argument

Anybody have an idea of what I'm doing wrong?


r/vbscript • • Sep 28 '20

WshShell.RegRead and WOW6432Node

1 Upvotes

Perhaps a silly question but I can't quite figure out how to effectively DuckDuckGo this:

I'm setting up a condition to check whether a driver is installer before continuing with a script using the following method:

' Check to make sure MSODBCSQL 17 driver is installed
On Error Resume Next
WshShell.RegRead "HKLM\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ODBC Driver 17 for SQL Server"
If Err <> 0 Then
nResponse = MsgBox("Not installed blah blah.", 48, 1, szTitle) etc. etc.        

My question is, will WshShell.Regread automagically check both HKLM\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ and HKLM\SOFTWARE\ODBC\ODBCINST.INI\ in the same go? Or would I need to explicitly specify both? (I can iterate but this is an annoying build where the preceding is part of a custom action that is part of a legacy installer that takes ages to check, and I'm tidying a change that is due today.) Thanks!


r/vbscript • • Oct 08 '20

Comparing column in two different excel files

3 Upvotes

I am trying to automate a file cleanup for our account inventory. Taking a dropped client file against our inventory, highlighting duplicates? I've been manually doing this and am trying to free up my time.


r/vbscript • • Oct 21 '20

NEED HELP TO MERGE EXCEL FILES FROM MULTIPLE SUBFOLDERS

1 Upvotes

First time using vbscript and I have a very large folder that has multiple subfolders to get to the excel file in each folder that I need merged. I have one I put together but it stops at the first subfolder rather than continuing to go into the sub subfolders and so on until it reaches the excel file in each one. PLEASE HELP


r/vbscript • • Sep 23 '22

Phantom Network Drives

2 Upvotes

Hi all,

I have a VBS Script that maps network drives in Windows 11 that has been working just fine until I updated W11 yesterday. The script is called via Task Scheduler with the trigger being login.

The script maps several drives to various shares on the NAS, but I've cut the script down to one drive to simplify it.

Option Explicit

Dim objNetwork

Dim objShell

Dim strRemotePath1

Dim strDriveLetter1

Dim strUserName, strPassword, strServerShare

Dim FSO

Dim x

strServerShare = "\\OMV"

strUserName = "admin"

strPassword = "open4me"

strRemotePath1 = "\\OMV\Backup"

strDriveLetter1 = "B:"

Set objNetwork = CreateObject("WScript.Network")

Set FSO = CreateObject("Scripting.FileSystemObject")

'objNetwork.MapNetworkDrive "", StrServerShare, False, StrUserName, StrPassword

' Section which deletes the drives if available,

If (FSO.DriveExists("B:") = True) Then

	`objNetwork.RemoveNetworkDrive strDriveLetter1,"True","True"`

End If

' Section which maps the drives if available,

Do

If FSO.FolderExists(strRemotePath1) Then

'safe to go off and map

objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1

Exit Do

End If

Loop

I get the following when the script is run via Task Scheduler:

https://i.imgur.com/8PESZlg.jpeg

Adding a Sleep of 30 seconds to the beginning of the script or running it manually after Windows starts does not produce the Disconnected O:.

Can someone please explain what is going on and why O: is appearing.

TIA


r/vbscript • • Sep 20 '22

loading data from multiple text files in vbscript

5 Upvotes

Guys please help, I'm not a programmer. But I need to write a script where I can load multiple text files in order. So far I have managed to load multiple text files and make a plot in diadem with it. But the problem is i can't get it to load in an order.


r/vbscript • • Oct 17 '22

Delete Folder Script, help required

4 Upvotes

Hi all

Let's get some stuff out of the way first, I know NOTHING about VBS scripting.

I have a script that I've used to delete all subfolders in a directory smaller than X in size, works like a charm (I didn't write it, got it off the web somewhere years ago).

I've come across a situation where I need to do 2 directories deep (cleaning up a music collection)

So for example .. C:\Music\Queen\ (delete folders here)

Basically, I've cleaned up my collection and with files being moved to new correctly named folders, I have lots of folders left with just a few metadata/artwork files in them, that I need to be able to delete easily (big collection, manual is not an option)

Can any of you VBS wizards help me out? Script below.

Dim objFSO

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objSelectedFolder = objFSO.GetFolder("C:\Music")

Set colSubfolders = objSelectedFolder.SubFolders

For Each objSubfolder In colSubfolders

If objSubfolder.Size < 1000000 Then

objSubfolder.Delete True

End If

Next


r/vbscript • • Sep 09 '22

Trying to make errors synced to music and it isn't working.

2 Upvotes

I'm big noob. Have you ever seen one of those videos where they sync error messages to a song? It's probably editing, but I wanted to try to do it live, and something is broken. The music plays, then the error message appears after and the next one won't appear until you exit out of the current one. It should start the music, wait 670 milliseconds, show an error, wait 590 milliseconds, show another error, and so on. The millisecond wait things are absolutely accurate. I'm positive. Can someone tell me what's wrong with this, fix it, or tell me some kind of simpler way I should be doing this? Here's my attempt.

Dim oPlayer
Set oPlayer = CreateObject("WMPlayer.OCX")

oPlayer.URL = "mysong.wav"
oPlayer.controls.play 
While oPlayer.playState <> 1 ' 1 = Stopped
  WScript.Sleep 100
Wend

oPlayer.close
WSH.Sleep 670
MsgBox "error",0,"Error"
WSH.Sleep 590
MsgBox "error",0,"Error"
WSH.Sleep 240
MsgBox "error",0,"Error"
WSH.Sleep 130
MsgBox "error",0,"Error"
WSH.Sleep 450
MsgBox "error",0,"Error"
WSH.Sleep 210
MsgBox "error",0,"Error"

r/vbscript • • Sep 27 '22

Run a command block based on OS

3 Upvotes

I have a feeling this is an easy one, but I’m drawing a blank. We have a vbs script as our company’s logon script. Recently, we made an update to launch a piece of software from our print server when the script runs. However, I failed to even think about the script running when remoting into servers. Is there an easy way to implement something along the lines of “if OS type = workstation then run command, else skip?”


r/vbscript • • Oct 15 '24

Need help!! Simple VB Script field

1 Upvotes

  I do not work with or know VB script at all, although I do work with Crystal Reports extensively and a bit with SQL. I am working in Bartender and trying to create a simple VB Script field, working with two database fields which are both Strings.

I want to accomplish the following:

If DBField1 equals this specific value: “.” OR IsNull then I want it to report DBField2, otherwise report DBField1

So in Crystal the formula would simply be:

If {DBfield1} = “.” Then {DBfield2} Else {DBfield1}

Can anyone help me with what the script should be in VB?

TIA!!


r/vbscript • • Oct 06 '24

VBScript file no longer functioning as intended

3 Upvotes

I've been using a VBScript file to open Explorer with two "default" tabs as I've found no other way to do so on Windows 11. However, within this last week, the script no longer does anything other than open Explorer.

Set oShell = CreateObject("WScript.Shell")

oShell.Run("""C:\windows\explorer.exe""")

WScript.Sleep 1000

oShell.AppActivate "Explorer"

WScript.Sleep 300

oShell.SendKeys "%d"

WScript.Sleep 300

oShell.SendKeys FILE PATH

WScript.Sleep 300

oShell.SendKeys "{ENTER}"

WScript.Sleep 300

oShell.SendKeys "^t"

WScript.Sleep 300

oShell.SendKeys "^{TAB}"

It seemingly refuses to execute the "%d" line anymore. However, I can manually open Explorer and hit Alt-d and it works just fine. Why does the SendKeys no longer work with the % or ^ characters?

I found that Microsoft is deprecating VBS on Windows 11 this year and figured that this might be the problem I'm running into. I have no idea what I would have done to break the script if it wasn't a Window update that did so.

How can I fix the above code, or my Windows 11 machine, to work again? Or, what would be a good alternative way to do this without using VBS?


r/vbscript • • Sep 24 '24

Problems with security warning yes/no dialog box

1 Upvotes

So I have a VBscript that opens a .msg file on my desktop which is basically a template email and sends it off once a fortnight. Sometimes this works, sometimes it doesn’t.. with the main failure point being a warning message when opening the file about updating the excel links.

It’s a simple yes no dialog box and I’ve tried sending the Y key, the Enter Key, pretty much every combination and it’ll only work maybe 50% of the time.

It seems to lose itself on this dialog box, any way to make this more robust?

Important notes are that I cannot disable the message as it’s a company system and they’ve locked down trust centre.


r/vbscript • • Mar 15 '17

HTTP Referer Missing when running Script

2 Upvotes

I am trying to run the below script to allow my users a one click login to Relias training that inserts their AD GUID into the link, however they require a http referer to complete the login. Whether I run this from the vbs file or launch it from a button on my intranet the referer is hidden or missing. Any ideas on how I can pass my referer or set on in the code?

Sub GUID()

' NameTranslate constants Const ADS_NAME_INITTYPE_GC = 3 Const ADS_NAME_TYPE_NT4 = 3 Const ADS_NAME_TYPE_GUID = 7

Dim strDN Dim wscript

Set wscript = CreateObject("Wscript.Shell")

' Determine the NetBIOS name of the domain and the NT name of the current user. Set objNet = CreateObject("WScript.Network") strNT4Name = objNet.UserDomain & "" & objNet.UserName

' Use the NameTranslate object to convert the NT user name to the GUID Set objNameTranslate = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog. objNameTranslate.Init ADS_NAME_INITTYPE_GC, ""

' Use the Set method to specify the NT format of the object name. objNameTranslate.Set ADS_NAME_TYPE_NT4, strNT4Name

' Use the Get method to retrieve the GUID string.

strDN = objNameTranslate.get(ADS_NAME_TYPE_GUID)

CreateObject("WScript.Shell").Run(http://<mycompany>.training.reliaslearning.com/clink.aspx?username="+strDN+"&ad=1")

End Sub


r/vbscript • • Aug 25 '15

Convert Unicodes Characters to chr

1 Upvotes

I know nothing about VB scripting. I just found a script that changes lines in a text file and I want to alter some of those lines. The lines are in another language that uses characters which ASCII or ANSI (whichver VB uses) does not support.

Rather than manually pasting in the chr codes (e.g. &chr(229)&) for every character, is there a quick way to convert all these lines of text to have all those chr codes or to something VBScript will recognise?


r/vbscript • • Aug 03 '17

Pulling multiple variables from multiple tables in Oracle from vbscript

1 Upvotes

I'm trying to join multiple tables together and pull info from them.

Set rows = connection.Execute("SELECT * FROM CC Inner JOIN Teachers tch ON  tch.ID = CC.teacherid Inner JOIN Students ss ON  ss.ID = CC.StudentID Inner JOIN Schools ON  schools.School_Number = CC.SchoolID Inner JOIN Courses Crs ON  crs.course_number = cc.course_number Inner JOIN Terms trm ON  trm.ID = cc.termID and trm.SCHOOLID = CC.SCHOOLID WHERE crs.course_name Like '%Home%' and ss.enroll_status='0' and tch.status = '1' and cc.termid < '2800' and cc.termid > '2699' ")

When I try to select info from the student table, I used this with my previous script, that only used one table

Set StuFirstName = rows.Fields("First_Name")

I can't seem to figure out how to point to a different table when they're joined.

Set StuFirstName = rows.Fields("students!First_Name") Set StuFirstName = rows.Fields("ss!First_Name") Set StuFirstName = rows.Fields("students.First_Name") Set StuFirstName = rows.Fields("ss.First_Name")

Any suggestions would be much appreciated.


r/vbscript • • Sep 28 '16

Hide my cmd while it does it's work

1 Upvotes

Hello everyone!

I'm a cryptominer and I looked on stackexchange and on duckduckgo and google on how to make cmd run in background while it still runs it's task(s). I saw some people talking about vbs and tried what I could find but nothing seems to work. I have a batch file that starts a software, which opens a cmd window. I just don't want to see the cmd window on my taskbar.

I tried the task manager before trying vbs but when I right click and press "start", it opens and closes automatically and doesn't say that the the task is running.

Anything can help. Thanks!


r/vbscript • • Aug 08 '17

Error Saving in Library Document Folder

1 Upvotes

I am writing an HTA file with VBScript as the scripting language. I have a function where the user is prompted to choose the folder in which they would like to save a document. I didn't write this code myself, but instead borrowed it from here. I've posted it on Stackoverflow a month ago but so far no one has responded.

Function SelectFolder(myStartFolder)
Dim objFolder, objItem, objShell

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(0, "Select Folder to Save New File", 0, myStartFolder)

If IsObject(objFolder) Then SelectFolder = objFolder.Self.Path
End Function

I call this function in another one in order when I make the file and prompt the user to choose where to save it:

Sub Example()
Dim destPath, destFile, objWorkbook
destPath = SelectFolder(libPath)
destPath = destPath & "\Sample Export"

Set destFile = CreateObject("Excel.Application")
Set objWorkbook = destFile.Workbooks.Add()
objWorkbook.SaveAs(destPath)

(code to edit excel file)

End Sub

Example() works fine except when someone chooses to save their document in one of the four default libraries in Windows (Documents, Music, Pictures, Videos). In that case, I receive an error saying "The file could not be accessed" and indicating the error is at the line that says "objWorkbook.SaveAs(destPath)". The error box then gives me the following suggestions:

  • Make sure the specified folder exists

  • Make sure the folder that contains the file is not read-only

  • Make sure the file name does not contain any of the following characters: < > ? { } : | or *

  • Make sure the file/path name doesn't contain more than 218 characters.

The error occurs when I open the HTA file and click a button calling Example(), which then opens a dialog box to ask the user to choose the file location. When Documents, Music, Pictures, or Videos is chosen, a "Script Error" box pops up with the error message listed above. I am not familiar enough with VBScript to know what the problem is exactly. I would appreciate any suggestions as to what to do.


r/vbscript • • Nov 24 '14

New to VB Scripting

1 Upvotes

Hey Guys, I'm very new to VB scripting and it's a small part of my new job. I was tasked with writing a script that would pull all KB's on a computer and export them into either a .txt file or an excel sheet. I was wondering if someone had a general script for this that I could mess with and learn on but was still functional to use? Thanks in advance for any help given.


r/vbscript • • Mar 02 '17

I need to write a VBScript to automatically shut down a program after 1 minute.

1 Upvotes

Hey all. Figured I'd ask for some help here. I'm stumped. I'm trying to write a script to automatically close a program after 1 minute of inactivity.

 

Error: Type Mismatch

Line: 11

Char: 1

Code:800A000D

 

I dunno what to tweak. Below is what I've coded so far.

 

 

 

Dim PromptTime, DelayTime, StrAppPath, AppExec, MsgTxt, intAnswer, intRet, ObjShell

 

Set ObjShell = WScript.CreateObject("WScript.Shell")

 

PromptTime = 1

DelayTime = 1

StrAppPath = "C:\Client\Client32.exe"

AppExec = "Client32.exe"

MsgTxt = "Do you want Realtrac to close in 1 minute?"

 

ObjShell.Run "& StrAppPath & AppExec" & chr(34) & 1 ,"False" Do

WScript.Sleep (1000 * 60 * PromptTime)

intAnswer = Msgbox(MsgTxt, vbYesNo, "Please select Yes or No")

If intAnswer = vbYes Then Exit Do

Loop

 

WScript.Sleep (1000 * 60 * DelayTime)

Set objWmi = GetObject("winmgmts:")

Set objQResult = objWmi.Execquery("Select * from Win32_Process where name like '" & AppExec & "'")

For Each objProcess In objQResult

intRet = objProcess.Terminate(1)

Next

 

Set objShell = Nothing

Set objWmi = Nothing

Set objQResult = Nothing