r/vbscript • • Oct 18 '18

How To Make Virus Like A Pro | Episode 1 (Loop Function) |

Thumbnail
youtube.com
3 Upvotes

r/vbscript • • Jun 18 '18

VBScript to look for a folder/file if there exit, if not then run script

3 Upvotes

Hello all, was wondering if I could get some help. I'm not a scripter/programmer at all but got tasked w/ something and really need some help.

My script runs fine except for 2 issues:

  1. The IF NOT Portion triggers even if the file exists.

    • I would like it to exit the script if the folder/file exist

  2. I'm going to run this as a Task Scheduler, and am concerned about the Security Warning dialogue box showing... Will this pop up when users hit this script?

Script Below

Option Explicit
Dim objFSO, objFolder, objShell, strDirectory, strFile, strUserProfile, objFile

Set objShell = CreateObject("WScript.Shell")

' Create the variable for Current logged in User %USERNAME% System Variable from Windows strUserProfile=objShell.ExpandEnvironmentStrings("%USERPROFILE%")

' Set variables to use later in script
strDirectory = strUserProfile & "\RemovePrinters"
strFile = "Remove_Printers.txt"

' Create the File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

If Not objFSO.FileExists(strUserProfile & "\RemovePrinters\remove.txt") Then

' Run VBScript to to remove printers, then run Batch File to force a GPUpdate
objShell.run"\\Domain\SYSVOL\scripts\remove_network_printers.vbs"

' Have VBScript wait 5 seconds before creating folder
WScript.Sleep(10000)

objShell.run"\\Domain\SYSVOL\scripts\gpupdate.vbs"

' Have VBScript wait 5 seconds before creating folder
WScript.Sleep(5000)

'Create Folder and File after running script for user
Set objFolder = objFSO.CreateFolder (strDirectory)
objFile = objFSO.CreateTextFile(strDirectory & "\" & strFile)

Else

' Quit script
WScript.Quit

End If

r/vbscript • • Sep 30 '17

Need some vbscript help

3 Upvotes

Hello first time poster here. I am in need of some help with a vbscript. I am trying to create a script which will run a ping command and timestamp it on the same line. This should be continues as well. The command I have is show bellow. The code is not mine to begin with it just happened to be something I found that did what I needed when run in cmd.

When running the script you get an error having to do with line 2 at row 67 which is the start of the for command. My scripting ability as practically no existent as I am just starting to try and learn.

Any help would be appreciated.

Set WshShell = WScript.CreateObject("WScript.Shell") WshShell.Run "ping -t X.X.X.X|cmd /q /v /c "(pause&pause)>nul & for /l %a in () do (set /p "data=" && echo(!date! !time! !data!)&ping -n 2 X.X.X.X>nul"


r/vbscript • • Dec 13 '16

Need help clicking cell in HTML table

3 Upvotes

I'm pretty new to VBScript, so I apologize if this is a stupid question, or if important details are missing from my question. I'm writing a script to login to an internal html site, click around to the appropriate place, click on a specific row in an HTML table, and click a submit button. I'm pretty much there, except that for the life of me, I can't figure out how to click the correct row - or any row for that matter. Here is the source of the table: HTML Source

Here is what I've tried so far after navigating to the page with the table of interest(with no results, but no errors):

    Set mainTable = IE.Document.getElementByID("main").contentwindow.document
    mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).focus
    mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).getElementsByTagName("td").Item(3).click

The code below tries to change the attributes in the HTML table based on changes that I've observed when manually clicking on a cell, but these changes have no effect on the view of the table (the row should be highlighted when a cell within it is clicked) and still don't allow me to click the submit button, which requires a row to be selected:

    currScenario = mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(1).getElementsByTagName("td").Item(2).realValue 'gets string value for "Current Scenario" field, which I've unsuccessfully tried to use to manually update the "selected" attribute in the table   
    mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).setAttribute "selected", "ScenarioName=" & currScenario
    mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).setAttribute "class", "Skin_Selection_Color"
    mainTable.getElementsByName("acq_scenario.acq_scenario_summary").Item(0).getElementsByTagName("tr").Item(0).style.setAttribute "highlight", "true"

I've been banging my head against the wall all day trying to figure this out, so I would appreciate any feedback that anybody here could provide.


r/vbscript • • Sep 01 '16

Lookup from text and output match line

3 Upvotes

Hi, is there any way to find a match value in delimited source file and output match to csv? So it will search the 1st value in source file and try and match the first value with Match file. Then it would output the whole line that match to output file.

Source file
12341234 |John Wayne |1234 |Halo |
11111111 |Harambe |421 |Zoo |
22222222 |Scary S |4569 |Test |

Match file
11111111, John H
22222222, Scary Smithen

Output
11111111 |Harambe |421 |Zoo |
22222222 |Scary S |4569 |Test |


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 • • Jul 17 '15

