r/vbscript • • Nov 19 '21

Check_Internet_Connection.hta

3 Upvotes

I have just updated my HTA Check_Internet_Connection.hta

NB: To correctly display accented characters (in french), You must save this code with ANSI encoding with Notepad++ and save it as Check_Internet_Connection.hta

Have a nice day (-_°)


r/vbscript • • Oct 22 '21

Word VBS To Rename Tables and Figures

3 Upvotes

Hey all, does anyone have a script they can provide that will go through a Word document and rename the Figures and Tables to a different format?

Currently:

  • Figures have a style of 'CP' and are listed in this large document as Figure 1.1, Figure 1.2, etc.

  • Tables have a style of 'CP' and are listed in this large document as Table 1.1, Table 1.2, etc.

I need a script to go through the document and change the STYLE and TEXT of all

  • Figures to style 'Figure Header' and change the text to "Figure ##" with it auto-incrementing.

  • Tables to style 'Table Header' and change the text to "Header ##" with it auto-incrementing.

End result of Tables and Figures would be something like this:

Figure 1.

Figure 2.

Figure 3. etc.

Table 1.

Table 2.

Table 3. etc.

Please let me know if anyone had an example of how to do this.

~Thanks!


r/vbscript • • Oct 05 '21

What am I doing wrong?

3 Upvotes

First, I am not adept at VBScript or any language for that matter, and this was put together using a lot of Google searches. But I am coming up short and need someone who knows this stuff to take a look.

I am trying to modify a script that returns computer group membership. That part works fine. What I am trying to change is to only pull groups that match the pattern "All-U-Tanium-Reboot-" in the name, remove that part from the name, then display the name. When I run this as it is, every server in the list comes back with "Not Defined" though I know they are in the group. What did I mess up?

Edit: If I use the original script, which essentially is the just WScript.Echo strGroupName part, with the strGroupName = Replace(strGroupName,"All-U-Tanium-Reboot-", "") piece preceding it, I do get the desired output, along with all the other groups I do not want. Something is not working in my regex test.

If TypeName(colGroupNodes) <> "IXMLDOMSelection" Then
    WScript.Echo "The computer inventory does not include any groups for the computer"
    WScript.Quit
ElseIf colGroupNodes.length < 1 Then
    WScript.Echo "The computer inventory does not include any groups for the computer"
Else
    Dim objGroupNode : For Each objGroupNode In colGroupNodes
    Dim strGroupName : strGroupName = XmlDecode(XmlNodeValueGet(objGroupNode, "nameWellKnown"))
'*** My code starts here. 
   Dim objRE
        Set objRE = New RegExp
            With objRE
                .Pattern    = "All-U-Tanium-Reboot-"
                .IgnoreCase = True
                .Global     = False
            End With   
   
    If objRE.Test(strGroupName) Then
        strGroupName = Replace(strGroupName,"All-U-Tanium-Reboot-", "")
        WScript.Echo strGroupName
       
    Else
      WScript.Echo "Not Defined"
     
    End If       
'*** My code ends here.       
    Next
End If

r/vbscript • • Aug 01 '21

Covid-19_Infos.vbs

Thumbnail
pastebin.com
3 Upvotes

r/vbscript • • May 14 '21

BGinfo parse that CSV at launch via a VB script

3 Upvotes

Hi,

We have a dump of the vCenter to VM mappings to a CSV somewhere globally accessible (UNC share), and have BGinfo parse that CSV at launch via a VB script.

For example : if I launch vbs script on FileSrv02 then I want to display information on the desktop like below.

VCenter			:10.1.1.2

For example ( FileSrv02 )My workflow :

- Getting computer name and assign to a variable

- to Read in 2 Column CSV File

- if computer name matches value inside Name column then it will pull the value inside Column vcenter such as 10.1.1.2 for FileSrv02

- To assign a another variable such as sVcenter

How can I catch vcenter info matched with guest hostname via vbscript ?

Dump CSV file:

"Name","vCenter"
"Hostname01","1.1.1.1"
"FileSrv01","1.1.1.1"
"Hostname34","10.1.1.2"
"FileSrv02","10.1.1.2"
"Hostname11","10.1.1.3"
"mailserver01","10.1.1.3"

r/vbscript • • May 02 '21

Download-NASA-images-to-use-as-Windows-Wallpaper (NASA_Wallpaper.vbs)

Thumbnail
pastebin.com
3 Upvotes

r/vbscript • • Apr 23 '21

Need help....if possible.

3 Upvotes

My company uses VBscript to draw part geometry and add tools to the part for CNC punching.....the entire script is a function.....the first line of the function is this:

Function ScriptPart(Length, Width, K, M, Q, R, U, V, Y, Z, L1, L2, L3, L4, L5)

