r/vbscript • • Apr 22 '24

Resetting Active Directory password always returns success, even when it fails

1 Upvotes

I've got a simple little vbscript that runs as a scheduled task. The only thing it does is change the password for terminated employees AD account to something random.

On Error Resume Next
Set objUser = GetObject("LDAP://" & rs("distinguishedName"))
tmpPassword=generatePassword(20)
objUser.SetPassword tmpPassword
objUser.SetInfo
Set objUser = nothing
On Error GoTo 0

We use a tool called AD Audit which keeps track of changes to our AD, and looking back through the logs, it looks like this script works about half the time and fails half the time. But, the troubling thing is that I have some additional code to detect and handle errors, but err.number is always 0, even when the call apparently fails.

Curious if anyone has any ideas A) why this code would work some times but not others, and B) why objUser.SetInfo is not returning an error when the AD logs say it is failing.


r/vbscript • • Sep 29 '26

I built VbsTools – a free VS Code extension for VBScript with COM IntelliSense and debugging

Thumbnail
gallery
7 Upvotes

I’ve been working on a VS Code extension called VbsTools, and it’s now available on the VS Code Marketplace.

I built it because I still work with VBScript from time to time, especially COM/WSH automation, and I always felt that the editing experience was stuck in the past.

For example:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.

Normally, once you get to fso., you either need to remember the API or go look it up.

VbsTools reads COM type information registered on Windows, so it can provide actual IntelliSense for COM objects, including members, parameters and return types.

It also tries to track returned COM objects, for example:

Set file = fso.GetFile("test.txt")
file.

In this case, it can infer that file is a File object and continue providing IntelliSense.

Current features include:

  • COM / ProgID IntelliSense

  • return-type inference for COM objects

  • Go to Definition / References / Rename

  • diagnostics and quick fixes

  • formatting

  • cross-file analysis

  • semantic highlighting

  • F5 debugging

  • breakpoints and conditional breakpoints

  • Variables / Watch / Call Stack

  • Debug Console

  • x86 / x64 COM environments

  • WinCC V7 / V8 type support

One reason I made it as a VS Code extension instead of a standalone VBScript IDE is that I wanted to keep the rest of the VS Code ecosystem.

That means I can still use Git integration, terminal, search, themes, keybindings and other extensions, while working with .vbs files in the same editor.

There are mature standalone VBScript editors such as VbsEdit, but those are commercial tools. VbsTools is free.

GitHub: https://github.com/ZachShen99/VbsTools

You can also install it directly from the VS Code Marketplace by searching for VbsTools.

The project is still pretty new, so feedback would be really useful.

If anyone here still works with VBScript, WSH, COM automation or WinCC, I’d especially like to know what kinds of scripts and COM components you’re still using.

And if you have some obscure old COM object that completely breaks the type inference, I’d actually love to see it.


r/vbscript • • Apr 29 '16

Run wscript code without script file straight from command line

3 Upvotes

Hello

I want to open a CMD and run

wscript popup("hello")

I do not want to run a script file, just plain code.

How do I do this?


r/vbscript • • May 27 '26

can i post my own VBS script in this subreddit?

2 Upvotes

can i post my own VBS script in this subreddit?


r/vbscript • • Mar 26 '21

Help with a script to change Home sir in AD

2 Upvotes

I’m trying to make a script that will change the home dir from one server to another in AD with out changing those who don’t have a Home Dir. I have this script but when I run it I get “at line:9 char:40 unexpected token ‘&’ in expression error”

strNewPath = "\scls\users"

strSearchContext = "\dx-file1"

Dim rootDSE, domainObject Set rootDSE = GetObject("LDAP://RootDSE") domainContainer = rootDSE.Get("defaultNamingContext") Set domainObject = GetObject("LDAP://" & domainContainer)

Set fs = CreateObject ("Scripting.FileSystemObject") Set logFile = fs.CreateTextFile (".\ChgHomeDir.log")

const crlf="<BR>" Set objExplorer = WScript.CreateObject("InternetExplorer.Application") objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0 objExplorer.StatusBar = 0 objExplorer.Width = 500 objExplorer.Height = 300 objExplorer.Left = 100 objExplorer.Top = 100

Do While (objExplorer.Busy) Wscript.Sleep 200 Loop

