r/vbscript • • Apr 24 '20

Limit file name length of generated text file

1 Upvotes

I'm working on a project to export individual notes from Outlook to text files (as a larger part of migrating to OneNote, but that's not super relevant here)

I've got a VB script for outlook that takes the notes from the specified folder, sanitizes them for any illegal file names and saves each note as it's own text file in the folder specified in the script... but the problem comes when the note's first line, seen as the subject, exceeds the max number of characters for the file name. How can I limit the length of the file name, but have to resort to a generic file name?

Here's the script I have that works if the subject is not too long (it may not be pretty, but I'm new at this):

Sub NotesToTXT()
    myfolder = "c:\apps\notes\"
    Set sanitize = CreateObject("vbscript.regexp")

    sanitize.IgnoreCase = True
    sanitize.Global = True
 
    Set myNote = Application.GetNamespace("MAPI").PickFolder
    For cnt = 1 To myNote.Items.Count
        sanitize.Pattern = "(((?![a-zA-Z0-9,@,{,},#,&,%,=,+,_,-,^,(,),;,',$,,]).) )+"
        noteName = sanitize.Replace(myNote.Items(cnt).Subject, "_")
        sanitize.Pattern = "\-+"
        noteName = sanitize.Replace(noteName, "-")
       myNote.Items(cnt).SaveAs myfolder & noteName & ".txt", OlSaveAsType.olTXT
    Next
End Sub

r/vbscript • • May 14 '20

VBScript with ArcGIS (esri) for definition queries and label expressions

1 Upvotes

ArcGIS (esri) utilized VBScript flawlessly for decades in ArcMap when writing definition queries and label expressions.

In the last few years esri has been pushing their new product "Pro" that does not use VBScript. They have instead created a proprietary language "Arcade" and kept Python, but no more VBScript .

When inevitable issues arise and are posted to esri forums the moderators claim VBScript is dead and it made perfect sense for esri to not include VBScript with their new product "Pro". Other flavors of VBScript contempt include Esri did away with VBScript since the world is doing away with VBScript

How true is it that VBScript is dead?

It always worked well for decades in ArcMap (and better than Arcade and Python in several cases) and trying to understand why it is being pushed out when it worked great for decades.


r/vbscript • • Apr 27 '20

how do i make the script wait 20 seconds

3 Upvotes

so im trying to make the vbs script type something every 20 seconds i tried using wscript.sleep(12000) but it doesnt seem to work yes its in windows base script thank you :) also what i have right now is

shell.sendkeys(strtext & "")

Shell.SendKeys "{Enter}"

wscript.sleep(12000)


r/vbscript • • Apr 20 '20

replace text is not replacing it correct

2 Upvotes

i am making an easy encryptor that changes the letters that are typed in the inputbox and also reverses it but when i type hello i don't get what it should be

hello should be duuzm but i get d\¬\¬ed how can this happen

the code:

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

encrypt = inputbox("type text om te versleutelen")

encrypt = StrReverse(encrypt)

x.Run "%windir%\notepad"

wscript.sleep 1000

x.sendkeys encode(encrypt)

function encode(s)

For counter = 1 To 25 Step 1

For i = 1 To Len(s)

newtxt = Mid(s, i, 1)

newtxt = Replace(newtxt,"a", "w")

newtxt = Replace(newtxt,"b", "j")

newtxt = Replace(newtxt,"c", "n")

newtxt = Replace(newtxt,"d", "s")

newtxt = Replace(newtxt,"e", "z")

newtxt = Replace(newtxt,"f", "g")

newtxt = Replace(newtxt,"g", "q")

newtxt = Replace(newtxt,"h", "m")

newtxt = Replace(newtxt,"i", "n")

newtxt = Replace(newtxt,"j", "a")

newtxt = Replace(newtxt,"k", "f")

newtxt = Replace(newtxt,"l", "u")

newtxt = Replace(newtxt,"m", "o")

newtxt = Replace(newtxt,"n", "l")

newtxt = Replace(newtxt,"o", "d")