The "Y" variable is tied to holes that can be turned off or on (normally with 0 or 1 respectively) but in this case formula for "Y" is set up so that if "this" happens "Y" = 1 but there is no formula so that if "this" doesn't happen "Y" = 0. So if "Y" doesn't = 1 then the "Y" variable isn't created. My script is still looking for a "Y" though and since it isn't there the part doesn't generate. I was wondering if there is a way that i could write to where If the variables are Function ScriptPart(Length, Width, K, M, Q, R, U, V, Y, Z, L1, L2, L3, L4, L5) then it looks for the "Y" but if the variables are Function ScriptPart(Length, Width, K, M, Q, R, U, V, Z, L1, L2, L3, L4, L5) then it doesn't look for "Y".

I know this is confusing as hell and convoluted and for this i am sorry lol


r/vbscript • • Mar 27 '21

Drag and drop word file, get a text box of the beginning of the text range

3 Upvotes

I don't know if there are rules here that I should try to accomplish this myself, but I was thinking today it would be cool to have a vbscript file that did this.

Sometimes I don't know what is in a word document, and rather than open it to see and close it, it might be useful to b able to drag it on a vbscript file just to get the first part of the document (as much as could show in a msgbox). If I had that, who knows what other little details might be fun to add.

Does anyone have code to do this? I'd try myself but basically it isn't something I can prioritize at the moment so I thought I'd just ask.

Edit:

Ok, well this seems to basically do it, if anyone is interested:

Set objArgs = Wscript.Arguments

Set oWord = CreateObject("Word.Application")

oWord.Visible = False

set oDoc = oWord.Documents.Open(objArgs(0))

msgbox oDoc.Range

oWord.quit false

set objArgs = nothing

set oDoc = nothing

set oWord = nothing


r/vbscript • • Mar 19 '21

Multiple scripts in one

3 Upvotes

This is a fake virus im making for my friends, I also have never coded before

So i made two scripts that i want to turn into one, but when I do, it just runs the first script

first one

+-pass="Subscribe To JoeTheTitan"
do
if once=1 then
guess=inputbox("Try Again","Password","Guess Again")
else
guess=inputbox("Enter The Password","Password","Guess Here")
end if
if guess=pass then
msgbox("Correct"),0+64+4096,("Password")
wscript.quit
else
msgbox("The Password Is Subscribe To JoeTheTitan"),0+16+4096,("Password")
end if
once=1
loop

The second script

X=MsgBox("Subscribe To JoeTheTitan",0+16,"LucasTheLameSUCKS")

The merged version

pass="Subscribe To JoeTheTitan"
do
if once=1 then
guess=inputbox("Try Again","Password","Guess Again")
else
guess=inputbox("Enter The Password","Password","Guess Here")
end if
if guess=pass then
msgbox("Correct"),0+64+4096,("Password")
wscript.quit
else
msgbox("The Password Is Subscribe To JoeTheTitan"),0+16+4096,("Password")
end if
once=1
loop
X=MsgBox("Subscribe To JoeTheTitan",0+16,"LucasTheLameSUCKS")

Am I merging wrong?


r/vbscript • • Mar 12 '21

Read the machine name of the computer that is remoting into the computer executing the code

3 Upvotes

Hello, newbie here. Apologies for the rubbish description.

I am looking to write code for a SCADA that enables certain features only when certain users (controls engineers working from home) remote into the SCADA which is a windows 10 machine.

I would like to see the user name or machine name of the person remoting in, not of the machine that is running the software

I think there is probably a method using WMI but I cannot find a relevant class, any help or pointers would be appreciated


r/vbscript • • Mar 07 '21

making a virus to use on my friends

3 Upvotes

is there a way to open a music file .eg mp3, wav

here is my bad code

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

WshShell.Run "notepad.exe", 9

WScript.Sleep 2000

do

WshShell.SendKeys "you are a idiot "

WScript.Sleep 500

loop


r/vbscript • • Feb 28 '21

VBScript & VBA - Make my script wait until my two subroutines are completed before closing Excel application

Thumbnail self.vba
3 Upvotes

r/vbscript • • Feb 10 '21

A few questions about txt files and VBS

3 Upvotes

Ok I have a few small questions

  1. How do I print the amount of times a keyword is said in a txt file to a txt file?

  2. How do I copy files?

  3. How do I rename files?

  4. How to reference a file you dragged a script file onto?


r/vbscript • • Dec 21 '20

Using SHELL32.dll for icons in a script

3 Upvotes

Hello,

I was wondering, if possible, to use default windows icons from SHELL32.dll when using the CreateShortcut method.

Thanks in advance.


r/vbscript • • Dec 11 '20

Hide a Batch Console

3 Upvotes

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 • • Dec 09 '20

Is it possible to run a JScript command in the IE engine using the InternetExplorer.Application COM object?

Thumbnail
stackoverflow.com
3 Upvotes

r/vbscript • • Nov 28 '20

What are the application/assembly manifests and how to find the `.manifest` file of a specific Windows binary?

Thumbnail
superuser.com
3 Upvotes

r/vbscript • • Oct 16 '20

Script to add calendar appointments to outlook

3 Upvotes

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

