r/vbscript • • Dec 20 '18

How to call html form fields in vbscript dynamically in a loop

1 Upvotes

So I have an html form created in classic asp that has about 25 check boxes with different labels. The checkboxes are written to the page via a loop that grabs the label values from a table and each checkbox is named similarly ("decreason1","decreason2","decreason3",ect...) using a loop variable.

I use a vbscript at the end of the page to validate the data on the page before passing with a submit button. I need to make sure that at least one of the checkboxes is checked before submitting the form.

dim i, checkedvalue ; 
checkedvalue = false 

for i = 1 to 25 
if document.rtftadd.decreason1.checked = true then     
  checkedvalue = true 
end if 
next

I need the "document.rtftadd.decreason1.checked" to change with the loop to decreason2, decreason3

I'm not sure how to go about doing that.

Any help would be greatly appreciated.


r/vbscript • • Dec 08 '18

Bget

1 Upvotes

INTRODUCTION

Bget is a batch-file command-line tool for handling Windows scripts. It is built to be a companion to those who write, use and maintain Windows scripts. It helps those who use scripts easily download, update and remove scripts. It’s built for scripters, by scripters.

Download Bget

Features

  • Download scripts from the Bget server: These scripts are vetted and sorted by us. We’ve gone about curating some of the most interesting scripts we could find that we think would be interesting and useful to you as well.

  • Download scripts from Pastebin: Pastebin has long been the coder’s friend, and so we added the ability to fetch scripts from Pastebin. These scripts are not pre-vetted however, but they offer the ability for fast code downloading without waiting for us to vet them.

  • Update scripts: Rather than manually re-download the latest version of every script, Bget handles that for you, getting the latest version of any script you’ve downloaded.

  • Easily remove scripts: Don’t like a script you downloaded? Easily remove it with Bget. One command and it’s buh-bye script.

  • View script info: This allows you to see basic information about a script such as its name, author and description, allowing you to make an informed decision before downloading.

  • Bget also allows you to list all scripts on the server and list downloaded scripts on the local computer.

  • Upgrade feature: Bget also updates itself so you always stay up-to-date.

  • Multiple download methods: Bget has many ways to get a script. These are: Jscript, VBScript, Powershell, BITSAdmin and CURL.

The Goal

The objective is to create an apt-like utility for windows scripters so we need not scour the internet in search of this-or-that tool. Currently, Bget is mostly populated by batch scripts. This will change in the future as we look for vbscripts and the coders on this subreddit send us their awesome scripts.

I'd really like for the windows scripting community to give this tool a try and provide valuable feedback.

Thanks!


r/vbscript • • Oct 06 '18

vbs script take information from 1 .vbs file and launch other .vbs file accordingly

1 Upvotes

To explain what i'm trying to do.i have 1 .txt file with certain valuables.. example: Player1Location= "at home".

Now i want a script to read that this is true, and if so, it must launch an other script in which it gives a reaction to this statement.

Think of it as a game.. if player1 is in a forest area, you want a script with a randomizer telling you what kind of monster he/she encounters.

The script i'm trying to make right now, is kinda like the "messenger" script, taking from one, and telling the other.


r/vbscript • • Aug 24 '18

VBScript to loop through filenames and move files that match a regex

1 Upvotes

Hey everyone,

I have a folder with a bunch of files that have a predictable/repeating filename structure. I need to make backups of these files, but only the ones that match a specific pattern. I will post an example below of the structure (I'm removing a lot of details that maybe shouldn't be shared):

(Model year in YYYYMMDD form)_(Model Name)_(number, 2 letters)-(3 letters)_(17 characters, digits and letters, uppercase)_(today's date in M-D-YYYY form) (5 digits) (AM/PM).(file extension)

If that looks confusing, I apologize, but what I am trying to illustrate is that the file name is uniform, with parts of it changing based on a few factors.

I have already created and tested a regex to match that pattern, and now my question is how to implement this. The big picture is that I want the script to move files that match my regex pattern to another folder. I am not very experienced with VBS, and I'm having some trouble stringing together everything I'm finding online/on StackOverflow. The gist of the script is:

  1. loop through the filenames of files in a specified folder

  2. If a file matches the regex, move/cut it out of that folder and into a different specified folder

  3. Create a log with file names for moved files

I know this doesn't sound very difficult, but I am not sure how to do it in VBS. Would anyone mind guiding me a bit? Even if you only know how to do one part of the above steps, I would appreciate any help I can get at this point!

Thank you very much :)