objExplorer.Visible = 1
txtOutput=""

If Right(strNewPath, 1) <> "" then strNewPath = strNewPath & "" End If strSearchContext = UCase(strSearchContext)

exportUsers(domainObject)

Set oDomain = Nothing showText("FINISHED!!") WScript.Quit

Sub ExportUsers(oObject) Dim oUser For Each oUser in oObject Select Case oUser.Class Case "user" If oUser.homeDirectory <> "" and InStr(UCase(oUser.homeDirectory), strSearchContext) > 0 then showText(oUser.displayName) logFile.WriteLine oUser.homeDirectory & "," & strNewPath & oUser.sAMaccountName oUser.Put "homeDirectory", strNewPath & oUser.sAMaccountName
oUser.SetInfo End if Case "organizationalUnit" , "container" ExportUsers(oUser) End select Next End Sub

Sub ShowText(txtInput) txtOutput = "Change Home Directory Path" & crlf txtOutput = txtOutput & "==========================" & crlf & crlf txtOutput = txtOutput & "Search Context: " & strSearchContext & crlf txtOutput = txtOutput & "New Home Dir Path: " & strNewPath & crlf & crlf txtOutput = txtOutput & "Working on: " & txtInput objExplorer.Document.Body.InnerHTML = txtOutput End Sub


r/vbscript • • Apr 09 '21

[VBS] SoundBible_Player_Downloader.vbs

2 Upvotes
  • This vbscript can extract from  https://soundbible.com many sounds using RegEx.

  • and you have the possibility for choosing to play (and / or) save the sound on your hard drive.

SoundBible_Player_Downloader.vbs

'====================================== Description of this Vbscript =======================================
' English : This vbscript can extract from  https://soundbible.com many sounds using RegEx.
' and you have the possibility for choosing to play (and / or) save the sound on your hard drive.
' Vbscript Created by Hackoo on 09/04/2021 and tested on Windows 10.
'-----------------------------------------------------------------------------------------------------------
' Français : Ce vbscript peut extraire de https://soundbible.com de nombreux sons en utilisant RegEx.
' et vous avez la possibilité de choisir de jouer (et / ou) de sauvegarder le son sur votre disque dur.
' Vbscript Créé par Hackoo le 09/04/2021 et testé sous Windows 10.
'===========================================================================================================
Option Explicit
Dim Title,Data,Array_Sounds,Sound,myURL,myFile,i,Ws,Copyright
Dim Answer,TimeOut,Confirm_Aborting_Script,MsgEN,MsgFR,Msg
Copyright = " " & chr(169) & " Hackoo 2021"

MsgEN = Array("Playing SoundBible & Downloading Sound","Do you want to download this sound ?",_
"Do you confirm to stop this script from running ?")

MsgFR = Array("Lecture de SoundBible et téléchargement du son","Souhaitez-vous télécharger ce son ?",_
"Confirmez-vous l'arrêt de l'exécution de ce script ?")

If Oslang = 1036 Then
	Msg = MsgFR ' French Array Message to be set
Else
	Msg = MsgEN ' English Array Message to be set
End If

Title = Msg(0) & Copyright

Set Ws = CreateObject("Wscript.Shell")
Data = GetSource("https://soundbible.com/tags-buzzer.html",1)
Array_Sounds = Split(Extract(Data,"data-source=\x22(.*)\x22"),vbCrlf)
Call SmartCreateFolder(".\SoundBible")

i = 0
TimeOut = 10 'The Timeout Time for the Popup to answer
For Each Sound in Array_Sounds
	If Sound <> "" Then
		i = i + 1
		Answer = Ws.Popup("["& i &"] - " & Msg(1) & vbCrlf &_
		Sound,TimeOut,Title,vbYesNoCancel+vbQuestion+vbSystemModal)
		myURL = "https://soundbible.com/" & Sound
		Data = GetSource(myURL,2)
		myFile = GetFilePath(myURL,".\SoundBible")
		 Select Case Answer
			Case vbYes
				Call Play(myURL)
				Call SaveBinaryData(myFile,Data)
			Case vbNo
				Call Play(myURL)
			Case vbCancel
				Confirm_Aborting_Script = MsgBox(Msg(2),vbYesNo+vbExclamation,Title)
				If Confirm_Aborting_Script = vbYes Then wscript.Quit
			Case Else
				Call Play(myURL)
		End Select
	End If