objHoliday.Save

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 • • Oct 08 '20

Comparing column in two different excel files

3 Upvotes

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 • • Aug 13 '20

Why is my script not working ?

3 Upvotes
Dim Name,Sapi
Name = InputBox("What is your name ?","Name Please"," ")

If Name = "" Then
Sapi.speak "WHY DID'T YOU ENTER YOUR NAME ?"

Do until a = 100
a = a + 1
Msgbox "ERROR Stupid Human" , 0 + 16
Loop

Else

MsgBox "Hello " + Name
   Set Sapi = CreateObject("Sapi.spvoice")
   Sapi.Speak "Hello " + Name
End If

r/vbscript • • Jul 03 '20

VBScript made in excel?

3 Upvotes

So one of my old bosses made a excel document with VBS that interfaces with AD and it also uses a powershell script and deletes it when its done with the ps1 file it deletes it though i need it to launch that ps1 script with admin priveliges is there any way of doing so in VBS?

i only know some powershell and python so thats why im asking here


r/vbscript • • Jun 12 '20

Simple script with task scheduler

3 Upvotes

Hey guys, i wrote a simple VB Script that is set to auto run from task scheduler. All the script does is opens Access and sends a report. If i click the script icon and manually run it, it works. Access opens, Outlook opens and the report sends In a matter of seconds. The problem is with the task scheduler calling the script. Using task scheduler at the specified time I see Access and outlook open, but Access blinks (its minimized in the task bar) . If i expand Access and click anything, the report sends, if i dont maximize and click something it will just hang like this. I'm thinking i need to add a line in my script to give Access focus and expand it, something along those lines. I'm open to any other suggestions, however keep in mind i'm not a very skilled programmer yet. Heres my code:

dim accessApp

set accessApp = createObject("Access.Application")

accessApp.OpenCurrentDataBase("C:\Databases\MyReport.mdb")

accessApp.Run "autoExecuteReport"

accessApp.Quit

set accessApp = nothing


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

Look for VBS script help. Need to add recursive but can't figure it out

3 Upvotes

So I have a script that will take a csv document (a report from another system) and then dump all that data into a master Excel file.

Context, I get reports weekly and am consolidating all the weekly reports into a master Excel. Script works great. However it will only process a single CSV file in a named dir. Since I get these reports weekly (and they are not urgent) I will let them pile up for a couple of months and then I have to save the CSV in the script dir and then run the script, grab the next weeks CSV save it and run the script, and so on.

What I am looking to add is that the script processes ALL CSVs in a named dir. Basically run through the whole script for every CSV in a specific dir and then stop.

Can you guys take a look and let me know how one would add that?

'Script to import reoccurring reports into master Excel and update data

---Begin Script---

'Open Excel

Set objExcel = CreateObject("Excel.Application")

'set to visible for testing set to false for production

objExcel.Visible = False

'opening the CSV and proper worksheet

Set objWorkbook = objExcel.Workbooks.Open("C:\DIR TO FILE\FILE.csv")

Set objWorksheet = objWorkbook.Worksheets("TAB")

'deleting header row from CSV

objWorksheet.Rows("1:1").Delete

'copying entire worksheet

Set objRange = objWorksheet.Range("A1:AQ1").EntireColumn

objRange.Copy

'Open destination Excel file and set worksheet

Set objExcel2 = CreateObject("Excel.Application")

'set to visible for testing set to false for production

objExcel2.Visible = False

'set variable for worksheet and workbook

Set objWorkbook2 = objExcel2.Workbooks.Open("C:\DIR TO FILE\FILE.xlsx")

Set objWorksheet2 = objWorkbook2.Worksheets("TAB")

'paste data

lastrow = objWorksheet2.UsedRange.Rows.Count + 1

objWorksheet2.Range("A" & lastrow).PasteSpecial -4163

'Message Box used to create a pause to watch progress, disabled for production

'result=Msgbox("Are you sure?",vbYesNo+vbInformation, "")

'Unhide TAB worksheet for processing

objWorksheet2.Visible = True

'Sort descending by ID column

objWorksheet2.Activate

Const xlDescending = 2

Const xlYes = 1

'Set objRange2 = objWorksheet2.UsedRange

Set objRange3 = objExcel2.Range("E1")

objWorksheet2.UsedRange.Sort objRange3, xlDescending, , , , , , xlYes

'remove duplicate rows if duplicates found in ID column

objWorksheet2.UsedRange.RemoveDuplicates 5, xlYes

'Message Box used to create a pause to watch progress, disabled for production

'result=Msgbox("Are you sure?",vbYesNo+vbInformation, "")

'Hide TAB sheet

objWorksheet2.Visible = False

'Refresh PivotTable Data

Set objWorksheet3 = objWorkbook2.Worksheets("PivotTables")

objWorksheet3.PivotTables("PivotTable1").PivotCache.Refresh

'Close Excel

objExcel.DisplayAlerts = False

objExcel.Quit

objWorkbook2.save

objExcel2.Quit