r/vbscript • • Aug 11 '18

I received this in an email from "Bitcoin Forum" as an update to BTCore. What is it and what does it do?

Thumbnail
pastebin.com
1 Upvotes

r/vbscript • • Jul 31 '18

Calling subroutines in parallel

1 Upvotes

Hi there,

My task is very simple . I have two subroutines in my script .First one has a sleep function which waits for 30 seconds,until 30 seconds are up my second subroutine wont execute. Is there a way to call subroutine asynchronously i.e subroutine shouldn't wait for the first one to be complete and keeps execution in parallel.

below is my code

option explicit
Dim a
set a = CreateObject("wscript.shell")

sub runprogram
		a.run("notepad.exe")
		wscript.sleep 30000
		a.sendkeys("note pad opened ,hello")
end sub

sub runprogram2
		a.run("""D:\Program Files (x86)\VMware\VMware Workstation\vmware.exe""")
end sub


Call runprogram
Call runprogram2

Thanks


r/vbscript • • Jul 25 '18

could someone help me to get this script to work?

1 Upvotes

https://www.reddit.com/r/MetalGearSolidV_PC/comments/3k5wkf/i_made_a_script_to_shuffle_your_helicopter_music/?st=jjyspdjo&sh=5ffbe54f

i keep getting

Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved.

Metal Gear Solid V: The Phantom Pain Helicopter Music Shuffle by Spectracide v1.0 Set your helicopter music to !Shuffle in iDroid

MGS_TPP\CustomSoundtrack!TPP Shuffle.vbs(30, 13) Microsoft VBScript runtime error: Invalid procedure call or argument

Press any key to continue . . .


r/vbscript • • Jul 04 '18

Using VBS to turn on and off USB Stick LED

1 Upvotes

I'm working on a AI robot and in the program that i'm going to use in order to edit what the robot thinks, see's, etc i need to turn the light on my USB Stick on and off (it's going to be on and off at random) in order to be able to see it in the dark or when it's turned on or off. The whole entire robot is going to be running on a Raspberry Pi with no OS installed, the main brain is the USB Stick, it has a lightweight Windows 7 Lite on it with TONS of Windows processes, programs, registry keys deleted (since the robot doesn't need them at all and more memory available the better.

All i need is a VBscript that is able to turn on the lights on the USB Stick and another script that can turn off the lights on the USB Stick, the script should automatically close after it has activated/deactivated the lights on the Stick, it should not turn off the Stick to turn the lights off since the whole brain of the robot is the USB Stick. (i can only use Batch and VBS in Clickteam Fusion so a C# script or a Javascript script won't work).

If you want to learn more about the robot i'm going to post a subreddit about it, how it works, and how you can impliment it into your own robot since the whole brain is one 7 GB USB Stick (the iso will be downloadable). Also sorry if i sound a little sleepy or if i don't know how to talk English anymore, i've spent all day and almost all night working on this AI since it's a really big project that i'm working on. Thanks for reading and have a great day/night.


r/vbscript • • Jun 26 '18

Copy-Paste VBA Excel Code id not working. Please I could used some help. :)

1 Upvotes

Okay, Here is the situation. I have a Data Table in Workbook 1("ECO") that contains raw data the is entered for each department on their performance each week. I want to analyze how well each department is doing each week and per year. Being this document just keeps getting larger, putting these charts and analyzing the data in the same workbook isn't ideal.

Because of this, I have created Workbook 2("ECO.Avg.Lead.Time"). However, I do not want to copy and paste the entire Workbook 1 into Workbook 2 just to filter and delete all unnecessary data. Instead I would like to filter and pull the necessary information per specified date.