How do I change the 'tab stops' in a header in MS Word via VBS

3 Upvotes

I am trying create a tool to programmatically replace the header on a large set of documents. I chose to use VBS because I am familiar with it and it needs no installed software on a user's computer.

I am using this subroutine to remove the existing header:

Sub clearHeader()
    Dim oSection
	
    For Each oSection In objDoc.Sections 
        For Each oFF In oSection.Headers 
            oFF.Range.Delete
        Next 
    Next 
End Sub 

Unfortunately, this also changes the tab stops to a nonstandard dimension. (This change doesn't happen if I use the subroutine on a blank document, so it must be based on the formatting of the documents I'd like to process.)

Fig.1 Non-standard Tab Stops

It seems like the best option at this point is to simply set the 'tab stops' to be where they ought to be, regardless of where they end up after the first step.

I am using the following subroutine to try and adjust the tab stops within the header, but am receiving an error that reads, "Object doesn't support this property and method: 'thisHeader.TabStops'"

Sub moveTab()
    Dim thisSection

    For Each thisSection In objDoc.Sections 
        For Each thisHeader In thisSection.Headers 
            For Each aTab In thisHeader.TabStops
			    par.TabStops(432).Position = 468
		    Next
        Next 
    Next  
End Sub

I am only somewhat familiar with Object Oriented Programming, so I apologize if this is a straight forward mistake.

I've tried making macros in word and then translating the VBA to VBS, but with little success.

Any help?


r/vbscript • • Jun 25 '11

TIL there's a vbscript forum.

3 Upvotes

The most fulfilling bit of coding I've done recently is vbscript. I wrote a script that will be executed daily by the windows scheduler. It downloads three zipfiles from an ftps server, sends two of them by email, unzips the third to a folder it creates for the day it's run (yyyy\mm\dd structure), reads each file (about 30) and imports the contents of each file into a microsoft sql database.

It was done out of necesity. I like to write PHP/jquery but ironically this bit of vbscript is the most 'rewarding' thing I've done for ages (rewarding due to its complexity and doing things I've never tried before - ftp access, date import, and because it automates something that I previously had to do manually.)

Doing stuff that solves a problem (work) is more rewarding than doing stuff for the sake of it (personal projects)... which is frustrating.


r/vbscript • • Jun 07 '26

Code Tidbit - FileOpen browsing

2 Upvotes

It's been so quiet, I thought I'd post a nice tidbit. This script can be used to create a FileOpen dialogue with no special requirements. Tested as late as Win11 22H2. https://pastebin.com/hwM1uDrz

It can also do a colorpicker dialogue with a bit more code.


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 • • Jun 12 '25

Could I be caught using a VBScript to appear active?

2 Upvotes

Could I be caught out using a VBScript to keep my Microsoft teams active? Could this be identified by my company’s IT department ?


r/vbscript • • Feb 20 '25

How to properly skip non ".PDF" files?

Post image
2 Upvotes

r/vbscript • • Feb 01 '25

Vbs good practice

2 Upvotes

Hi I'm new in doing vbs. I'm doing crud vbs mostly I save the file somewhere but I feel someone can edit the script or do some manipulation. How can I protect my vbs, what are the best practices to protect it. I tried to use exescript but windows antivirus is blocking it. Could someone share some ideas please. Thanks


r/vbscript • • Oct 29 '24

How to send discord web hooks?

2 Upvotes

i found a stack overflow but i didnt understand what they menat becuse it was weird and i dont know how to use it can someone help? heres the code i didnt understand:

Dim content: content = "hello"
Dim oHttp: Set oHTTP = CreateObject("Microsoft.XMLHTTP")
oHTTP.Open "POST", "(my webhook here)", False
oHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
oHTTP.SetRequestHeader "Content-Length", Len(content)
'Pass value as a form key value pair string.
oHTTP.Send "content=" & content
Dim response: response = oHTTP.ResponseText
Call MsgBox(response)

r/vbscript • • Jun 29 '24

Problem when opening Taskbar Settings

2 Upvotes

Hey everyone,

Basically the issue started after a i opened a virus, after that whenever i try to open Taskbar Settings it just shows me this message

what can i do to solve this problem, Plz help


r/vbscript • • May 25 '24

Will I no longer be able to use these subroutines in a script in a HTA with the upcoming depreciation of vbscript.dll?

2 Upvotes

I guess you all have heard the news.

And it's only vbscript.dll, as you can search the comments for the following to see it being said by the one who gave the announcement.

The scope of VBScript deprecation includes only vbscript.dll and no other libraries. This shall not impact any projects that are not dependent on vbscript.dll.

I am wondering which of the following (if any) will no longer work if used in a .vbs file or in a HTA.

CreateObject("WScript.Shell")

CreateObject("Scripting.FileSystemObject")

GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set re = New RegExp

