VB Script

37K

Solutions

20K

Contributors

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
I have the following VB Script Task in an SSIS package.
It takes a set of variables  (ScriptPath, uName, Pwd, etc) and builds a shell command .
The package is not executing successfully.
I want to somehow be able to output the final text that is presented to the Shell so I can examine it, and possibly try to run it outside of the package.
Any guidance in how I can output this text, possibly a log file? Or output to the screen when running the package on Debug mode in visual studio?
Thanks

' Microsoft SQL Server Integration Services Script Task
' Write scripts using Microsoft Visual Basic 2008.
' The ScriptMain is the entry point class of the script.

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

<System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
<System.CLSCompliantAttribute(False)> _
Partial Public Class ScriptMain
	Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase

	Enum ScriptResults
		Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
		Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
	End Enum
	

	' The execution engine calls this method when the task executes.
	' To access the object model, use the Dts property. Connections, variables, events,
	' and logging features are available as members of the Dts property as shown in the following examples.
	'
	' To reference a variable, call 

Open in new window

0
Amazon Web Services
LVL 12
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

I use a vb script to reformat CSV I receive from a vendor on a daily basis. I've started receiving a new batch of fields (columns) that I need to concatenate AND insert separators between values. Currently, my tortured method is below:

objSheet.Range("X2:X" & lastrow).FormulaR1C1 = "=RC[5] & "";"" & RC[6] & "";"" & RC[7] & "";""& RC[8] & "";"" & RC[9] & "";"" & RC[10] & "";"" & RC[11] & "";"" & RC[12] & "";"" & RC[13] & "";""

However, this results in a whole lot of orphan semi-colons whenever a column is empty. I've tried TEXTJOIN like so:

objSheet.Range("X2:X" & lastrow).FormulaR1C1 = "=TEXTJOIN("";"",TRUE,RC[5]:RC[16])"

but that failed.

Can somebody provide an alternative method that won't end up creating entries like this?

;;;;subject5;;subject7;;;;subject11
0
Hi there
I have a client that needs to image a large number of laptops. Prior to imaging they need to make some BIOS (UEFI) changes. I believe this can be done in Windows PE as well as MDT/SCCM, using WMI commands inside a VBS script.
2 questions:-
1. How do I create this VBS script in the first place?
2. Is there a tool I can use to help me?
Bonus question! Is there an easier way to be adjust an UEFI BIOS prior to imaging?
Cheers
Michael
0
<%

If (XYZ IsNot Nothing) Then 

 Response.write(XYZ)

End If

%>

Open in new window

This gives me an error:

Server Error in '/' Application.
Object reference not set to an instance of an object.


How can I test if XYZ is actually defined?
0
VB logon script that will set IE so when you open a new tab the user's frequent sites will show up, not MSN's top sites.
0
I've a problem connecting via an MSSOAP.SoapClient to a web service.

The exact same call works on a different client.

Here is the code - this is in a VBS file:

set h = CreateObject("MSSOAP.SoapClient30")
h.ClientProperty("ServerHTTPRequest") = True 
url = "https://(myserver)/WebService.asmx?wsdl"
h.MSSoapInit(url)

Open in new window


This gets an error:

WSDLReader: WSDLReader:XML Parser failed at linenumber
0, lineposition 0, reason is: The system cannot locate the resource specified.
HRESULT=0x1: Incorrect function.
- WSDLReader:Loading of the WSDL file failed HRESULT=0x80070057: The parameter is incorrect.
- Client:One of the parameters supplied is invalid. HRESULT=0x80070057: The parameter is incorrect.

The same URL loads fine in the browser.

There is a very similar issue described here:
https://stackoverflow.com/questions/3374573/why-can-i-access-a-wsdl-file-from-a-browser-but-not-from-application 

In which the suggested resolution is to compare the traffic between the browser and the app using Fiddler.

However I can't seem to get Fiddler to intercept the traffic.

I've tried with and without this line:
h.ClientProperty("ServerHTTPRequest") = True


I'm on Windows Server 2008 R2
1
In column A are names and in column B I have emails. I then removed all of the emails that are present in my unsubscribe list. Now I have about 1K less emails. I want to now match the name with the final list of emails. Anyway to do that using an Excel formula or Macro?
1
Hi,