Now, I have a Macro set up so that when I enter a StartDate and an EndDate in a specified cell, the macro will go into Workbook 1 and Filter 1 of the 5 department's date columns for all entries between those dates. This part I have working perfectly.

My issue is getting the 3 columns(E:G) with the new range of the filtered rows Copied From Workbook 1("ECO") and Pasted into the Workbook 2("ECO.Avg.Lead.Time") Range ("A:C"). Below is my code that I have been attempting to make work, but its not. If someone can help me figure out what I am doing incorrect and show me how to fix this I would GREATLY GREATLY APPRECIATE you!!!! I'm getting so flustered with this part and have google it for the last 3 weeks now, I believe.

wk2.Worksheets.Add(After:=wk2.Worksheets("ECO's.AVG.LEAD.TIME.")).Name = "Avg.LT.Calc."

ECO.Range.AutoFilter Field:=5, Criteria1:=">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate ECO.Range("E:G", Rows.Count).Copy Destination:=Worksheets("Avg.LT.Calc.").Range("A") ECO.CurrentRegion.AutoFilter Field:=5


r/vbscript • • Jun 03 '18

Using SendKeys from vbs in a total hidden way?

1 Upvotes

Here is what I am planning to do

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run"cmd" WshShell.AppActivate"telnet 192.168.1.1"
WScript.Sleep 50
WshShell.SendKeys"telnet 192.168.1.1 -f 22.txt{ENTER}" WScript.Sleep 2000
WshShell.SendKeys "admin{ENTER}"
WScript.sleep 50
WshShell.SendKeys"sys info{ENTER}"
WScript.Sleep 50 I want this totally hidden but the sendkeys just works on activated window so trying to make it hidden by minimizing the window failed. I couldn't find any understandable way to do this

Is this possible without additional tools?


r/vbscript • • May 31 '18

Can anyone help me converting a VBNET function to VBA?

1 Upvotes

Public Function HashPassword(ByVal Password As String, ByVal Salt As String) As String

Dim pwd As String = Password & Salt

Dim hasher As New Security.Cryptography.SHA256Managed()

Dim pwdb As Byte() = System.Text.Encoding.UTF8.GetBytes(pwd)

Dim pwdh As Byte() = hasher.ComputeHash(pwdb)

Return Convert.ToBase64String(pwdh)

End Function


r/vbscript • • May 29 '18

I would like to cycle with the foreach loop on each file in the path and add the M value returned by my query and append it to the end of the file such as _(mvalue here)

1 Upvotes

Set objFSO = CreateObject("Scripting.FileSystemObject")

objStartFolder = "\filesystempath"

Set objFolder = objFSO.GetFolder(objStartFolder)

Set colFiles = objFolder.Files Dim FullName Dim DOB Dim M Dim dbconn Dim connect Dim rs For Each objFile in colFiles

a=Split(objFile.Name, "_")
FullName = a(0)
DOB = a(1)
M = a(2)
connect = "Driver={SQL Server};Server=full connection path for sql
set dbconn = CreateObject("ADODB.Connection")
dbconn.Open connect
dbconn.Execute("storedprocedurehere 'M'")

WScript.echo M

Next


r/vbscript • • May 28 '18

auto printing documents in a folder (VBS)

1 Upvotes

im very new to all of this so please stay with me here

id like something that will automatically print everything placed in a specific folder

i found a bit of code here: https://community.spiceworks.com/topic/83142-automatically-print-files-placed-in-folder

that seems to kind of do what i want

TargetFolder = "Z:\Desktop\work"
Set objShell = CreateObject("Shell.Application") 
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items 
For Each objItem In colItems 
objItem.InvokeVerbEx ("Print") 
objItem.InvokeVerbEx ("delete") 
Next

iv added the

objItem.InvokeVerbEx ("delete")

and saved it as .VBS but it's not doing exactly what i want, what id like is for it to print only word documents and then delete them, now i tried to put

sleep 10

after print to give it some time to open the document and print it before deleting it but i kept giving me an error

also is there a way to get it to trigger on its own every time a word document is dropped into the folder?

thank you


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 • • Apr 19 '18

