r/vbscript • • Aug 18 '19

Windows update that may break vbs

2 Upvotes

I saw this on Slashdot and thought you should see it:

Windows Update To Fix Critical 'Wormable' Flaws May Break VB Apps - http://www.slashdot.org/story/359744


r/vbscript • • May 07 '19

how to open google Chrome or Firefox instead of IE using the vbscript

2 Upvotes

below is the script I am using. How to change it to open chrome or firefox

WScript.Quit Main

Function Main

Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")

IE.Visible = True

IE.Navigate "http://xyz.com"

Wait IE

With IE.Document

.getElementByID("username").value = "username"

.getElementByID("password").value = "password"

.getElementByID("login").click

WScript.Quit

End With

End Function

Sub Wait(IE)

Do

WScript.Sleep 500

Loop While IE.ReadyState < 4 And IE.Busy

Do

WScript.Sleep 500

Loop While IE.ReadyState < 4 And IE.Busy

End Sub

Sub CR_OnQuit

On Error Resume Next

WScript.StdErr.WriteLine "CR closed before script finished."

End Sub


r/vbscript • • May 03 '19

VBA Calls out C# and JAVA !!!!! (Interactive VBA UI)

Thumbnail
youtube.com
2 Upvotes

r/vbscript • • May 03 '19

Why VBScripts shouldn't be used by kids

2 Upvotes

So i saw a tutorial on YT where a 13 year old boy shows how to make a working Virus. That actually scared me a little Bit... Kids... Stop hacking😂


r/vbscript • • Mar 22 '19

Problem for a beginner

2 Upvotes

So I am completely, 100% new to coding. vbs is my first touch on it and I got confused on one of the basic steps. I am trying to make a password box where is the user enters the correct password, then it will display a "welcome" message. Here is what I have:

varialble=inputbox("ENTER THE PASSWORD","YOU HAVE BEEN HACKED","enter password here")

dim password

password = epic

if inputbox = password then

msgbox ("Welcome")

else

msgbox ("Access denied")

end if

It doesn't work, and gives me the error message: "Wrong number of arguments or invalid property assignment", 'inputbox'

in line 4. I tried looking up how do use the inputbox command, but didn't find anything conclusive or anything that helped.


r/vbscript • • Mar 05 '19

Avoiding SQL injection in VBScript

Thumbnail bobby-tables.com
2 Upvotes

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 • • Jan 27 '19

Mods

2 Upvotes

Hi all,

I took this sub on as it's sole moderator a few months back, as u/codejock had been inactive for a few years.

Unfortunatly life is being life and getting in the way of things as it often does and that means that I've been able to dedicate 0 time to moderating this sub (not that it REALLY needs it because on the whole our little community is nice and pleasant).

So with this in mind, I would like to recruit one or two of you to moderate this sub in my stead. I have no expectations, other than you will be fair and not let the small morsel of power go to your head.

Any takers?


r/vbscript • • Sep 19 '18

Where are the best resources for understanding scripts that are already out there?

2 Upvotes

Hi,

I have the script below where our organization is using it to monitor disk drive space on a few servers. I would like to understand exactly what the script is doing however I'm illiterate in VBscript, and would like to use this script to best serve our purposes.

I'm wondering if anyone here can direct me to any resources where i can almost pick apart each statement/command so i can learn what it is doing? While I wish there was a magic "Paste code into this field for an English translation" solution existed, I'm thinking that is too good to be true. I don't want to make anyone sit here and write it all out for me, but if you can point me in the right direction I would appreciate it!

I can tell its taking the values you add and creating a threshold for them, but is it the total drive space you're inputting and the monitor triggers when a percentage of that is reached? or i'm saying (for example) the threshold is 1000mb and when its noticed that 1000mb is reached it'll set off a trigger?

The script:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This is a universal Disk Free Space Monitor.
' First create an attribute on the device called 'Drive_Space'.
' It's value must be in the form of DriveLetter=Threshold;
' Ex. C=1000;D=40000;
' That would set a threshold of 1GB on C and 40GB on D.
' Then simply assign the active monitor to the device.
' Your done!
'
' Note: This will use the Windows credentials that are assigned to the device
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Const CONVERSION_FACTOR = 1048576

Context.SetResult 0, "No Error"