I have this json request that I want to deserialize to an vb object. The json looks like this:
{
    "PerReg": [
        {
            "AnstNr": "1",
            "EfNamn": "Ljunggren",
            "FoNamn": "Siv",
            "Adress1": "Föreningsgatan 33",
            "Adress2": "",
            "PostNr": "447 34",
            "PostOrt": "VÅRGÅRDA",
            "LandAdr": "",
            "EpostPriv": "",
            "EpostArb": "",
            "Telefon": "0322-21298",
            "Mobil": "",
            "PersNr": "197901049283",
            "Signatur": "SL",
            "Befattning": "VD",
            "AnstDatum": "2001-09-01",
            "Slutat": false,
            "AvgDatum": "1899-12-30",
            "AnstTom": "1899-12-30",
            "Locked": false,
            "KalSchemaAuto": false,
            "UseOBRegel": false,
            "LockOBRegel": false,
            "OBRegelID": "",
            "UseArbSchema": true,
            "ArbSchema": "1",
            "Avdelning": "10",
            "KalUseAttest": true,
            "PerTyp": "LED",
            "AnstForm": "TV",
            "LoneForm": "MÅN",
            "LSSBerPerStart": "1899-12-30",
            "LSSBerPerInt": "",
            "LSSAnnanArbGiv": false,
            "LSSArbGivNamn": "",
            "LSSArbGivOrgnr": "",
            "UseSysGrad": true,
            "SysGrad": 100,
            "VeckArbTid": 40,
            "HelVeckTid": 40,
            "VeckArbDgr": 5,
            "DagArbTid": 8,
        

Open in new window

1
I could use some help with my script. I put *** where I need help making a code that would auto enter the most recent sundays date. Could you help?

[PCOMM SCRIPT HEADER]
LANGUAGE=VBSCRIPT
DESCRIPTION=
[PCOMM SCRIPT SOURCE]
OPTION EXPLICIT
autECLSession.SetConnectionByName(ThisSessionName)

REM This line calls the macro subroutine
subSub1_

sub subSub1_()
   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[tab]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "158"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "5"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[enter]"
   
   autECLSession.autECLPS.WaitForAttrib 10,56,"00","3c",3,10000

   autECLSession.autECLPS.WaitForCursor 10,57,10000

   autECLSession.autECLOIA.WaitForAppAvailable
   
   autECLSession.autECLOIA.WaitForInputReady
   ***Input the most recent sunday's date.
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "[field+]"
   autECLSession.autECLOIA.WaitForInputReady
   autECLSession.autECLPS.SendKeys "580171"
end sub
1
Hi ,

i have working script..
i want to put additional checks in the script to check for files and proceed further.
it should check for files after it checks for source folder.
if all three files available then proceed further to run remaining lines of checking backupfolder.
if even one file is missing or all missing it should write log the missing files and exit

Files names to check-
cat.xml
rat.xml
bat.xml

$logdate=Get-Date -Format ddMMMyyyy_HHmmss
$Logfile = "E:\Logs\FileProcessing_$logdate.txt"

function LogWrite ([string]$logstring)
{  
   Add-content $Logfile -value $logstring
}

#Zip Files
$sourcefolder="E:\INT\PUT"
$backupFolder="E:\INT\Archive"

#check if source exists
if(!(Test-Path $sourcefolder)){
    $msj="The source folder ""$($sourcefolder)"" doesn't exists. Exiting..."
    LogWrite "$( Get-Date -Format "yyyy-MM-dd HH:mm:ss" ) ERROR:`t$msj"
    LogWrite -ForegroundColor Red $msj
    exit -1
}

#check the target folder or create it
if(!(Test-Path $backupFolder)){
    $msj="The target folder ""$($backupFolder)"" was created"
    LogWrite "$( Get-Date -Format "yyyy-MM-dd HH:mm:ss" ) EXECUTE:`t$msj"
    LogWrite -ForegroundColor Magenta $msj
    New-Item -ItemType Directory -Path $backupFolder | Out-Null
}
foreach($file in (Get-ChildItem -File $sourcefolder -Filter "*.xml" -Recurse)){
    $date = Get-date -Format "ddMMyyyy_HHmmss"
    $destinationFile = "$($FILE.Directory.FullName)\$($file.Name).zip"
    $MoveFile = …
0
Learn SQL Server Core 2016
LVL 12
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

I would like to change this script, so that instead of hard coding in the destination email addresses, it will look into a flat txt file and use the email addresses listed in that specific file instead.


###SETUP START###
#-------DO NOT MODIFY-------#
    #Yesterdays Date
        $date = ((Get-Date).AddDays(-2)).ToString("MMM/dd/yyyy")
###SETUP END###

###USER VARIABLES START###
#-------MODIFY AS NEEDED-------#
    #Mail Subject
        $Subject = "Report: "+$date+" REVISED "
    #Body of Email
        $MessageBody = "REVISED - Report for $date. Thank you."
###USER VARIABLES END###

###PROGRAM START###
      # Invokes the Send-MailMessage function to send notification email
Send-MailMessage -From 'email1@mail.com' -To 'email2@mail.com', 'email3@mail.com', 'email4@mail.com' `
  -SmtpServer 'smtp.mail.com' `
  -Subject  $subject `
  -body $MessageBody `
  -BodyAsHtml `
  -Attachment 'C:\Attachment\Attachment.pdf'
 ###PROGRAM END###

Thanks in advance for your assistance
0
Scheduled task won't run unless logged in on Windows Server 2016. I've researched this for several hours and I'm getting nowhere. This is calling a VBS script which runs just fine if you either run it manually, or set the scheduled task to run only when the user is logged in.

The user is a domain admin. I also tried activating the default administrator account and it also fails in the same way when using this account, too.

I've tried calling the script via a batch file.
I've ensured that the START IN folder is specified and that it has a trailing backslash.

I've also tried calling this as C:\windows\syswow64\cscript - with a variable of the path to the vbscript, and using the syswow folder as the START IN folder.

I'm at a loss to know what to try next. There's possibly a typo somewhere along the line, but the scheduled task does run if it's set to run only when I'm logged in - I would hope that this proves the parameters to be correct.

For information, the script calls a program called Snapshot.exe and this creates a volume shadow copy vss type backup to a folder. This will eventually be a network resource but I've reconfigured it to be a local drive location temporarily so that there's no confusion over network credentials.

Any ideas please?
0
I am developing a ASP.NET Web Forms / VB.NET app.  I am new to the ASP.NET portion of coding (I prefer to do as much of the coding in this project in VB.Net as possible) .  I am wanting to use a GridView with a column to click for a drill down.  I found some code online that seems like it should work with some tweaking.  I have it partially working.  It works for the main GridView, but not the drill down.

This is the link of the demo where I got the sample code showing how it works:  "https://www.aspsnippets.com/demos/308/"

Here is what I am getting on my webpage:
WebPage.JPG
Here is the code that calls the main GridView:
       
       ' Get main table data and bind to GridView control
        grdDelvImp.DataSource = GetData("SELECT * FROM " & gtblship_delay & "WHERE so_id = '" & strSO_IDIn & "'")
        grdDelvImp.DataBind()

Open in new window


GetData function:
    
Public Function GetData(query As String) As DataTable

        ' Open Connection To The Database
        If con Is Nothing Then
            open_db_connection()
        ElseIf con.State = 0 Then
            open_db_connection()
        End If

        Using con
            Using cmd As New SqlCommand()
                cmd.CommandText = query
                Using sda As New SqlDataAdapter()
                    cmd.Connection = con
                    sda.SelectCommand = cmd
                    Using ds As New DataSet()
                        Dim dt As New DataTable()
                 

Open in new window

0
I'm using the following code to copy files from one folder to another and receive the error message object required on line:
objfso.CopyFile strSource & strFileName, strDest, OverWriteExisting

Open in new window


strSource = "C:\Users\vincent.shields\Documents\MATS\dbs\"
strDest = "\\itio-ARL-fs01.itsc.hhs-itsc.local\alj_arlington\MATS\Testdbs"
For Each strFileName In Array("matsdbarl.accdb", "matsdosarl.accdb")
objfso.CopyFile strSource & strFileName, strDest, OverWriteExisting
Next


Set objfso = Nothing

Open in new window

0
I am pulling my hair out on parsing a JSON API response (from ShipStation) due to the arrays within the response object.  I have always used a JSON parser (from demon.tw) which works perfectly for accessing the various items in a JSON object, however it does NOT work with arrays because of the fact that it is using JScript one cannot loop with a variable index.

I have tried a few other JSON classes but still had no success in being able to easily loop through each order and pull the relevant order information for each.

Below is a sample of the JSON response from the API. Can someone please help me loop through the orders (only 2 orders in the array in the sample below), and populate all the necessary order variables on each loop, such as OrderID, Customer info, billing/shipping addresses, line items ordered, priciing etc.


Open in new window

0
I would like to know a simple script, either using .bat, vbs or powershell, to send an email to several email recipients, with 1 specific attachment.
Using a gmail email account.
I would like to be prompted for what to input for the Subject, the Body of the email, and I would like to be prompted the name of the file to attach.
A pop up where I can type the Subject, the Body, and the name of the file would be good.
For simplicity's sake the attachment will reside at:  C:\Attachment..

**Very importantly I would like to add BCC recipients, multiple**
I have a script that works however I cannot seem to add BCC recipients.

Thanks in advance for your assistance.
0
Hi!  We are testing our existing files before upgrading from Office 2010 to Office 365 (Office 2016).

We have a complicated Excel frontend created by users to process data and automatically create charts and graphs and ultimately export everything directly to PowerPoint.

We have done a ton of testing but have only come across one problem that I can't seem to resolve.

VB code that copies and paste a chart from Excel to PowerPoint works in Office 2010 but not in 2016.  
Here's how the code currently exists in Office 2010.
        Set activeSlide = pp.ActivePresentation.Slides(1)
        ActiveSheet.Range("BX146:BY158").Select
        ActiveSheet.Range("BX146:BY158").Copy
        activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject).Select

Open in new window

This gives us the following error in 2016.
Run-time error '424':
Object required
(also see screenshot in Word doc)

I read posts online and made the following code changes but ended up with the same error.
   
        Set activeSlide = pp.ActivePresentation.Slides(1)
        ActiveSheet.Range("BX146:BY158").Select
        ActiveSheet.Range("BX146:BY158").Copy
       '9/5/18 activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject).Select 'Runs table
        '9/5/18
        Dim pptshape As PowerPoint.Shape
        Set pptshape = activeSlide.Shapes.PasteSpecial(DataType:=ppPasteOLEObject)
        pptshape.Select
        '9/5/18 end

Open in new window


As I said, this code runs fine in Excel 2010.

Does anyone have any ideas on how to resolve this issue?  Also, please note that we need to be able to paste the object (which is a table in Excel) so that PowerPoint links to the table in Excel and "sees" any updates that may be made in Excel to the table.

Thank you for your help.

Alexis
isummary-powerpoint-creation-error-.docx
0
Hi Experts ,

I have a  Independent folder in Outlook named "Test" .
I have macro whose work is to get the attachment from "Test" folder emails and save at"EmailAttachments" folder in "MyDocuments"

So the program is working when I manually run the macro , So I need your help to set some program which can run this macro automatically .
The program should run when new email comes in "Test" folder only otherwise if it will check inbox and all outlook then it will be performance issue.

I am using below code in "ThisOutlookSession" but it is checking all incoming emails in outlook , just need to check "Test" folder only.

Private Sub Application_NewMail()
    Call SaveAttachments
End Sub 

Open in new window



Also "Run as Script" is not available.


Appreciate any help in this regard.
0
Good Afternoon,

I am looking for a script that can do a comparison between two types of files and output the differences to a new file.

The two files are a list of names, I am looking to see what names are missing from the file called 'Names2.txt' compared to the full list of names from the file called 'Names.csv'


0
Become a CompTIA Certified Healthcare IT Tech
LVL 12
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Need help -

How to save the .xls file as .xlsx without opening it:

Below code is working properly and saving files but need to change the extension while saving .



Sub SaveLatestAttachment()
Dim olApp As Outlook.Application
Dim oMail As Outlook.MailItem
Dim NS As Outlook.NameSpace
Dim oFolder As Outlook.Folder
Dim SaveInFolderName As String
Dim SaveInFolder As String
Dim subFolderName As String
Dim strFile As String
Dim Item As Object
Dim Items As Outlook.Items
Dim x()
Dim i As Long

SaveInFolderName = CreateObject("WScript.Shell").SpecialFolders(16)
subFolderName = "EmailAttachments"
SaveInFolder = SaveInFolderName & "\" & subFolderName & "\"

Set olApp = New Outlook.Application
Set NS = olApp.GetNamespace("MAPI")
Set oFolder = NS.GetDefaultFolder(olFolderInbox).Parent.Folders("Test")
ReDim x(1 To oFolder.Items.Count, 1 To 4)
Set Items = oFolder.Items
Items.Sort "[ReceivedTime]", True
For Each Item In Items
    If TypeOf Item Is Outlook.MailItem Then
        Set oMail = Item
        If LCase(oMail.Subject) = "my daily report" Then
            If oMail.Attachments.Count > 0 Then
                For i = 1 To oMail.Attachments.Count
                    strFile = oMail.Attachments(i).FileName
                    If InStr(LCase(strFile), "my report") > 0 Then
                        MsgBox oMail.ReceivedTime
                        strFile = SaveInFolder & strFile
                        On Error Resume Next
                        Kill strFile
                 

Open in new window

0
Hi,

Please I need a script (powershell or VBs) to Assign 'Self' Permissions to allow user to modify self "home folder" in Active directory

I have a list of 150 users;

Example attached.ask.png
Thx
0
Hi Experts,

This Program is saving the attachments from Independent Outlook folder to My Dcoumnets "EmailAttchments" folder.


The issue is , loop is checking at every run the whole folder emails one by one , In that folder I will get daily one email that have same subject suppose " My Daily Report" and I need that the program check latest email only and save (overwrite) the latest attachment on destination folder and avoid checking the whole email folder.

Appreciate your help.


Public Sub SaveAttachments()
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim NS As Outlook.NameSpace
Dim srcOLFolder As Outlook.Folder
Dim i As Long
Dim lngCount As Long
Dim srcOLFolderName As String
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim subFolderName As String
Dim sFileType As String
Dim dtDate As Date
Dim sName As String
       
       
   ' Get the path to your My Documents folder
    strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)
    
    ' The attachment folder needs to exist
    ' You can change this to another folder name of your choice
    'Assuming  a folder called "Email Attachments" in your Document folder
    Set fso = CreateObject("Scripting.FileSystemObject")
    subFolderName = "EmailAttachments"
 
    '--------------------------------------------------
    'create the folder if it doesnt exists:
    Dim ttxtfile, txtfile, 

Open in new window

0
We are currently using an SSO kiosk software (Imprivata).  Windows automatically logs into windows using a shared AD account and then locks.  Individual users can then login with their own credentials to run software etc..  The problem is that when each user logs in, they do not have access to their home directory documents folder.  THe shared autologon account maps the AD drive throu GPO as it would for any other account on our network. The SSO software can incorporate VBS scripts during logon/logoff.

I am attempting to map their home directory folder, but having issue.  I can get all the way to the home$ folder, but not the username folder.  Attached is the script I am running.  It seems like there is something the system doesnt like about the %username% variable?

Option Explicit
Dim objNetwork, strRemotePath1
Dim strDriveLetter1
strDriveLetter1 = "M:"
strRemotePath1 = "\\cmc-vserver\home$\%username%"
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
Wscript.Quit
0
I am using namespaces for the first time in a Visual Studio project, following a sample project tutorial and am struggling to use them.
(I usually don't bother specifying namespaces but am trying to do things "by the book"!)

My basic problem is that Visual Studio's intellisense doesn't like me doing a VB Imports statement with just the namespace I specify - it wants me to add the project name to the namespace to validate my code.  When I do this, my code can build successfully but I then get problems further down the line. Before getting to solving these latter problems, I'd like to understand why this namespace/imports behaviour is different behaviour to that of the sample code I'm trying to emulate.

The sample project that I am working with is:
getting-started-with-aspnet-45-web-forms
The complication is that I'm using Visual Studio 2017 and I'm translating all of the code to VB as I go!

In my code, I am specifying a Namespace in a vb file as:
Namespace WingtipToys.Models

    Public Class Product

    End Class

End Namespace

Open in new window


...but when I want to use it in an Imports statement on codebehind for another page, intellisense is insisting that I include the project name (also "WingtipToys")
Intellisense not happy with my code without adding the extra namespace.Intellisense suggests I change it to
Imports WingtipToys.WingtipToys.Models.Product

Open in new window

0
Does anyone know of resources either in books or on the web, or does anyone have experience of using SCSI Pass Through / Direct using (ideally VB6).
I am interested in how to set up the IOCTL_SCSI_PASS_THROUGH / DIRECT without using .net I have tried some sample .net code and it is clunky and very slow.
0

VB Script

37K

Solutions

20K

Contributors

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.