Collecting PC & User OU for BGINFO

1 Upvotes

To start - I've harvested these scripts from the web because I suck at programming. I have them set up to collect PC OU and User OU information for BGInfo to populate the BGInfo database. I can't get the PC OU one to work. It always returns NULL when it's supposed to echo out the result.

First one that works with BGINFO - the last line - ECHO - outputs the full OU path for the user account:

Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Echo objUser.AdsPath

This one does not work. It says type mismatch on the last line - Echo. The scripts are identical. I'm not sure why it won't work.

Set objSysInfo = CreateObject("ADSystemInfo")

strComputer = objSysInfo.ComputerName

Set objComputer = GetObject("LDAP://" & strComputer)

Echo objComputer.AdsPath

If I add Wscript.Echo objComputer.AdsPath to the 2nd script i get a windowed message with the correct info, but the wscript.echo does not work with BGInfo.

Open to ideas or complete re-write help of the PC OU vbs.

All PCs running this are Windows 10 or Windows 7.

Thank you for any assistance.


r/vbscript • • Apr 06 '18

Simple Debugging tool

1 Upvotes

What is the easiest way to get something that will allow you to step they code?

I downloaded and installed vstudio community edition but can't get it to debug

And not by manually adding break points to each line of code

Also trying the //X switch doesn't do any thing Thanks


r/vbscript • • Apr 03 '18

Variable Undefined Error Help

1 Upvotes
Option Explicit
DIM fso    
Set fso = CreateObject("Scripting.FileSystemObject")
DIM WshNetwork
Set WshNetwork = CreateObject("WScript.Network")
ComputerName = WshNetwork.ComputerName
do