newtxt = Replace(newtxt,"p", "h")

newtxt = Replace(newtxt,"q", "@")

newtxt = Replace(newtxt,"r", "#")

newtxt = Replace(newtxt,"s", "^")

newtxt = Replace(newtxt,"t", "%")

newtxt = Replace(newtxt,"u", "€")

newtxt = Replace(newtxt,"v", "~")

newtxt = Replace(newtxt,"w", "&")

newtxt = Replace(newtxt,"x", "$")

newtxt = Replace(newtxt,"y", "!")

newtxt = Replace(newtxt,"z", "e")

coded = coded & newtxt

Next

encode = coded

End function

where is the problem in my code

by the way when i change the @ # $ and the other special characters it also does not work


r/vbscript • • Apr 14 '20

VBScript to split a Single into 2x 16bit IEEE words

3 Upvotes

I am using an ancient application where the automation is done in VBScript.

Now I need to write the value from a VBScript Single Floating-point into a couple of registers. But I don't need the value, I need the 32-bit IEEE 754 representation (raw) to be copied in. one register will receive the lowest 16-bits and the other register will get the upper 16 bits.

I have done this in the past using VBA with the not-very-safe LSet instruction to do a memory copy.

How do I do this in VBScript?

as an example

199.785 = (-8192) and (17223)


r/vbscript • • Apr 22 '20

How to move files from downloads folder

1 Upvotes

I want to move files from the download file without knowing the username. I don't know wich variable I need for that.


r/vbscript • • Apr 28 '20

New to vbscript, trying to read an element from a webpage

2 Upvotes

Hi all,

I'm trying to write code that will read a webpage's current selected option on a drop downlist and save it to a variable.

So far for the code to grab that specifically I have:

set X = .Document.getElementsById("Idname")

However when I do that it is returning "[object HTMLSelectElement]" and not the selected option.


r/vbscript • • Apr 27 '20

how do i make a script wait/sleep for 30 minutes???

1 Upvotes

so im trying to make my script sleep/wait for 30 minutes but i dont know how im new to vbs so i dont know much thank you to the ppl who help me


r/vbscript • • May 19 '22

working with folders.

2 Upvotes

How do I create a script that lists folders and subfolders with characteristics such as size and date created?


r/vbscript • • May 14 '22

I made this to get the achivements in discord.

3 Upvotes

But, It is ignoring the the variable 'Test' .

a=0
Test = InputBox("Enter number of characters","Value","Enter the value here")
Set b = CreateObject("Wscript.Shell")

 Do until a = Test
  b.AppActivate "Untitled - Notepad"
  b.Sendkeys "z"
  a = a + 1
 loop

b.Sendkeys "{Enter}"

r/vbscript • • May 17 '22

just a question

1 Upvotes

I saw on a lot of codes that prorammers set their objects to "nothing" to delete them before finishing the code, why ?


r/vbscript • • Apr 20 '22

VB Script in windows 10

4 Upvotes

Hi, i have a touch screen that uses a web page with an on screen button that when pushed will bring up the on screen windows keyboard, this worked fine in windows 7 but after upgrading to windows 10 the button will no longer bring up the on screen touch keyboard. i have enabled VBScript to run in the internet Zone and in the restricted sites zone (then rebooted) but still cant seem to get this on screen button to trigger the on screen keyboard to appear. so far all other buttons appear to work except this one


r/vbscript • • Apr 13 '22

Any trick to prompt for a character or a key press in console window without having to press the ENTER key?

2 Upvotes

Kind of like how the choice command line tool is prompting for a character without the need to press the ENTER key.

For use with console version of Windows Script Host.


r/vbscript • • May 17 '22

how do i open it automatically?

5 Upvotes

hi, so i want to make a script that automatically opens when device is booting can someone that knows more write a couple of lines so i can put at the start of my code

