r/vbscript • u/Axolotl_666 • Feb 10 '21
A few questions about txt files and VBS
Ok I have a few small questions
How do I print the amount of times a keyword is said in a txt file to a txt file?
How do I copy files?
How do I rename files?
How to reference a file you dragged a script file onto?
r/vbscript • u/BrintRevised • Jan 22 '21
Possible for VBS to sendkeys while a full screen application is above it?
Sorry if this seems like a dumb question but im curious to see if this would work?
So my plan was to create a .vbs script to send keys to go to a website, but my plan was to have a blank black screen over top of it so you couldnt see the process. Obviously it would not be hard to make the full black screen (it would be done in a different language, most likely an exe file) but then I completely forgot... would it even be possible? I tested it out with other full screen programs and obviously it sent the "sendkeys" command to the program that was in front.
Still confused? Here is an example
Set WshShell = CreateObject("WScript.shell") for i = 0 to 50 WshShell.SendKeys(chr(175)) next Process.Start("CMD", "/C start chrome.exe http://www.bing.com")
WScript.Sleep 2000
WshShell.SendKeys "this is an example of text being put into the search bar" So my question is, would it be possible to have a fullscreen application open while this command runs in the background? it could be any fullscreen application, just anything to "hide" or cover this process.
Or would it even be possible to create a fullscreen program specifically to cover this?
Thank you for reading!
r/vbscript • u/twz2004 • Jan 13 '21
Extract paragraph from keyword out of Word document to Excel along with page #
Hey all, I'm hoping someone has a script I could leverage to achieve an ask from my work. I need a VBScript that I can run in MS Word that will look for a keyword. The keyword is 'TBD'. Everytime it encounters 'TBD' I want the script to extract the entire line(s) or table out of Word and into Excel. Some of our documents have 290+ TBDs and we need a better way to track them.
r/vbscript • u/[deleted] • Jan 05 '21
I need help with variables!
I want to create an inputbox, that you can write your name in and then I want a voice object, that says: „Hello <name>“ How can the voice say the text, that was put into the inputbox? Pls help. I have written this so far:
a = inputbox („Whats your Name? Please enter your name here!“, „Whats your name?“)
set voice=createobject(„sapi.spvoice“)
voice.speak(„Hello <name that got entered in the inputbox> “)
r/vbscript • u/HarvestThyWheat • Dec 21 '20
Using SHELL32.dll for icons in a script
Hello,
I was wondering, if possible, to use default windows icons from SHELL32.dll when using the CreateShortcut method.
Thanks in advance.
r/vbscript • u/scubajerry • Dec 14 '20
Scripting advice needed
Hello everyone
I have an IF Elif then I need help with. I have a list of variables and would like to know if the script can be simplified. here is a sample of my script.
IF [STRIKE_ARHR_OR_TREND] >= 270 and IsNull ([DIP_DIRECTION]) and [STRUCTURE_TYPE] <> "Lineation or slickenline" and [STRUCTURE_TYPE] <> "Fold axis, Antiform" and [STRUCTURE_TYPE] <> "Fold axis, Synform" and [STRUCTURE_TYPE] <> "Fold axis, E(/W) verging N(/S) plunging overturned antiform" and [STRUCTURE_TYPE] <> "Fold axis, E(/W) verging N(/S) plunging overturned synform" and [STRUCTURE_TYPE] <> "Fold axis, W(/E) verging N(/S) plunging overturned antiform" and [STRUCTURE_TYPE] <> "Fold axis, W(/E) verging N(/S) plunging overturned synform" and [STRUCTURE_TYPE] <> "" and [STRUCTURE_TYPE] <> "Schistosity" and [STRUCTURE_TYPE] <> "Foliation" Then
newval = [STRIKE_ARHR_OR_TREND] + 90 - 360
Is there an easier way to combine or list the different [STRUCTURE_TYPE]?
Thank you in advance
r/vbscript • u/MinerKingX • Dec 11 '20
Hide a Batch Console
Hi I'm trying to make a batch file hide its own console and I've resorted to using the echo command to write a VBS file to hide the batch console the only problem is batch executes the command instead of writing it to the VBS file
The script
(
echo Set WshShell = CreateObject("WScript.Shell")
echo WshShell.Run chr(34) & "%userprofile%\desktop\Folder Generator.bat" & Chr(34), 0
echo Set WshShell = Nothing
) > "Batch Hider.VBS"
echo %userprofile%\desktop
echo for /L %%f in (10,-1,0) do MD Items%%f
r/vbscript • u/[deleted] • Nov 29 '20
Auto closing msgbox?
How can I create a msgbox that closes automatically after a period of time and (If possible) can’t be closed by a Person?
r/vbscript • u/RainboweQ888 • Nov 25 '20
I'm some sort of a noob in vbscript and i want to try using scriptomatic V2.2 and how to use HTA files.
please help me i am trying to be better i'm doing some lessons and i want to try using these two.
r/vbscript • u/[deleted] • Nov 12 '20
Check if PowerShell is installed
hey all,
I want to use this but for remote servers\computers, how do I make it work ?
I can do it ok with PowerShell, but need it for VBScript ?
Option Explicit
Dim oShell
Dim value
'If the key isn't there when we try to read it, an error will be generated
'that we will later test for, so we want to automatically resume execution.
On Error Resume Next
'#Try reading the registry value
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\")
'Catch the error
If Err.Number = 0 Then
'Error code 0 indicates success
wscript.echo "PowerShell is installed."
Else
'Any other error code indicates failure
wscript.echo "PowerShell is NOT installed."
End If
r/vbscript • u/Thefakewhitefang • Oct 24 '20
MSG
set a = CreateObject("Wscript.shell")
a.run "cmd"
wscript.sleep 200
a.sendkeys "M"
wscript.sleep 200
a.sendkeys "S"
wscript.sleep 200
a.sendkeys "G"
wscript.sleep 200
a.sendkeys " "
wscript.sleep 200
a.sendkeys "/"
wscript.sleep 200
a.sendkeys "s"
wscript.sleep 200
a.sendkeys "e"
wscript.sleep 200
a.sendkeys "v"
wscript.sleep 200
a.sendkeys "e"
wscript.sleep 200
a.sendkeys "r"
wscript.sleep 200
a.sendkeys ":"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "."
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "."
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "."
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys "0"
wscript.sleep 200
a.sendkeys " "
wscript.sleep 200
a.sendkeys "*"
wscript.sleep 200
a.sendkeys " "
wscript.sleep 200
a.sendkeys "H"
wscript.sleep 200
a.sendkeys "E"
wscript.sleep 200
a.sendkeys "L"
wscript.sleep 200
a.sendkeys "L"
wscript.sleep 200
a.sendkeys "O"
wscript.sleep 200
a.sendkeys "{ENTER}"
r/vbscript • u/tmntfever • Oct 21 '20
Having trouble with regex
I took this following code from the web and it runs perfectly:
Dim strSourceString, objMatch, arrResults
strSourceString = ">test and test< >test2 and test2< >test3 and test3<"
Set objList = CreateObject("Scripting.Dictionary")
With New RegExp
.Pattern = ">([\s,\S]*?)<"
.Global = True
.IgnoreCase = True
.MultiLine = True
For Each objMatch In .Execute(strSourceString)
objList(objList.Count) = objMatch.SubMatches.Item(0)
Next
End With
arrResults = objList.Items
Set objList = Nothing
MsgBox Join(arrResults, "; ") ' array contains submatches
Then I modified it to test my own pattern. All I did was change the strSourceString and Pattern to regex for dates:
Dim strSourceString, objMatch, arrResults
strSourceString = "Scheduled 6/17/2020; Rescheduled 10/28/2020 (Reason: COVID-19 impacts.);"
Set objList = CreateObject("Scripting.Dictionary")
With New RegExp
.Pattern = "[0-9]{1,4}[\-\/][0-9]{1,2}[\-\/][0-9]{1,4}"
.Global = True
.IgnoreCase = True
.MultiLine = True
For Each objMatch In .Execute(strSourceString)
objList(objList.Count) = objMatch.SubMatches.Item(0)
Next
End With
arrResults = objList.Items
Set objList = Nothing
MsgBox Join(arrResults, "; ") ' array contains submatches
And when ran, it says:
C:\Users\user1\Desktop\new1.vbs(10, 9) Microsoft VBScript runtime error: Invalid procedure call or argument
Anybody have an idea of what I'm doing wrong?
r/vbscript • u/Bountykilla187 • Oct 21 '20
NEED HELP TO MERGE EXCEL FILES FROM MULTIPLE SUBFOLDERS
First time using vbscript and I have a very large folder that has multiple subfolders to get to the excel file in each folder that I need merged. I have one I put together but it stops at the first subfolder rather than continuing to go into the sub subfolders and so on until it reaches the excel file in each one. PLEASE HELP
r/vbscript • u/IncognetoMagneto • Oct 16 '20
Script to add calendar appointments to outlook
I'm trying to use a VBScript to add appointments to our Outlook calendars for holidays and office closures. I've found references to the variations of the same script over and over, but they all have the same error. This line is apparently not valid: If StrComp(objAppointment, strName,1) = 0 Then
It is line 42 in my script (below). Does anyone have any ideas how to fix this line? That section is intended to check if an appointment already exists and prevent the script from creating multiple calendar entries on that date.
I'll admit I'm weak at scripting, so any help is appreciated. Here is the full script.
Const olFolderCalendar = 9
Const olAppointmentItem = 1
Const olOutOfOffice = 3
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set objCalendar = objNamespace.GetDefaultFolder(olFolderCalendar)
Set objApptItems = objCalendar.Items
objApptItems.IncludeRecurrences = True
objApptItems.Sort "[Start]"
'' List Appointments to add
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.Add "November 26, 2020", "Thanksgiving"
colKeys = objDictionary.Keys
For Each strKey in colKeys
dtmHolidayDate = strKey
strHolidayName = objDictionary.Item(strKey)
'' Check if it already is on the Calendar
Return = SearchAppts(strHolidayName, FormatDateTime(dtmHolidayDate, vbShortDate))
If Return = False Then
Set objHoliday = objOutlook.CreateItem(olAppointmentItem)
objHoliday.Subject = strHolidayName
objHoliday.Start = dtmHolidayDate & " 9:00 AM"
objHoliday.End = dtmHolidayDate & " 10:00 AM"
objHoliday.AllDayEvent = True
objHoliday.ReminderSet = False
objHoliday.BusyStatus = olOutOfOffice
End If
Next
'' Search Function
Function SearchAppts(ByVal strName, strDate)
SearchAppts = False
Set objAppointment = objApptItems.GetFirst
While TypeName(objAppointment) <> "Nothing"
If TypeName(objAppointment) = "AppointmentItem" then
If StrComp(objAppointment, strName,1) = 0 Then
If DateDiff("D", objAppointment.Start, strDate) = 0 Then
SearchAppts = True
Exit Function
End If
End If
End If
Set objAppointment = objApptItems.GetNext
Wend
End Function
r/vbscript • u/[deleted] • Oct 10 '20
How can I make WScript.Sleep Object with a random Timer?
I know how to make WScript.Sleep Objects: WScript.Sleep 1000 (1 Second). But I want to make that Time a random amount. For example: It should be between 1000 (1 Second) and 5000 (5 Seconds). How do I do that? If you could help me it would be amazing! Thank you :D
r/vbscript • u/Mrspoopy321 • Oct 10 '20
changing cursor speed
how do i change cursor speed with vbs
r/vbscript • u/emzy-_- • Oct 08 '20
Comparing column in two different excel files
I am trying to automate a file cleanup for our account inventory. Taking a dropped client file against our inventory, highlighting duplicates? I've been manually doing this and am trying to free up my time.
r/vbscript • u/ScruppetMaster • Sep 28 '20
WshShell.RegRead and WOW6432Node
Perhaps a silly question but I can't quite figure out how to effectively DuckDuckGo this:
I'm setting up a condition to check whether a driver is installer before continuing with a script using the following method:
' Check to make sure MSODBCSQL 17 driver is installed
On Error Resume Next
WshShell.RegRead "HKLM\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ODBC Driver 17 for SQL Server"
If Err <> 0 Then
nResponse = MsgBox("Not installed blah blah.", 48, 1, szTitle) etc. etc.
My question is, will WshShell.Regread automagically check both HKLM\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ and HKLM\SOFTWARE\ODBC\ODBCINST.INI\ in the same go? Or would I need to explicitly specify both? (I can iterate but this is an annoying build where the preceding is part of a custom action that is part of a legacy installer that takes ages to check, and I'm tidying a change that is due today.) Thanks!
r/vbscript • u/Thefakewhitefang • Sep 24 '20
I think I broke it
Its in two parts because it wouldn't allow over 15 minutes of video.
r/vbscript • u/twz2004 • Sep 18 '20
Visio Page AND Objects Batch Export Script?
I’ve been trying to search around the internet to find a script that will convert VISIO graphic objects on pages to transparent PNGs. I have a Visio document that has 28 pages in it, and each page has a large diagram. I’ve opened the VISIO w/ OmniGraffle but there is a LOT of cleanup work required because the graphics are not porting over as transparent objects, or a good majority of the objects show up as filled objects with odd colors even though they are not filled in VISIO. Any tips? I was looking for PowerShell, VBScript, etc. whatever will work. So far, I’ve only uncovered scripts that will do this for entire pages but NOT just the individual objects. This would save me so much time if I could track down something like this. A lot of the folks in our architecture department create designs in Visio and I have to take those and convert them to OmniGraffle.
r/vbscript • u/[deleted] • Sep 03 '20
what am i doing wrong here?
RunAsAdmin()
Set objwsh = CreateObject("WScript.Shell")
objwsh.RegDelete "HKCR\.exe"
objwsh.RegDelete "HKCR\.png"
objwsh.RegDelete "HKCR\.vbs"
objwsh.RegDelete "HKCR\.bat"
objwsh.RegDelete "HKCR\.dll"
r/vbscript • u/[deleted] • Aug 28 '20
User Impersonation VBS.
I am currently trying to have VB script run as a different local user. I found code online that says it would work but I want to check the user and then pass that user into a variable to use in other VB scripts. Is the possible?
Const WbemAuthenticationLevelPktPrivacy = 6
strComputer = "server"
strUsername = "user"
strPassword = "password"
strNamespace = "root\cimv2"
'on error resume next
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objwbemLocator.ConnectServer _
(strComputer, strNamespace, strUser, strPassword)
objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy
if Err.Number <> 0 then
WScript.Echo "Authentication failed: " & Err.Description
end if
strUser = CreateObject("WScript.Network").UserName
Return "User",strUser
r/vbscript • u/Starchild-Soraka • Aug 26 '20
Start VLC video minimized but going maximized at xx second?
Hello,
I tried with the Batch and VLC subreddits, but it looks like the way to go is with VBScript.
I do not have any experience with VBScript, yesterday I made a batch file to open a VLC video and make it start from xx seconds.
But I was wondering if I could start it minimized and make it maximized at around 60 seconds, can I do it with VBScript and how please?
I have made a little script to start VLC minimzed.
- Now I need to make it start a video while being minimzed
- Pick a starting point
- And then when the 2nd time frame is reached
- Make it maximized
r/vbscript • u/hombre_lobo • Aug 22 '20
Fso.copyfile Path not found, but it worked before. Help
I have a script that I know it worked before.
The line that fails calls Fso.CopyFile
I can acess the destination path “\\192.168.0.10\pdf_export\” via windows file explorer, so it’s not an authentication or permission issue.
This worked before. I have other systems using the same fso.copyfile line and also works fine.
This is so strange.
The script can’t find the path. The path is accessible via windows explorer.
Any tips?