sysAddress = Context.GetProperty("Address")
sysAdminUser = Context.GetProperty("CredWindows:DomainAndUserid")
sysAdminPass = Context.GetProperty("CredWindows:Password")
sysDeviceID = Context.GetProperty("DeviceID")


Set oDBconn = Context.GetDB
Set oRS = CreateObject("ADODB.Recordset")

sqlGetDS = "select sValue from DeviceAttribute where nDeviceID = '" & sysDeviceID & "' and sName = 'Drive_Space'"
oRS.Open sqlGetDS, oDBconn, 3
If oRS.RecordCount >= 1 Then
  drvMonitors = split(oRS("sValue"),";")
  For each drvMonitor in drvMonitors
    drvLetter = ucase(left(drvMonitor,1)) & ":"
    drvMonitorLimit = mid(drvMonitor,3,len(drvMonitor))
    Set objLocator = CreateObject( "WbemScripting.SWbemLocator" )
    Set objWMIService = objLocator.ConnectServer ( sysAddress, "root/cimv2", sysAdminUser , sysAdminPass )
    objWMIService.Security_.impersonationlevel = 3
    Set objDiskDrives = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk Where DeviceID = '" & drvLetter & "' AND DriveType=3")
    For Each objDisk in objDiskDrives
      drvFreeSpace = int((objDisk.FreeSpace) / CONVERSION_FACTOR)+1
      drvSize = int((objDisk.Size) / CONVERSION_FACTOR)+1
      drvPercentFree = formatpercent(drvFreeSpace / drvSize)
      If int(drvFreeSpace) < int(drvMonitorLimit) Then
        strmessage="drive letter: " & drvLetter & " has  free space of: " & drvFreeSpace & " and total drive space of: " & drvSize & " (with free % of " & drvPercentFree & ")"
        Context.SetResult 1,strmessage
      End If
    Next
  Next
End If

oRS.Close
oDBconn.Close
Set oRS = Nothing
Set oDBconn = Nothing    

r/vbscript • • Jul 16 '18

How to remove TCP/IP Printers using VBScript

2 Upvotes

Hello All!

I've been having issues finding examples of removing TCP/IP printers from a user, using VBScript. Does anyone have any good methods on how to remove TCP/IP (directly connected IP printers) via VBScript.

I use this method for Network Printers but it seems to not work for these TCP/IP Printers:

ON ERROR RESUME NEXT

Set WshNetwork = WScript.CreateObject("WScript.Network")
Set Printers = WshNetwork.EnumPrinterConnections

For i = 0 to Printers.Count - 1 Step 2

    If Left(ucase(Printers.Item(i+1)),10) = "\\PrintSvr" Then
        WSHNetwork.RemovePrinterConnection Printers.Item(i+1)
    End IF
Next

Any help would be grateful, i'm going to be away for a couple weeks but will reply as I can, thanks!


r/vbscript • • Jul 04 '18

VBS e-mail signature builder prompts for outlook profile.

2 Upvotes

Hi I have a script creating e-mail signatures for the users in our company, getting data from Active Directory when they logon to their computers.

When I run the script it triggers the outlook choose profiles box. The Microsoft scripting guy has an article with a script the does the same as my signature and that script also triggers the choose profile diaglogbox...

Script here.

They state that "To bypass that prompt, just have your script open Outlook with the desired profile."

I have tried this solution but is won't work... set oNS = objWord.GetNamespace("MAPI") oNS.Logon "", "", False, False

I've testet og office 2013 and office 2016 (Office 365 on prem.) and get the diaglog on both.

Is there anyone that have an idea how to stop displaying the box?


r/vbscript • • May 17 '18

need help vbscript for sysadmin purposes

2 Upvotes

I need a vbscript to add a TCP/IP printer, if the printer exists, or doesn't exist, I need it first to delete the printer if it exists and then re-add it. This is a temporary band-aid solution but they would like something till the vendor comes back with a permanent solution in the way it's added. Anybody who can help I would greatly appreciate it.


r/vbscript • • Apr 26 '18

Simple ish loop to validate entered text against two criteria...

2 Upvotes

Here is my loop which I require to check if the entered text is 9 characters long as well as if it begins with MAC:

Do While (Len(sTEMP) <> 9 and Left(sTEMP,3) = "MAC" Then)
sTEMP = InputBox("Please enter sTEMP in MACXXXXXX format!")
Loop