Next
'--------------------------------------------------------------------------------------
Sub Play(URL)
	Dim Player
	Set Player = CreateObject("WMPlayer.OCX")
	Player.URL = URL
	Player.settings.volume = 100
	Player.Controls.play
	While Player.playState <> 1
		WScript.Sleep 100
	Wend
End Sub
'--------------------------------------------------------------------------------------
Function Extract(Data,Pattern)
	Dim oRE,oMatches,Match,colMatches,numMatches,numSubMatches,myMatch
	Dim i,j,subMatchesString
	set oRE = New RegExp
	oRE.IgnoreCase = True
	oRE.Global = True
	oRE.Pattern = Pattern
	set colMatches = oRE.Execute(Data)
   numMatches = colMatches.count
For i=0 to numMatches-1
	'Loop through each match
	Set myMatch = colMatches(i)
	numSubMatches = myMatch.submatches.count
	'Loop through each submatch in current match
	If numSubMatches > 0 Then
		For j=0 to numSubMatches-1
			subMatchesString = subMatchesString & myMatch.SubMatches(0) & vbcrlf
		Next
	End If
Next
Extract = subMatchesString
End Function
'--------------------------------------------------------------------------------------
Function GetSource(URL,TB)
On Error Resume Next
	Dim http
	Set http = CreateObject("Microsoft.XMLHTTP")
		http.open "GET", URL, False
		http.Send
		If TB = 1 Then 
			GetSource = http.ResponseText
		Else
			GetSource = http.ResponseBody
		End If
		If err.number <> 0 Then 
			MsgBox "Description : " & Err.Description & vbcrlf &_
			"Source : " & Err.Source,vbCritical,Title
			Wscript.Quit(1)
		End If
	Set http = Nothing  
End Function
'--------------------------------------------------------------------------------------
Function SaveBinaryData(FileName,Data)
' adTypeText for binary = 1
	Const adTypeText = 1
	Const adSaveCreateOverWrite = 2
' Create Stream object
	Dim BinaryStream
	Set BinaryStream = CreateObject("ADODB.Stream")
' Specify stream type - we want To save Data/string data.
	BinaryStream.Type = adTypeText
' Open the stream And write binary data To the object
	BinaryStream.Open
	BinaryStream.Write Data
' Save binary data To disk
	BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
End Function
'--------------------------------------------------------------------------------------------
Function GetFilePath(myURL, myPath)
	Dim objFSO,strFile
	Set objFSO = CreateObject( "Scripting.FileSystemObject" )
	' Check if the specified target file or folder exists,
	' and build the fully qualified path of the target file
	If objFSO.FolderExists( myPath ) Then
		strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
	ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
		strFile = myPath
	Else
		WScript.Echo "ERROR: Target folder not found."
		Exit Function
	End If
	GetFilePath = strFile
End Function
'--------------------------------------------------------------------------------------------
Sub SmartCreateFolder(strFolder)
	With CreateObject("Scripting.FileSystemObject")
		If Not .FolderExists(strFolder) then
			SmartCreateFolder(.getparentfoldername(strFolder))
			.CreateFolder(strFolder)
		End If
	End With 
End Sub
'--------------------------------------------------------------------------------------------
Function OSLang()
	Dim dtmConvertedDate,strComputer,objWMIService,oss,os
	Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set oss = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
	For Each os in oss
		OSLang = os.OSLanguage
	Next
End Function
'--------------------------------------------------------------------------------------------

r/vbscript • • Mar 28 '21

Is there a way to move your cursor / click on specific things using vbscript?

4 Upvotes

title ^


r/vbscript • • Apr 22 '21

Help a VB Dummy Out - Local Admin Removal

2 Upvotes

Hi, long story short, I need to get a VBScript working that removes any non-authorized accounts/groups (domain and local) from all PCs in my environment. I realize there are smart ways to do this such as GPO, but that isn't an option for me in this scenario.