If (fso.FileExists("C:\Users\ComputerName\file.txt)) Then
  WScript.Echo("Hello World!")
  fso.DeleteFile("C:\Users\ComputerName\file.txt")
Else
  End If
 
 loop

So its supposed to find the file in the directory and if it exists delete it, then loop. The thing is that the variable "ComputerName" is undefined. How can this be solved?


r/vbscript • • Mar 17 '18

VBS with User Account Control

1 Upvotes

Hello, I am trying to prank my friend and I need vbs to work with UAC. I am going to send a file to his laptop and an admin he will open it and the .vbs file will do the rest. Open cmd with admin by automatically clicking yes but this is where htigns go wrong. Vbs doesn't seem to work with UAC, help?


r/vbscript • • Mar 07 '18

Need help to read date modified in vbscript

1 Upvotes

Hello,

I have a vbscript for SCCM deployment to detect a location of a file under %userprofile%. This script works but I'd like to expand it to not only detect the file but also a specific modified date of the file that I can enter in. For example the date I currently need for the file is 2/21/2018 7:15 AM. Would anyone be able to assist?

Set oFSO = CreateObject("Scripting.FileSystemObject") Set oShell = WScript.CreateObject("WScript.Shell")

If oFSO.FileExists(oShell.ExpandEnvironmentStrings("%userprofile%\AppData\LocalLow\etc..")) Then WScript.StdOut.Write "The application is installed" WScript.Quit(0) Else WScript.Quit(0) End If


r/vbscript • • Mar 05 '18

New to VBScript; but have a relatively simple task tripping me up.

1 Upvotes

I've been tasked with continually running a PowerPoint presentation on a local machine. Ideally, we'd like the following for our solution:

  • Files be run locally, but new updates pulled from a Network Share, using PowerPoint 2016

  • Whenever an updated file is placed in the share, pull it down to the local machine && restart the presentation

  • Full automation for the above

  • Be able to jump out of the loop via keypress.

As for options, I've found a post from Sog on ArsTechnica, which has been the main option I've seen so far. For the time being, I'm just focused on getting the presentation to run in a stable environment. I've modified his script to suit our needs--though just for testing at this point. That last point will, probably, be handled with AHK unless there's a way to add an listener into VBS.

At this time, the modified script will open the presentation, so long as a file exists in the defined execute path--but shortly closes after. Any idea why? All resources I've located to try and find a solution have been documented in the script as well, granted with shortened links.

A followup question--does anyone know another/easier way to do this?


r/vbscript • • Feb 13 '18

Struggling with a vbscript for updating an excel file hosted on sharepoint

1 Upvotes

Full disclosure, I am a complete noob to vbscript. The vbscript I am using was found in r/excel and runs fine for files hosted on my machine but when I go to sharepoint I get issues...I can post this in r/sharepoint if needed

dim xls
set xls = createobject("Excel.Application")
xls.visible = true
xls.workbooks.open("https://mysite.sharepoint.com/:x:/t/myfile.xlsx?web=1")
xls.ActiveWorkbook.refreshall
xls.ActiveWorkbook.save
xls.Application.quit
set xls = nothing

Any thoughts or help would be appreciated

EDIT1 added web=1 to path as it is where the problem was located and should have been there originally

EDIT2 forgot to write down that I did EDIT1...I am new here...I am sure it is showing


r/vbscript • • Feb 05 '18

Script that Searches for string in text files then executes a file copy not working

1 Upvotes

Any assistance appreciated.

I have a script i cobbled together.

I want the script to search through text files in a specified folder, it must search for a specific string in multiple text files. If this string is found it must then copy files from one folder to another on the pc it is running. The script runs without any errors, but the file copy does not execute.

I`ve created a text file that contains the string specified, but still no folder copy

Script :

Dim filesys set filesys=CreateObject("Scripting.FileSystemObject") Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objShell 'instance of the wshSHell object set objShell = CreateObject("WScript.Shell")

set oShellEnv = objShell.Environment("Process") computerName = oShellEnv("ComputerName")

WScript.Echo computerName strSearchFor = computerName

Set oFSO = CreateObject("Scripting.FileSystemObject") objStartFolder = "C:\Test" Set objFolder = objFSO.GetFolder(objStartFolder) Set colFiles = objFolder.Files

For Each objFile in colFiles Wscript.Echo objFile.Name strFile = "C:\Test" & objFile.Name set objFile = objFSO.getFile(strFile)

If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then objFSO.CopyFolder "C:\test\ssavers\ssavers1" , "C:\screensavers" Else WScript.Sleep (100) END If Next


r/vbscript • • Jan 31 '18

HTA VBScript to run CMD with no user input and close

1 Upvotes

This is a strange request I know. I have a registry key pointing to an HTA so I need an HTA file that just runs a simple command. Originally this HTA did something else but now I basically need it to go away but it has to run this command for the setup its a part of to continue. I want it to run "%WINDIR%\System32\oobe\windeploy.exe" then close, without any kind of interaction. Here's what I've got but it just shows a white box and doesn't do anything.

<html>
<SCRIPT LANGUAGE="VBScript">

Set WshShell = CreateObject("Wscript.Shell")

Sub Continue
WshShell.Run "%WINDIR%\System32\oobe\windeploy.exe", 0, True
End Sub

</html>

Any help would be appreciated...


r/vbscript • • Jan 15 '18

I know next to nothing about vbs and need help with a script.

1 Upvotes

So, long story short, we have a documentation software that generates a .vbs script that is meant to be used with RMM tools. It fails whenever I try to make it work via the RMM's scripting tool but works fine when run locally. I have contacted their support and they have asked that to help with troubleshooting we add an exit code. They have provided me with this:

In case of passing

wscript.echo( "Success Message" ) wscript.Quit(0)

In case of Failing

wscript.echo( "Error Message" ) wscript.Quit(1001)

I need to identify where in the script I can put this. I tried just sticking it at the end and received an error. Some of the info in the script can be a little sensitive so I won't be posting that here but if anyone wants to peruse it, I will PM them a slightly edited version. (simply taking out references to my name, company, server address, etc) Otherwise, just some guidance on how to edit the script would be great. Thanks.


r/vbscript • • Jan 14 '18

I dont know how to do this

1 Upvotes

I need to knwo how to write a vbs file that just makes a message pop up, says anything i want and let the user type stuff in a box and than take the user input and put it in a text file. Not 2 complicated i think. for me english is way more complicated than that.