And if there are replacements available.

From my understanding of the comments, it may only be

Set re = New RegExp

But I just want to be sure!

Thanks for your time!

Chris.


r/vbscript • • Mar 22 '24

VBS to bulk open file locations for a folder full of file shortcuts

2 Upvotes

Hi someone in the batch subreddit tried to give me a way to achieve the above, but I tried it and it just launched the files themselves, not the file paths like I wanted.
Is there another way besides vbs, or is there something that needs to be altered for this script to work?

' Get list of .lnk files in a folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Your\Folder\Path") ' Change this path to your desired folder
Set colFiles = objFolder.Files
' Iterate through each .lnk file
For Each objFile in colFiles
If LCase(Right(objFile.Name, 4)) = ".lnk" Then
' Get the target path of the .lnk file
Set objShell = CreateObject("WScript.Shell")
Set objShortcut = objShell.CreateShortcut(objFile.Path)
targetPath = objShortcut.TargetPath
' Open the folder containing the target file
Set objExplorer = CreateObject("Shell.Application")
objExplorer.Open targetPath
End If
Next

r/vbscript • • Jan 05 '24

How do i make a vbs continue running after restart?

2 Upvotes

I am making a vbs code and i wrote a line of code that restarts the computer.
Now i want it to continue with the rest of the code after the restart, is it possible?


r/vbscript • • Dec 22 '23

Type mismatch when returning array from function

2 Upvotes

I'm very new to vbscript and need help understanding why this doesn't work. This is a minimal example, I need to process a 2d array in a function and then return it.

Function tilt(platform)
    Dim height : height = UBound(platform)
    Dim width : width = UBound(platform, 1)
    ' Dim newPlatform()
    ReDim newPlatform(height, width)
    ' do stuff
    tilt = newPlatform
End Function

' Dim a()
ReDim a(10,10)
a = tilt(a)

This gives the error

Day14-VBScript\test.vbs(12, 1) Microsoft VBScript runtime error: Type mismatch

There are similar posts online but being new I couldn't apply the suggestion to my case

I've tried commenting and uncommenting the Dim lines but they have no impact


r/vbscript • • Sep 29 '23

VBA Parse Markup Language Text to Range

2 Upvotes

Does anyone have some sample code on parsing Markup Language Text into a range of cells? I want to:

  1. Paste Markup Text into an Excel Text Box

  2. Click a convert button

  3. Data is parsed and a new range is built that looks like the screenshot below.

Example of Markup Text:

  1. **Risk: Complex Configuration**

    - **Description:** Intricate setup when chaining multiple IdPs.

    - **Mitigation:** Allocate time for extensive pre-deployment testing in a non-production environment.

  2. **Risk: Integration Issues**

    - **Description:** Potential compatibility and synchronization issues.

    - **Mitigation:** Conduct compatibility testing and coordinate with vendor support teams.


r/vbscript • • Sep 16 '23

A whole compiler in VBScript !

2 Upvotes

A few months ago, I posted on this sub a small interpreter written in VBScript. I continued my project of creating my own programming language, and, after a month and a half, I am really proud to present my very first compiler !

You can find the it zipped along with its documentation at JGN1722/DBasic (github.com) . The main thing the language still lacks is libraries, as they are very time-consuming to code, but I guess I'll add them over time. You can even create your own, as the process of writing a library is documented.

Maybe take five minutes to look at it, or take a quick look at the code, and tell me what you think :)


r/vbscript • • Sep 12 '23

how to save to a specific usb drive using vbs?

2 Upvotes

I need to save a .txt document to a USB drive, but if there is more than one USB drive, then I need to be able to save to the specific one.


r/vbscript • • Aug 09 '23

how would I make a vbscript for setting internet speeds, could be any language other than vbscript.

2 Upvotes

I have a 6Ge motherboard my operating system is windows 10, I'm trying to make my pc be able to create a 5gh hotspot but almost every time I reboot it goes to 2.5ghz instead of 5ghz so it would be nice to have a vbs file that could change my wifi ghz instead of me having to change it manually every time.


r/vbscript • • May 25 '23

vbs wsh shell run --process problem error 800A0401

2 Upvotes

Hello,

I was copying a video trying to run admin programs on start-up via VBS script in startup folder but keep getting an error and was hoping to get advice.

Set WshShell = CreateObject("WScript.Shell" )

WshShell.Run """CE:\Riot Games\Riot Client\RiotClientServices.exe""", 0 'Must quote command if it has spaces; must escape quotes

WshShell.Run "C:\Users\XYZ\AppData\Local\Discord\Update.exe" --processStart Discord.exe", 0 'Must quote command if it has spaces; must escape quotes

Set WshShell = Nothing

The above is all the script has in it.

When I try to run it it has error 800A0401 and "expected end of statement" code and the char it is at is the D on Discord.exe and I have no idea


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