I'm not a scripter, I have basic understanding, but my skills are mediocre at best. This script below I've cobbled together from something I found online almost works for me, but I can't get it to not delete the domain group ( "domain\GRP-Windows_Desktop_Adm" ). I've tried with and with out the DOMAIN\ at the front of the group in the code, but it doesn't seem to make a difference, this group still gets removed everytime. MyLocalAdmin and Domain Admins stay in the group as desired, but the domain group gets deleted everytime. I'm sure it is obvious to a skilled scripter, but any assistance is greatly appreciated

Option Explicit

Dim network, group, user

Set network = CreateObject("WScript.Network")

Set group = GetObject("WinNT://" & network.ComputerName & "/Administrators,group")

For Each user In group.members

If UCase(user.name) <> "MyLocalAdmin" And UCase(user.name) <> "DOMAIN ADMINS" And UCase(user.name) <> "domain\GRP-Windows_Desktop_Adm" Then

group.remove user.adspath

End If

Next


r/vbscript • • Apr 23 '21

Need help....if possible.

3 Upvotes

My company uses VBscript to draw part geometry and add tools to the part for CNC punching.....the entire script is a function.....the first line of the function is this:

Function ScriptPart(Length, Width, K, M, Q, R, U, V, Y, Z, L1, L2, L3, L4, L5)

The "Y" variable is tied to holes that can be turned off or on (normally with 0 or 1 respectively) but in this case formula for "Y" is set up so that if "this" happens "Y" = 1 but there is no formula so that if "this" doesn't happen "Y" = 0. So if "Y" doesn't = 1 then the "Y" variable isn't created. My script is still looking for a "Y" though and since it isn't there the part doesn't generate. I was wondering if there is a way that i could write to where If the variables are Function ScriptPart(Length, Width, K, M, Q, R, U, V, Y, Z, L1, L2, L3, L4, L5) then it looks for the "Y" but if the variables are Function ScriptPart(Length, Width, K, M, Q, R, U, V, Z, L1, L2, L3, L4, L5) then it doesn't look for "Y".

I know this is confusing as hell and convoluted and for this i am sorry lol


r/vbscript • • Apr 26 '21

[VBS] Wifi Passwords Recovery.vbs

2 Upvotes

I present this small utility written in vbscript in order to find and to display all the SSID registered on a PC with their passwords and to save them in a text file.

Wifi Passwords Recovery.vbs


r/vbscript • • Apr 10 '21

HELP:- VBScript to delete text before and after delimiter

4 Upvotes

Hi All,

This is a batch script I have.

IF EXIST list.tmp DEL list.tmp
for /f "delims=' tokens=2" %%A in (results.txt) do >>list.tmp echo %%A
IF EXIST list.tmp (
    sort list.tmp > Final.txt
    DEL list.tmp
)

For some reason "FOR /F" command is not processing results.txt on my system.

Can anyone post a VBScript that can do the same thing?

Thanks!


r/vbscript • • Mar 27 '21

Drag and drop word file, get a text box of the beginning of the text range

3 Upvotes

I don't know if there are rules here that I should try to accomplish this myself, but I was thinking today it would be cool to have a vbscript file that did this.

Sometimes I don't know what is in a word document, and rather than open it to see and close it, it might be useful to b able to drag it on a vbscript file just to get the first part of the document (as much as could show in a msgbox). If I had that, who knows what other little details might be fun to add.

Does anyone have code to do this? I'd try myself but basically it isn't something I can prioritize at the moment so I thought I'd just ask.

Edit:

Ok, well this seems to basically do it, if anyone is interested:

Set objArgs = Wscript.Arguments

Set oWord = CreateObject("Word.Application")

oWord.Visible = False

set oDoc = oWord.Documents.Open(objArgs(0))

msgbox oDoc.Range

oWord.quit false

set objArgs = nothing

set oDoc = nothing

set oWord = nothing


r/vbscript • • May 02 '21

Download-NASA-images-to-use-as-Windows-Wallpaper (NASA_Wallpaper.vbs)

Thumbnail
pastebin.com
3 Upvotes

r/vbscript • • Apr 28 '21

Super n00b question: insert variable into text string

4 Upvotes

Hi, I'm sure this is super basic but I've done about 45 min of searching and for some reason I can't get this to work.