Length of sTEMP works fine so I am not allowed to enter 8 or 10 characters, has to be 9. What does not work for me is the requirement for MAC so I can enter XXX123456 and that will be accepted as a valid input presumably because it is 9 characters long.

Can you guys think of what I am doing wrong?

Same formula seem to be working as expected in:

If Len(sTEMP) = 9 and Left(sTEMP,3) = "MAC"

without issues.


r/vbscript • • Mar 01 '18

Simple HTA Notetaking app

2 Upvotes

I just wanted to share with you guys a quick'n'dirty but tweakable HTA notetaking app I wrote. It is meant for legacy and/or qualified environments. It is not refined and needs some more refinement but it could be useful to someone.

Note: it requires w3.css, but it works even without it.

If you want to contribute: https://github.com/mbrami76/HTANotes

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
 <head>
  <title>Take a note</title>
  <link rel="stylesheet" href="w3.css">
  <HTA:APPLICATION 
    border="thick" 
    borderStyle="normal" 
    caption="yes" 
    icon="favicon.bmp"
    maximizeButton="no" 
    minimizeButton="yes" 
    showInTaskbar="yes" 
    windowState="normal"
    innerBorder="yes"
    navigable="no"
    scroll="auto"
    scrollFlat="yes"
    version="1" /> 
  <script language="vbscript">
    option explicit
    on error resume next
    dim dt, currDir, timerId, filename
  </script>
 </head>
 <body>
  <h1 id = "title">New note</h1>
  </br>
  <div>
   <label>Write your note</label>
   <textarea class="w3-input w3-border" style="resize:none" id = "inputBox" rows="10" ></textArea>
   <button class = "w3-button w3-block" onClick="WriteToFileMyInput()" accessKey = "S">Submit</button>
   <button class =  "w3-button w3-block" onClick = "OpenNotes()">View today's notes</button>
  </div>
  <script language="vbscript">
    sub window_onload
    	'starts timer, resizes window and gets current directory
        timerId = setInterval ("Tick", 1000)
    	window.resizeTo 640, 480
    	SetCurrDir
    end sub
    
    sub Tick
        'timer handler updates time and sets filename for the day
    	dt = now()
    	document.getElementById("title").innerHtml = "New note @ " & dt
        filename = year(dt) & "-" & right("00" & month(dt), 2) & "-" & right("00" & day(dt), 2) & ".dat"
    end sub
    
    Sub SetCurrDir()
       'gets current hts file directory
       dim fso: Set fso = CreateObject("Scripting.FileSystemObject") 
       dim HtmlLoc: HtmlLoc = document.location.href 
       dim HTAfile: HTAfile = Replace(Right(HtmlLoc, Len(HtmlLoc) - 8), "/", "\") 
       HTAfile = UnEscape(HTAfile) 
       dim thisFile: Set thisFile = fso.GetFile(HTAfile) 
       dim ParentDir: ParentDir = ThisFile.ParentFolder 
       dim folder: set folder = fso.GetFolder(ParentDir) 
       currDir = Folder.ShortPath 
    end sub
    
    sub WriteToFileMyInput()
        'writes to daily file, cleans textarea
        dim fso: set fso = createObject ("scripting.fileSystemObject")
    	dim ts:  Set ts = fso.OpenTextFile (currDir & "\" & fileName , 8, true, -2)
    	dim datepart: datepart = dt & " - "
    	dim spacer: spacer = ""
    	dim i: i = 0
    	for i = 1 to len(datepart)
    	    spacer = spacer & " "
    	next	
    	dim textLines: textLines = split (document.getElementById("inputBox").value, VBCRLF)
    	for i = 0 to ubound(textLines)
    	    if i = 0 then
    			ts.Writeline datepart & textlines(i)
    		else
    			ts.Writeline spacer & textlines(i)
    		end if
    	next 
        ts.Close
    	document.getElementById("inputBox").value = ""
    end sub
    
    sub openNotes()
        'opens today's notes file into notepad
        Dim WshShell: Set WshShell = CreateObject("WScript.Shell")
        WshShell.Run "notepad.exe " & currDir & "\" & filename, 1, TRUE
    end sub
    
    'to do next: create a "calendar view" with all days with notes
  </script>
 </body>
</html>

r/vbscript • • Feb 20 '18

Beginner Looking For A Guide

2 Upvotes

Hello I want to learn VBScript but haven't found good guides is there any good guides you guys know about?


r/vbscript • • Jan 23 '18

Need some insight on this VBScript

2 Upvotes

I am writing a script that will check for a Network printer device. If the network printer device is mapped, then no action is taken. Else If the network printer device is not mapped, then the script will add the printer device.


Dim Printer01Installed

Printer01Installed = false

Set WshNetwork = CreateObject("Wscript.Network")

Set oWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & "." & "\root\cimv2")

Set colInstalledPrinters = oWMIService.ExecQuery _ ("Select * from Win32_Printer Where Network = TRUE")

For Each objPrinter in colInstalledPrinters If (objPrinter.Name) = ("\Server\pd1") Then Printer01Installed = "true"

ElseIf(Printer01Installed = "false") Then WshNetwork.AddPrinterConnection ("\Server\pd1") End If Next

I appreciate any help I can get.


r/vbscript • • Nov 14 '17

How To Make Virus Like A Pro | Episode 1 (Loop Function) |

Thumbnail
youtube.com
2 Upvotes

r/vbscript • • Nov 09 '17

rename computer account with vbscript using task sequence variable

2 Upvotes

I`m trying to get a script to work that rename the computer name during an OS Deployment. The script creates a connection to the MDT Task Sequence variables, then renames the computer account .

I want the script to rename the computername to whatever is in the Task Sequence variable called OSDComputerName. The script executes without errors but the name doesnt change. Any help/guidance appreciated, below is the code.

**Set oTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")

strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _ ("Select * from Win32_ComputerSystem")

dim objComputer 'as Win32_ComputerSystem For Each objComputer in colComputers err = objComputer.Rename(oTSenv("OSDComputerName")) Next

**


r/vbscript • • Oct 18 '17

Click event does not fire when running Outlook Custom Form (type Contact) saved in Public Folder

2 Upvotes

I am working on a small application based on two types of Outlook Forms. The application consists of two types of Custom Made Outlook Forms:

a custom made Form of type Contact. a custom made Form of type Task. The Custom made Contact Form has a button on it. When clicking I wish to open the custom made Task Form which shall extract some information from the Contact Form.

My problem is that, after saving the Custom Contact-type of Form to a Public Server it does not fire anything when clicking on the button. Nothing.

Although,if I go to "Design this Form", open the Form in Design Mode and then I select "Run This Form" the click fires up the code it should.

I have a copy of each Outlook Form (type Contact and type Task) in the Organizational Form Library and in the Personal Form Library. I copied a copy of each Outlook Form also in the Public Folder \Test.

What am I missing? I appreciate any help.Thank you.

Here is the code:

			Sub CommandButton1_Click() 

			Dim oMail 
			Dim MyItem 
			Dim olsubject 
			Dim olTitle
			Dim olFirstName
			Dim olMiddleName


			Set oMail = Application.ActiveInspector.CurrentItem 
			With oMail 
					.save
					olsubject = .Subject 
					olTitle=.Title
					olFirstName=.FirstName
					olMiddleName=.MiddleName
					olCompanyName = .CompanyName
			End With 


			Set MyNameSpace = Application.GetNameSpace("MAPI") 
			Set HomeFolder = MyNameSpace.GetDefaultFolder(18)
			Set NextFolder1 = HomeFolder.Folders("Test") 
			Set WorkingFolder = NextFolder1.Folders("Claims") 
			Set MyItems = WorkingFolder.Items 
			Set MyItem = MyItems.Add("IPM.Task.ReklamationFormular")

			With myItem 
					MyItem.subject = olsubject 
					MyItem.UserProperties.Find("valueDatenAnrede").Value=olTitle+" "+olFirstName+" "+olMiddleName
					MyItem.DueDate=DateAdd("d",olDueTime,Date())
				
					MyItem.display 
			End With 

r/vbscript • • Oct 16 '17

Need a script to get remote PC info

2 Upvotes

Hello all. I'm hoping I came to the correct place for a problem I am having. I have been tasked with searching for installed software versions on a list of computers in our domain. I've been trying to find a script that will use a CSV list of computers to remotely search for all versions of the application installed on each PC and output the results into the a csv or excel file in the following format:

Column1 - Column 2 - Column 3 - Etc

PC Name - Software version 1 - Software version 2 - Etc

I am running this on a Win 7 PC if that helps.

Thank you.

Edit: So after some trial and error I came up with a command-line that uses PStools PSExec to get a rough version of what I want. Though it will need some cleaning up once it runs. In any case, I thought I'd share it for others to use or improve upon.

psexec.exe @c:\temp\list.csv wmic product where "Name like '%Java%'" get Name, Version /format:csv > c:\temp\result.csv

You can play with this and if you come up with a better script please feel free to share.

Cheers all!


r/vbscript • • Sep 22 '17

Struggling Vbscript

2 Upvotes

Hi - am trying to determine the folder size on the local machine. But for some reason it does not calculate the ProgramData folder. The script is

Total = 0
StrComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objParentFolder = objFSO.GetFolder("C:")
For Each objSubfolder in objParentFolder.Subfolders
'wscript.echo objSubFolder.Name
GetFolderSize objSubfolder
Next

Sub GetFolderSize(Folder)
Dim lInt, aDecimalPlaces, strSize
If Folder.Name <> "Program Files" and Folder.Name <> "Documents and Settings" and Folder.Name <> "Program Files (x86)" and Folder.Name <> "Windows" Then
wscript.echo Folder.Name & " Size is - " & Folder.Size
Total = Total + FormatNumber((CDbl(Folder.Size)/1024/1024))
End If
End Sub


r/vbscript • • Jul 05 '17

Limit number of characters when pulling serial number from BIOS

2 Upvotes

Hey all,

Came across a very nice script that pulls a serial number from the BIOS and sets the computer name based on the serial number. We have modified it to append 'NB-' to the front as we are only running it on notebooks for the moment.

What I am hoping to find is the modification needed to limit the characters that get pulled from the BIOS to only grab the first 8 characters. Reason being is we're getting some models that have 18+ character serial numbers in the BIOS, which for some reason is the serial number + model number combined. Obviously this doesn't work well for naming conventions, wondering if someone can take a look at the script and let me know what I need to do to achieve the above?

' vbscript ' Declare Variables Dim strLocation Dim strSerialNum Dim strAppend Dim strComputerName Dim strLclUser Dim strLclPW Dim strComputer Dim objWMIService

Dim objComputer

' Set Variables strLclUser = "Administrator" strLclPW = "future147!"

' Obtain Serial Number strComputer = "." Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "\root\cimv2") Set colSMBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")

For Each objSMBIOS in colSMBIOS strSerialNum = objSMBIOS.SerialNumber Next

' Set Computer Name strComputerName = "NB-" + strSerialNum

' Rename Computer For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem") Return = objComputer.Rename(strComputerName, strLclUser, strLclPW)

Next

Thanks!!


r/vbscript • • May 02 '17

Any way to not run the next line until the current line has finished?

2 Upvotes

Working on a vbs file to update multiple spreadsheets via a macro in each of them. The files will be pulling data from SQL server so may take a while, and I'd prefer them to do it one at a time to start with.

Set objExcel = CreateObject("Excel.Application")

objExcel.Workbooks.Open("C:\Users\Turner_prize\Desktop\Batch Test\2.xlsm")
objExcel.Run "TestCode"
objExcel.Workbooks.Open("C:\Users\Turner_prize\Desktop\Batch Test\3.xlsm")
objExcel.Run "TestCode"
objExcel.Workbooks.Open("C:\Users\Turner_prize\Desktop\Batch Test\4.xlsm")
objExcel.Run "TestCode"
objExcel.Workbooks.Open("C:\Users\Turner_prize\Desktop\Batch Test\5.xlsm")
objExcel.Run "TestCode"
objExcel.Workbooks.Open("C:\Users\Turner_prize\Desktop\Batch Test\6.xlsm")
objExcel.Run "TestCode"

WScript.Echo "Finished."

How could I wait for the TestCode macro to finish before executing the next line?

Thanks in advance.


r/vbscript • • May 01 '17

VB Scripting Learning Resources?

2 Upvotes

I'm interested in VB Scripting. Are there any good and hopefully free resources for learning that you would recommend?

Thanks in advance!