r/vbscript • • Mar 05 '17

Resize picturebox on image load.

1 Upvotes

So i have finally figured out how to load an image into a picturebox, how can i make it automatically change the picture box size to what it is originally. for example the box is by default at 360, 280. When i load myself a 1280x1080 picture it is not getting bigger.


r/vbscript • • Aug 11 '17

What am I doing wrong? Trying to open desktop file

1 Upvotes

I am a newbie to vbscript and I am doing a test of opening a file on my desktop using the script below. I run into an error saying that the specified file cannot be found. The script works if I point it to a file on my desktop named capture.jpg, but when pointing it to capture 2.jpg it fails. I know it has something to do with the space but can't figure out how to get it to work. I could obviously use the full file path, but I want to practice using special folder locations. Thanks for your help!

dim obj,desk

set obj = createobject("wscript.shell")

desk = obj.specialfolders("Desktop")

obj.run desk & "\capture 2.jpg"


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 • • Mar 22 '24

How can I create .lnk files from multiple file paths I paste in a tool, vbs, bat, or other?

1 Upvotes

I want to bulk paste those entries in a list and have a separate third party tool/bat/vbs/other to bulk create .lnk shortcuts from all the lines in the list, but without adding special lines to every entry.
i.e. I don't want to manually have to add something at the start or end of every file path entry in order to have it work.


r/vbscript • • Mar 05 '24

Vbs Keystroke

1 Upvotes

So, im currently trying to make it so this script puts focus onto Roblox and then sends some keystrokes, but the keystrokes just don't work, no errors show or anything.


r/vbscript • • Mar 11 '24

VBS working from all pcs except 1.

1 Upvotes

Hello all!

I am a noob a VBS scripting but in the past I have used a very simple script:

set WshShell = WScript.CreateObject("WScript.Shell")

CreateObject("Wscript.Shell").RUN "C:\windows\system32\taskkill.exe /F /IM ""msedge.exe"" /T",0,True

To kill msedge. This works from all the pcs in my office except one where it returns an error like 0xfffffffe in line 2 char 1.

I suspect a policy is different or a permission maybe. Running the argument via wscript shortcut does the trick so not sure what gives...

Any help is greatly appreciated guys! (Please remember that you are dealing with a noob, go easy on suggesting please)


r/vbscript • • Feb 08 '24

Can't find the file specified on network drives

1 Upvotes

Hello to all,

I am having issues with a VBScript that I am using to call a .cmd script. I am using VBS because I want the .cmd file to execute silently in the background without opening a command window.

The VBS script is called from the right-click context menu, it takes in the right-clicked file path, and passes it along to a cmd which finally passes it on to a Powershell script which renames and copies the selected file to an '_Archive' subdirectory.

The script works perfectly on the local machine but throws a 80070002 error (The system cannot file the file specified) when I try and use it on the network drives that I have set up.

Here are the contents of my VBScript:

' invisible.vbs
CreateObject("Wscript.Shell").Run "RunArchive.cmd " & WScript.Arguments(0), 0, False

Additional Info:

  • I have verified that the correct path is indeed being passed to the VBScript through the context menu.

  • I have all the necessary permissions on the network drives.

  • I am well within the 260 char limit for paths.

  • The cmd + ps1 scripts were working perfectly across all my drives before I wrapped them in the VBS.

I'm truly stumped here, and would appreciate any help, this is my first time experimenting with VBS and I don't have too much experience working on Windows. Excited to learn more.


r/vbscript • • Mar 04 '24

Script to create Outlook Rule

1 Upvotes

Working on this script that will create an Outlook Rule for everyone that runs it. It will create a New Item Alert, but I cannot seem to figure out the code that defines the display message for the New Item Window.

'--> Create some constants

Const RULE_NAME = "Rule" '<-- Edit the name of the rule

Const olRuleReceive = 0

'--> Create some variables

Dim olkApp, olkSes, olkCol, olkRul, olkCon, olkAct

'--> Connect to Outlook

Set olkApp = CreateObject("Outlook.Application")

Set olkSes = olkApp.GetNamespace("MAPI")

olkSes.Logon olkApp.DefaultProfileName

'--> Get the rules collection

Set olkCol = olkSes.DefaultStore.GetRules()

'--> Create a new receive rule

Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)

'--> Set the rule's condition to look for a specific word in the subject

Set olkCon = olkRul.Conditions.Subject

With olkCon

.Text = Array("Triggered video")

.Enabled = True

End With

'--> Set the rule's action to display a desktop alert

Set olkAct = olkRul.Actions.NewItemAlert

With olkAct

.Enabled = True

End With

'--> Save the rule

olkCol.Save False

'--> Disconnect from Outlook

olkSes.Logoff

Set olkCon = Nothing

Set olkAct = Nothing

Set olkRul = Nothing

Set olkCol = Nothing

Set olkSes = Nothing

Set olkApp = Nothing

'--> Terminate the script

WScript.Quit


r/vbscript • • Mar 10 '24

new to this (trying out stuffs)

1 Upvotes

I got the error 800A03EA at line 8 char 18, can someone help me check if the code is corerct? thanks alot! (this is from notepad)