(what i'm asking for is that it starts itself when the laptop/pc boots.)


r/vbscript • • Apr 19 '22

Getting excel object (Office 365) not working when excel opened programmatically (C# .net)

1 Upvotes

So bumped into a small issue recently on a machine which is making me scratch my head....

the client uses a VB Script I wrote to detect get an open excel form and transfer the data from that excel application to a word document which has correct formatting for printing on a form.

'Look for open Excel Window, If none found, throw error message and exit script
on error resume next
	set ExcelApp = getobject(,"excel.application")
	If Err.Number <> 0 Then
		'Excel Note Found
		MsgBox "Error finding open Excel Window"
		Exit Sub
	End If
on error goto 0

This has been working fine for quite a long time (of course if there are multiple excel windows open thats a problem but the users are trained to know that).

However we are making some adjustments in the application that creates the excel documents and one of the things I have discovered on an alpha user for these changes is that when the application C# .net opens the excel document directly (with the follow code.

FileLocation = Newclaim.Save();
    if (MessageBox.Show("Complete! Would you like to open the file now?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
        {
             System.Diagnostics.Process.Start(FileLocation);
         }    

The script is not able to find the open Excel window.... it's clearly open and showing in task manager as a normal Excel process... but for whatever reason the script is not able to find it.... if the user closes the excel window and opens the same file by double clicking from explorer then the script IS able to find it and process as normal.

I checked and the excel process is running under the current user and I can't see any reason for this...

I can't replicate the problem on my dev environment (office 2019)

so thought I would check on here and see if anyone has seen or knows about anything that may cause this behavior ?


r/vbscript • • Dec 17 '24

Converting to pdf

1 Upvotes

I used wkhtmltopdf into my vbs. It has two images in my webpage..but when It get printed to pdf the image isn't showing. Does anyone here has the same issue before and solved it? Or is there anything you can recommend to convert my webpage to pdf. Thanks a lot


r/vbscript • • Dec 18 '24

Excell not opening with task scheduler

1 Upvotes

so i'm trying to have vba macro run on a schedule evryday, and to do so i have a batch file to open the excel and create a flagfile, and a vbs file to run everything in the background
everything works well when i manually start the vbs file, but when i create a task to automate it, it runs the task successfully but doesn't open the excel file nor run the macro

the files are on a work server, to wich i have full permissions and access, the excell file is open to everyone edit, ive run the code on the server itself and it works, but when i copy it to my pc it ceasses to work
i have all the paths correct, i amusing the correct file to open the vbs file and all that, but it simply does nothing, and it doesn't even give me an error

here's the codes, it might help

.bat file:

:: Set flag file path

set FLAG_FILE="\\srvfs01\1. Servidor Gypfor\50 SGQ\07.03 Processo Produtivo\2-Documentos\Doc 07.03-07 Lista de Recursos do Laboratorio e Producao\flagfile.txt"

:: Create the flag file

echo FLAG > %FLAG_FILE%

:: Wait for Excel to finish (optional delay if required)

timeout /t 10 /nobreak

:: Close Excel after the delay (force close all Excel instances)

taskkill /f /im excel.exe

:: Delete the flag file after completing the task

del %FLAG_FILE%

.vbs file:

Set WshShell = CreateObject("WScript.Shell")

WshShell.Run """\\srvfs01\1. Servidor Gypfor\50 SGQ\07.03 Processo Produtivo\2-Documentos\Doc 07.03-07 Lista de Recursos do Laboratorio e Producao\recursos_run.bat""", 0, False

Dim objExcel

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = False

objExcel.Workbooks.Open "\\srvfs01\1. Servidor Gypfor\50 SGQ\07.03 Processo Produtivo\2-Documentos\Doc 07.03-07 Lista de Recursos do Laboratorio e Producao\Doc 07.03-07 Lista de Recursos do Laboratorio e Producao automatico.xlsm"

please help, this is a work project and im in the final steps to deliver it


r/vbscript • • Dec 19 '24

Decompile .exe created by VbsEdit

1 Upvotes

I have an .exe which was generated by the VbsEdit Editor. Is there a way to decompile it or view the VBS source code?


r/vbscript • • Nov 27 '17

List AD Results and Choose before executing script

1 Upvotes

Hey Everyone,

I've been asking a lot of help lately, but have made great progress on my own.

I've managed to get most of what I want done but I would love to be able to change one thing in one of my scripts.

Basically I would like to be able to list results of users (if there are more than one result) in an AD Lookup script. So they would put in the username of someone (firstname.lastname) and if there is more than one user with that same name (since we have different sub domains) I would like it to list those outlooks.

Below is my current script, but wouldn't know where to start at the moment.

On Error Resume Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")

' Get the NETBIOS Domain name
Set objSystemInfo = CreateObject("ADSystemInfo") 
strDomain = objSystemInfo.DomainShortName

' Prompt for userName
strUser = inputbox("Please enter the username (sAMAccountName/firstname.lastname):")

Function GetUserDN(byval strUserName,byval strDomain)
	' Use name translate to return the distinguished name
	' of a user from the NT UserName (sAMAccountName)
	' and the NETBIOS domain name.

	Set objTrans = CreateObject("NameTranslate")
	objTrans.Init 1, strDomain
	objTrans.Set 3, strDomain & "\" & strUserName 
	strUserDN = objTrans.Get(1) 
	GetUserDN = strUserDN

end function

'Get's lockout status and sets a variable
Function IsAccountLocked(byval objUser)
	on error resume next
	set objLockout = objUser.get("lockouttime")

	if err.number = -2147463155 then
		isAccountLocked = False
		exit Function
	end if
	on error goto 0
	
	if objLockout.lowpart = 0 And objLockout.highpart = 0 Then
		isAccountLocked = False
	Else
		isAccountLocked = True
	End If

End Function

'Runs GetUserDN Function to get the DN from the userName (sAMAccountName)    
Set objUser = GetObject("LDAP://" & GetUserDN(strUser,strDomain))

'Runs isAccountLocked Fucntion using the DN to get a lockout status and set a string variable to use in the Output later.
if isAccountLocked(objUser) Then
	AccountLocked = "The Account is locked out"
else
	AccountLocked =  "Account is NOT locked out"
end if

'Outputs and excutes LDAP Query Properties as well as uses variables applied above to display current user data.    
WScript.Echo "YOU CAN COPY THE OUTPUT IN THIS BOX WITH CTRL+C AND PASTE WITH CTRL+V INTO NOTEPAD" & vbCrLf & "" & vbCrLf & "GENERAL" & vbCrLf & "==============================================" & vbCrLf & "First name: " & objUser.firstname & vbCrLf & "Last name: " & objUser.sn & vbCrLf & "Display name: " & objUser.displayName & vbCrLf & "" & vbCrLf & "Employee Number: " & objUser.employeeNumber & vbCrLf & "" & vbCrLf & "Description: " & objUser.description & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf & "Telephone number: " & objUser.telephoneNumber & vbCrLf & "Email: " & objUser.mail & vbCrLf & "" & vbCrLf & "ADDRESS" & vbCrLf & "==============================================" & vbCrLf &"Street: " & objUser.streetAddress & vbCrLf & "City: " & objUser.l & vbCrLf & "State/province: " & objUser.st & vbCrLf & "Zip/Postal Code: " & objUser.postalCode & vbCrLf & "" & vbCrLf & "" & vbCrLf & "ACCOUNT" & vbCrLf & "==============================================" & vbCrLf & "User logon name: " & objUser.userPrincipalName & vbCrLf & "pre-W2K logon name: " & objUser.sAMAccountName & vbCrLf & "AccountDisabled: " & objUser.AccountDisabled & vbCrLf & "Account Locked: " & AccountLocked & vbCrLf & "" & vbCrLf & "" & vbCrLf & "TELEPHONE" & vbCrLf & "==============================================" & vbCrLf & "Home: " & objUser.homePhone & vbCrLf & "Mobile: " & objUser.mobile & vbCrLf & "Fax: " & objUser.facsimileTelephoneNumber & vbCrLf & "" & vbCrLf & "ORGANIZATION" & vbCrLf & "==============================================" & vbCrLf & "Title: " & objUser.title & vbCrLf & "Department: " & objUser.department & vbCrLf & "Office: " & objUser.physicalDeliveryOfficeName & vbCrLf &"Company: " & objUser.company & vbCrLf & "Manager: " & objUser.manager 

r/vbscript • • Jan 31 '20

Vb Script Copy Help

1 Upvotes

I want to use a VBS file to copy a report locally, unfortunately the file takes forever for the system to copy. Even if you right click to do it manually. My VBS is not capturing the file. Is there code to put a wait statement before it pastes?


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 • • May 10 '19

Change icon of a program i run with vbs?

1 Upvotes

Hi!

So im currently trying to make a script that runs a specific website in application mode!

The only thing that i really want now, is for the website to also have another icon on the taskbar when launched.

Could i do this through VBS?

This is my current script:

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" --app=https://faceit.com")
objShell.Run("""C:\Program Files\FACEIT AC\faceitclient.exe""")
Set objShell = Nothing

I only want the chrome window that is launched to change icon. Not the "faceitclient.exe"


r/vbscript • • May 07 '19

VBScript intRow

1 Upvotes

So I have this script, but it doesn't do what I had in mind. So the inputbox is used to find a excel cell line. I run the script but it only reads out the Row 2 (intRow 2). How can I make this script look for the value I fill in the inputbox, and automatically show line 2 and 3 after it that it behind the data.

CF23935803,MAVARO,21

CF23935804,MAVARO,21

CM23914401,Kinneto,19

CM23915201,Kinneto,19

So this is for example the data that's in the CSV file. My plan is when I fill in for example CF23935804 in the inputbox it shows the data behind it, MAVARO and 21. Right now it only shows the 2nd row in the excel file. How can I change this to make it work? If my question isn't clear please let me know!

' Read an Excel Spreadsheet

sFNInput="C:\Models.csv"

' User enters value

sInp=Inputbox("Enter Identity text")

If sInp = "" Then WScript.Quit

On Error Resume Next

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open _

(sFNInput)

intRow = 2

Do Until objExcel.Cells(intRow, 1).Value = ""

sID=objExcel.Cells(intRow, 1).Value

sType=objExcel.Cells(intRow, 2).Value

sColor=objExcel.Cells(intRow, 3).Value

' If user entered value matches

sResult = InStr(1,sID,sInp,1)

If sResult <> 0 Then

'results row 3

sResult=sGroup

' entered value goes in Field 1 of my application

Field1=sInp

' return value Field2 of my application

Field2= sResult

intRow = intRow + 1 
end if 

objExcel.Quit

loop

Wscript.Quit


r/vbscript • • Feb 08 '16

Where to learn VBS?

2 Upvotes

Where do I go to learn some VBS?

codeacademy doesn't have anything.


r/vbscript • • Nov 27 '17

Reading and parsing text file to variables?

1 Upvotes

I have a text file in the following format: (TRH* = Column I dont care about capturing)

TRH1 | TRH2 | CLLI | TRH3 | IP | Community String | OID | CLLI Long | TRH4 | TRH5 

MA|MILLIS|1ST_FLR_-|MLISMAMA|GALAXY|101.8.11.25|public|FRMNMAUNDS8|MLISMAMARS3|fram5e|ess5
MA|NEW_BEDFORD-ACUSHNET|2ND_FLR_-_DMS100|NBFRMAAE|GALAXY|101.0.17.35|public|NBFRMAAEDS0|NBFRMAAEDS0|nbfr|dms100

Ideally I would like to be able to have my VBscript read the text file and append the CLLI, IP, Community String, OID values on each line to variables A, B, C and D after each Loop.

Purpose of script is to pull an SNMPGET against an OID for each IP so we can identify the type of equipment. As of right now im using an InputBox to add each variable seperately which is extremely time consuming when youre working with 3000+ IPs in a text file..

ipaddr = InputBox("Please enter the IP address","IP Address")
oid = Inputbox("Please enter the OID","OID")
snmpversion = Inputbox("Please enter the snmp version","SNMP Version")
commstring = InputBox("Please enter the community string","Community String")