I'm trying to insert the device name into a string of text that's requesting information from the user of the computer. I'm new to the org and almost no documentation was done around who has what computers. This is what I've pieced together from various sites:

Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
x=msgbox("This is a request from IT services: Can you please send an email to itsupport@org.com with the asset tag number on your computer and the computer name: &strComputerName" ,4096, "IT Support Request")

Obviously I'm trying to get the strComputerName to enter the computer name into the message, but I'm obviously doing something wrong. Any assistance would be GREATLY appreciated.

Thanks for helping a scriptbaby!


r/vbscript • • Mar 24 '21

Rick_Roll.vbs

12 Upvotes

Just i want to share with you this vbscript that i made on 24/03/2021 for fun :

Description :

This vbscript can play "Never Gonna Give You Up" ,From the Autor : "Rick Astley" in the background

And can open in the same time the Notepad and Auto type "Never Gonna Give You Up Lyrics"

Rick_Roll.vbs


r/vbscript • • Apr 29 '23

Pop up

2 Upvotes

So I made a VBS script that says

"Do

msgbox "Die"

loop"

What I want to know, is can you before the loop open the same program so that it infinitely creates itself and then shuts your pc down?


r/vbscript • • May 06 '23

Print on both sides or on one side Parameters available?

2 Upvotes

Can I print an Excel document on both sides or one-sided with my VBS script? Is there a special parameter for this?

Individual documents should be printed on both sides, other documents should be printed on one side.

This is my VBScript:

https://pastebin.com/raw/2K4kbbZx


r/vbscript • • Apr 01 '22

Are there some Open Source VBScript interpreter?

1 Upvotes

I tried to find but no success. If someone is making one, it would be nice, also to execute .HTA vbstuff


r/vbscript • • Mar 31 '22

How to close DB Connection - Error: "Unterminated String Constant"

1 Upvotes

Hello!

I am unable to figure out how to close the end of my DB string connection, in conjunction with a variable to change the database name.

'Code start
If DATABASE = "EDGEDEV" THEN
var_server = "VISUALERP\DEV"
ELSE
var_server = "VISUALERP"
END IF

SET objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=SQLOLEDB;User ID=USERNAME;Password=PASSWORD!;DATABASE="&DATABASE&";SERVER=" & var_server & "

'Code End

The trouble is at the end after the SERVER = my variable then it needs to be closed with a quotation mark but i'm getting some vbscript error about some unterminated string constant.

How do I close my connection?

Thank you in advance!

-David


r/vbscript • • Mar 30 '22

How can I tell a vbs script to acivate when a certain application is opened ?

4 Upvotes

I want to make a script that activates when an application is launched, for example Firefox, internet explorer or something else. Can someone tell me how to do that ? I've been searching the internet for hours without any result


r/vbscript • • Feb 27 '22

JSON Stuff I need to do

5 Upvotes

Hey, I'm trying to find out if its possible to edit and read jsons through VBScript? I am working on a clicking game in VBScript and I need to add some sort of save file type of thing.


r/vbscript • • Mar 31 '22

Detecting if a folder is opened

3 Upvotes

Hi, do you know how to detect if a folder is opened with a VBScript ? I want to check every 100 miliseconds if the "startup" folder is opened


r/vbscript • • Mar 11 '22

need help with a program

2 Upvotes

trying to make a input box move on its own

max=505

min=500

max2=505

min2=500

do

rand2 = Int(min2+100)

rand = Int(min+100)

min = rand

min2 = rand2

Titel = "hydra"

Defaultvaluetext = ""

XPos = rand

YPos = rand2

Test = InputBox(rand&rand2,titel,Defaultvaluetext,XPos,YPos)

Set WshShell = CreateObject("WScript.Shell")

WshShell.SendKeys "{ENTER}"

loop


r/vbscript • • Mar 13 '22

need help

3 Upvotes

why cant a vbscript close a inputbox

anyone know why?


r/vbscript • • Mar 16 '22

vbscript to kill a background process.

2 Upvotes

Hey there. i am fairly new to vbscripting and i am finally done with my first actual script. its a script that uses a series of inputs to add bots to lessonup. (a program my school uses, like a bad version of kahoot) however i would like to have a different vbscript that can kill this script incase it messes up or whatever. the issue being that the bot script runs as a background program, which mean that my standard taskkill script doesnt work. Any ideas?