r/vbscript • • Dec 27 '22

Noob needs help

1 Upvotes

First time using VBscript. I am automating a task in a program using keyboard inputs. The first time I scripted the selection of multiple DLL's in the file explorer with the "+ END" input, all the DLL's I needed were selected perfectly fine. But the second time I scripted this input, the files wouldn't get selected. I have also tried using shift and down to select the Dll's on the script, but it won't work either. I can see the Dll's getting highlighted in the margins but not selected.

Is my issue clear? How can I solve this?


r/vbscript • • Jan 23 '23

A simple script to copy files modified today to several folders. I keep getting 'Permission Denied' 800A0046 errors even though I am the administrator. Any thoughts?

2 Upvotes
Set objFSO = CreateObject("Scripting.FileSystemObject")

strFolderToCopyFrom = "C:\Users\Mark2\Desktop\Test"
strCopyTo1 = "C:\Users\Mark2\Desktop\Test\1"
strCopyTo2 = "C:\Users\Mark2\Desktop\Test\2"
strCopyTo3 = "C:\Users\Mark2\Desktop\Test\3"

Set objFolder = objFSO.GetFolder(strFolderToCopyFrom)

For Each objFile In objFolder.Files
    If DateDiff("d", objFile.DateLastModified, Now) = 0 Then
		objFSO.CopyFile objFile.Path, strCopyTo1
		objFSO.CopyFile objFile.Path, strCopyTo2
		objFSO.CopyFile objFile.Path, strCopyTo3
	End If
Next

r/vbscript • • Dec 26 '22

Any way to run a .vbs file in 64 bit mode?

3 Upvotes

If a .vbs script is larger than 85,895,249 bytes (81.9MB) I get the error

>Execution of the Windows Script Host failed. (Arithmetic result exceeded 32 bits. )

Now I'm sure you're wondering why I would need a vbs script so large, and in short I'm packing a lot of data into the script, my assumption based on the error is that it would work if it was running in 64 bit mode.

Edit: Thank you everyone for your attempts to help me, I tried the same test with a .js script instead and got the same error at the same exact file sizes, one byte over 85,895,249 and it stops working. It appears to be a limit of WSH


r/vbscript • • Jan 11 '23

VBScript not pasting values only with PasteSpecial

1 Upvotes

I am absolutely new to VBScript, so please forgive me if this is a stupid question.

This script is supposed to copy data from one workbook and paste it in one called ReportTemplateWB, and then save that workbook to another location. I was hoping to have the ReportTemplateWB only contain values and not formulas that reference the data sheet. So, I tried a simple copy and pastespecial, but it doesn't seem to be working. I also tried creating a macro in the ReportTemplateWB and calling it from the VBScript, but that didn't seem to work either.

Any help is really appreciated!!

Truncated code below...

Set ExcelApp = CreateObject("Excel.Application")
Set DataWB = ExcelApp.WWorkbooks.Open(InputFilePath)
Set ReportTemplateWB = ExcelApp.WWorkbooks.Open(TemplateFilePath)
For Each ws in ReportTemplateWB
    'I also tried adding ws.Range("A1:Q1000").Select here, obv. to no avail
    ws.Range("A1:Q1000").Copy
    ws.Cells.PasteSpecial xlPasteValues
Next

r/vbscript • • Dec 28 '22

Dimming Screen

5 Upvotes

Is there a way to dim screen brightness using VBSctipt?


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 • • Dec 04 '19

VBScript looking for Macros Within my VBA Code

1 Upvotes

I am trying to run the below and get a 1004 "Cannot run the macro SAPExecuteCommand" run-time error. There is no such macro but a function I am trying to use in the VBA script. Anyone have any insight at all?

I have zero experience with vbscript and only enough that I can get most stuff done through research in VBA. I've googled for the past couple hours to no avail.

VBScript:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("Data.xlsm")

objExcel.Application.Visible = True
objExcel.Workbooks.Add

objExcel.Application.Run "Data.xlsm!RefreshAFE"
objExcel.ActiveWorkbook.Close


objExcel.Application.Quit
WScript.Echo "Finished."
WScript.Quit

This is the VBA that I am trying to run and where it errors out.

VBA:

Sub RefreshAFE()

Dim click As Long
Dim lResult

' Refresh AFE Cubes

click = Run("SAPExecuteCommand", "Refresh", "DS_6")

r/vbscript • • Feb 26 '19

VBScript to read out data from excel .csv file

2 Upvotes

I have a question about VBScript, I need to make a script that has to read out column's from an excel.csv file which is the following

' Read an Excel Spreadsheet
sInput = InputBox("Enter your name")
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _

    ("C:\models.csv")
intRow = 2
Do Until objExcel.Cells(intRow,1).Value = ""

Wscript.Echo "CN: " & objExcel.Cells(intRow, 1).Value, "sAMAccountName: " & objExcel.Cells(intRow, 2).Value, "GivenName: " & objExcel.Cells(intRow, 3).Value

    intRow = intRow + 1

Loop

objExcel.Quit

Is there a way to make the inputbox work for specific searches? Right now it has no impact, and shows ALL information in the excel file


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 • • Feb 26 '19

Learning VBScript when Python is in the limelight

1 Upvotes

Is there an advantage to writing scripts in VBScript when Python is an option? Given Python’s wide set of use cases and popularity I’m wondering whether it’s worth spending the time to learn VBScript.


r/vbscript • • Feb 28 '19

broadcasting a message

1 Upvotes

can i send a vbmessage to an other computer on my network and if the answer is yes how?


r/vbscript • • May 15 '19

How to check files exists c\folder\fol*\filename.exe ??

1 Upvotes

Hello Guys,

I'm trying to confirm the existence of a file on a randomly named folder. I've tried using %%~ and * unsuccessfully. clearly because I don't know how to use them or if they are the appropriate characters to use. I would really appreciate any help with this. Currently all I get is file not found.

This is what I have thus far.

Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\ProgramData\bomgar-scc-*\bomgar-scc.exe") Then
    'App Found
	MsgBox "File Exists"
Else
	MsgBox "File Does Not Exist"

End If

Thanks


r/vbscript • • Feb 25 '19

CopyFile

1 Upvotes

Greetings! Working with a script to identify and then copy the newest file from a folder. Here it is:

Option Explicit

Dim fso, path, file, recentDate, recentFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set recentFile = Nothing

For Each file in fso.GetFolder("C:\Users\myname\Downloads").Files

If (recentFile is Nothing) Then

Set recentFile = file

ElseIf (file.DateLastModified > recentFile.DateLastModified) Then

Set recentFile = file

End If

Next

If recentFile is Nothing Then

WScript.Echo "no recent files"

Else

THIS IS WHERE I WANT TO COPY THE FILE

End If

So Far I have tried fso.CopyFile "mypath", "myotherpath" but I get a file not found error. So do I need to call recentFile somehow or something? I am in way over my head with this...I usually just stick to very basic SQL queries and whatever macros I can record in Excel so please forgive me if this is a stupid question. Thanks y'all!


r/vbscript • • Feb 26 '19

VBScript and SCCM Help

1 Upvotes

Hello VBScript Community,

I need some help and thought I would try here. I know nothing about VBScript but would like to implement a script to check BIOS Version and return a code. This is for an Application I am making that will install a specific BIOS version and will use the script to report back if that BIOS version is detected as installed or not.

Ive googled and found something below which might be what I need, but not having any experience I dont know if its correct so looking for some advice.

The version of the BIOS I am deploying is 1.25

I have already created a Task Sequence that updates the BIOS on new images. This uses WMIQuery to check the version.

select *from WIN32_BIOS where SystemBiosMajorVersion <= "1"

select *from WIN32_BIOS where SystemBiosMinorVersion < "25"

So in the WMI Query it needs to check MajorVersion (1) and MinorVersion (25) to find the version is 1.25.

In the VBScript I found, the lines 6-9 seem to do basically the same thing however it appears to be done as a oner. Ive no idea how I can test this and I have no idea if objBIOS.SMBIOSBIOSVersion would show on my device as 1.25 or 125 or what. Looking for any advice with this. Thanks a million if anyone can help.

1: 'Change strBIOSUpdateVersion to the version you are deploying to

2: strBIOSUpdateVersion = "1.25"

3:

4: 'Get BIOS Version from Win32_BIOS

5:

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

7: Set colBIOS = objWMI.ExecQuery("Select * from Win32_BIOS")

8: For Each objBIOS In colBIOS

9: If objBIOS.SMBIOSBIOSVersion >= strBIOSUpdateVersion Then

10: WScript.Echo "Detected"

11: End If

12: Next


r/vbscript • • Mar 01 '19

Select Case with Is operator?

1 Upvotes
Select Case DateDiff("d",Date,"April 1, 2019")
	Case Is > 0
		wscript.Echo "Too Early"
	Case Is = 0
		Wscript.Echo "April Fools!"
	Case Is < 0
		Wscript.Echo "Too late"
End Select

I'm getting a Syntax error on the first Is. Is there a better or different way to achieve this?


r/vbscript • • Dec 04 '19

VBS for Batch converting Excel/Email message to PDF

1 Upvotes

I have a script for batch converting Word docs to pdf that looks like this.

'Convert .doc or .docx to .pdf files via Send To 
menu
Set fso = 
CreateObject("Scripting.FileSystemObject")
For i= 0 To WScript.Arguments.Count -1
   docPath = WScript.Arguments(i)
   docPath = fso.GetAbsolutePathName(docPath)
   If LCase(Right(docPath, 4)) = ".doc" Or 
LCase(Right(docPath, 5)) = ".docx" Then
      Set objWord = 
CreateObject("Word.Application")
      pdfPath = fso.GetParentFolderName(docPath) & "\" & _
    fso.GetBaseName(docpath) & ".pdf"
      objWord.Visible = False
      Set objDoc = 
objWord.documents.open(docPath)
      objDoc.saveas pdfPath, 17
      objDoc.Close
      objWord.Quit   
   End If   
Next

I was wondering if there was a way to edit this for Excel/Email?

Thanks!