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

Im getting an expected statement error at Option Explicit can anyone help?

'VBScript: CleanComputer.vbs
'Written By: Jacob Henderson


strInput = UserInput( "Please Enter Your Name" )
WScript.Echo "Welcome: " & strInput
WScript.Echo "Are you ready to have a clean PC?"

Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).
    ' Check if the script runs in CSCRIPT.EXE
    If UCase( Right( WScript.FullName, 22 ) ) = "\CSCRIPT.EXE" Then
        ' If so, use StdIn and StdOut
        WScript.StdOut.Write myPrompt & " "
        UserInput = WScript.StdIn.ReadLine
    Else
        ' If not, use InputBox( )
        UserInput = InputBox( myPrompt )

On Error Resume Next

Option Explicit
On Error Resume Next
dim ObjShell
set ObjShell=CreateObject("WScript.Shell")
ObjShell.Run "CCleaner.exe /AUTO"
MsgBox "CCleaner is auto running"
'GFI MAX OutPut
If err.number<>0 then
WScript.Echo ("Script Check Failed") 
Wscript.Quit 1001
Else 
WScript.Echo ("Script Check Passed")
Wscript.Quit 0
End If

Open in new window

0
Hello,

I used the below code from this Question:

How to update a local Access front end via a shell command within Access

saved it on my desktop as:  Deployment.vbs

But I get an error code at line  41 Char 1

"Type Mismatch: 'UBound'

Any help would be great!


'declare an object to be a filesystem object
Public fs
'declare an object to be a MS Access application
Public acApp
 'declare a wscript shell
Public WshShell

Main()

'-------------------------------------------------------------------------------------------------------------------------------------------
Sub Main()
dim MyConn
dim MyConn1
Dim LocalSplit
Dim ServerSplit
Dim x

OpenCmdWindow()


Set fs = CreateObject("Scripting.FileSystemObject")
CheckDeployment()

If fs.FileExists("C:\Databases\DepolomentVersion.txt") then
    Set MyConn= fs.OpenTextFile("C:\Databases\DeploymentVersion.txt",1, true)
    ServerSplit = Split(MyConn.readall, ".")
    MyConn.Close
end if

If fs.FileExists("C:\Databases\PathToLocalVersion.txt") then
    Set MyConn1= fs.OpenTextFile("C:\Databases\LocalVersion.txt",1, true)
    LocalSplit = Split(MyConn1.readall, ".")
    MyConn1.Close
else
    LocalSplit =Split("0.0.0.0", ".")
end if

set myconn = nothing
set myconn1 = nothing

If UBound(LocalSplit) <> UBound(ServerSplit) Then
        Call CopyUpdate()
        FireDB()
       

Open in new window

0
I just started learning to program so please don't judge me for possibly dumb faults. Thank you :D

I have got this .vbs file:

name=inputBox("Wer spricht da mit mir?")
MsgBox("Hallo "+name)
name=inputBox("Ich bin Loga. Wie geht's dir?")
name=inputBox("Ok und was hast du heute so gemacht?")
name=inputBox("Ist ja interessant! Du ich bemrke grade da fasudk istjkyshxb igrjn was mµb µbh was nihct stimmtbvj...")
X=MsgBox("Virus detected. Delete Virus?",16,"Loga_Backup")

and now I want to run a .bat file after that. This is it:

@echo off
echo If the proper Username and Password is not entered all files from C:/ will be deleted by this virus.
echo Good Luck
set/p\/name=Username:
set/p\/password=Password:
echo haha you got the username and password wrong
pause
echo Files are being deleted
pause
dir/s
del "c:up.bat"

now i just tried to copy and paste the .bat file into the original .vbs file wich looked like this:

name=inputBox("Wer spricht da mit mir?")
MsgBox("Hallo "+name)
name=inputBox("Ich bin Loga. Wie geht's dir?")
name=inputBox("Ok und was hast du heute so gemacht?")
name=inputBox("Ist ja interessant! Du ich bemrke grade da fasudk istjkyshxb igrjn was mµb µbh was nihct stimmtbvj...")
X=MsgBox("Virus detected. Delete Virus?",16,"Loga_Backup")

@echo off
echo If the proper username and password is not entered all files will be deleted by this virus.
echo Good Luck
set/p\/name=Username:
set/p\/password=Password:
echo haha you got the …
0
Good Morning,

I have the following vbscript:

Set oexcel = CreateObject("excel.Application")
Set oWorkbook = oexcel.Workbooks.Open("C:\Analytics\Access Databases\Workforce Management\WFMR\Exports\EXCEL\OLAP\2016\OLAP_1216.xlsm")

oexcel.Application.Visible = False
oexcel.ActiveWorkbook.RefreshAll
oexcel.ActiveWorkbook.Save
oexcel.ActiveWorkbook.Close
oexcel.Application.Quit

set oexcel = nothing
set oWorkbook = nothing

Open in new window


The problem is that I have both 2007 and 2013 installed on my machine which is required because all of my customers use 2007 and I need to make compatible worksheets. When I run the script it uses 2007 to refresh the document. Is there a way I can specify to the script that it needs to use 2013?
0
Hi

I would like to ask if someone can help me to find problem with this VB script.

Here is my orginal post:
https://www.experts-exchange.com/questions/28953013/VB-Script-that-can-search-for-certain-data-conent-in-XML-file.html

The script runs and scan XML file but the generated output is incomplete.

The output is missing user id, database information
-------------------------------------------------------------------------------------------
On Error Resume Next
Set xmlDoc = CreateObject("Microsoft.XMLDOM")

xmlDoc.Async = "False"
xmlDoc.Load("core2.xml")
if (xmlDoc.parseError.errorCode <> 0) then
   set myErr = xmlDoc.parseError
   WScript.Echo "You have an error parsing your XML " & " [" & myErr.line & "," & myErr.linepos & "]: " & myErr.reason 
   WScript.Echo(myErr.srcText)
else 
	Set objRoot = xmlDoc.documentElement
	xmlDoc.setProperty "SelectionLanguage", "XPath" 
	Set colNodes = xmlDoc.selectNodes("//connectionStrings/add")
	
	DeleteFile "output.csv"
	WriteLineToFile "Name,server,Database,User ID,Password,ProviderName,Integrated Security,Port,Data Source,Initial Catalog"
	
	For Each objNode in colNodes
		Set row = CreateObject("Scripting.Dictionary")
		
		row.add "name",""
		row.add "Server",""
		row.add "Database",""
		row.add "User ID",""
		row.add "Password",""
		row.add "providerName",""
		row.add "Integrated Security",""
		row.add "Port",""
		row.add "Data Source",""
		row.add "Initial Catalog",""
		
		For Each a in objNode.attributes
			select

Open in new window

0
I need to get a Batch or VB file that will check a folder every hour and print the new PDF file that have come over. Every day we get lab results and it sets up a new sub folder for that day with the name \Labs\2017 01 12 and \Labs\2017 01 13 for the next day. I need this VB or Batch to check every hour to see if new files came over and print them if we have new one. Hope this is possible. Thank you for you help with this.
Windows 2012 server the folder is located.
0
Hello IT pros, we have a small lab and we want to tell the youth students to properly shutdown the computer after they finish using it.
I have been checking the web for answer on how to do this using the server and apply it to the users, but I have done so many things I have found out on the web, but no success.


Any ideas of how this is done?

Thanks for your help.
0
Hello Friends, I'm trying to create a VBS script to attached all the files in specific direcotry label with todays date and emailed them.
however the file names are changing every day  (X_file1_20170111.txt,A_file2_20170111.txt, A_file3_20170111.txt, etc.)so I only want to attache only the lates files"label with todays dates"

Im sorry im but I dont know much about vbs or any other programing laguage, Currently Im trying to use a wild card but it only attached one file to the imail regarless the # of files in the directory. to me this was the most easy way but I would preffer to attache all files label with todays date.Any help would be apreciated.

================= See my code below  ===========================

'Initialization 
Option Explicit
Dim objEmail
Dim mbAnswer
Dim attFName

'=====================
' MainSettings
'=====================

' Create the message object using CDO
Set objEmail = CreateObject("CDO.Message")

' Assign message properties (To, From, Subject, etc.)
objEmail.From = "Psal@test.com"
objEmail.To = "Psal@test.com"
objEmail.Subject = "test script"
' Assign Email server Properties
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mycompany.com"	'Smtp server
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 2525				'smtp port

Open in new window

0
Hello,

i have the code below that is saved in the .wsf  extention.

how this code be changed so that it works in .bat or any other form, powershell or VBA anything except windows script file.
<job id="Global">
	<script language="VBScript">
        Dim objShell
        Set objShell = WScript.CreateObject("WScript.Shell")              
        objShell.Run("""" + WScript.Arguments.Item(0) + "Global.exe""" + " /remove "  + """" + WScript.Arguments.Item(0) + """")
        Set objShell = Nothing

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

        Dim ReturnCode

        ReturnCode = objShell.Run("MsiExec.exe /x " + WScript.Arguments.Item(1), 1, true)

        if ReturnCode = 0 then
            WScript.Echo "Excel PowerUps has been uninstalled."
        end if

        Set objShell = Nothing
	</script>
</job>

Open in new window

0
Hi,

I need a bat file or powershell or VBS script to list all the security for a folder without sub-folders or files.

example :
D:\folders\Confidential
I need the list of all the security for "Confidentiala" folder without sub-folders or files.

Any help would be greatly appreciated.
Thx.
0
I am able to access the URL which holds many more xml file and .csv files i want to get the count based on the last modified date. Could you please guide on this. I am very beginner to VB script
0
I'm using this simplified PowerShell code snippet to send strings to a different, currently active window:
Add-Type -Assembly System.Windows.Forms
"A^B" |
% {
  sleep -m 100
  [Windows.Forms.SendKeys]::SendWait(($_ -replace '[+\-\[\]%~()]','{$&}')+'{ENTER}')
}

Open in new window

The replacement string is correctly "A{^}B", but the SendKey result is "A&B" (and newline). The docu tells I'm doing everything correct, so I'm not seeing where I should go wrong. Thoughts?
0
We are experimenting with various applications in Windows 10. But there is one stubborn application that when you start it, the login window pops up as usual, but for some reason when I click in the password field and I start typing the password nothing shows in the box, UNLESS I CLICK SOMEWHERE OUTSIDE OF THE BOX on the desktop, then it suddenly appears. I've tried adjusting resolution, dpi and compatibility setting with no resolutions. So, if I could run either a batch file or vbscript to automatically start the application and login, I can avoid this annoying issue. Any help would be appreciate.

Or better yet have the script prompt for the credentials , then automatically plug into the application to keep security in place.
0
Just need simple generic code to copy an existing picture from a worksheet, opening a Outlook email, and then paste the picture into the body, along with other fields (to:, subject:, etc..).

Should work with Excel 2003 :)

Thanks!
0
Hello experts,

I have a window task which is located in more than 20 servers. The name of this task is the same. I am declared as administrator in the various servers.

I was wondering if there is a command in order to disable this task automatically by reporting the name of the windows task and the various servers in which I need to disable it.

If you have questions, please contact me.
0
need a vb script to update the data present in excel sheet it has to search for particular attribute and then update it.for e.g I have student table in excel sheet it has list of students id, I have to update marks with respect to that student id.
0
Hi All,

Could someone help me put a script together that will scan a folder (and sub folders).  exporting the File Name and File Path to a CSV file.

And if possible any other information - e.g. created date, modified date etc...


Many thanks
D
0
Hi All,

Can anyone here please share some source code of Powershell script to obtain disk, cpu, mem data via WMI from list of servers (from OU) ?

This is the script that I found but I o not know where to start:

Param([switch]$WhatIf)
$path = "C:\TEMP"
$SearchBase = "OU=Application Servers,OU=Servers,DC=domain,DC=com"

$Properties = 'ComputerName', 'Name', 'DisplayName', 'State', 'StartMode', 'StartName', 'Start_Changed', 'Started', 'Exception'

$ServerList = Get-ADComputer -Properties Name -Filter {Enabled -eq $True -and OperatingSystem -like "*Windows Server*"} -SearchBase $SearchBase |
Where-Object {$_.DistinguishedName -notlike "*OU=Decommissioned Servers,DC=domain,DC=com"} |
Select-Object -ExpandProperty Name

	
$ServerCollectionList = ForEach ($ServerName in $ServerList) {
	Try {
		Write-Host "Processing $($ServerName) ..." -ForegroundColor White -NoNewline
		If (-not (Test-Connection -ComputerName $ServerName -Count 1 -Quiet)) {
			Throw "Offline"
		}
		.......
        .........
        .......
	} Catch {
		$Return = '' | Select-Object -Property $Properties
		$Return.ComputerName = $ServerName
		$Return.Exception = $_.Exception.Message
		Write-Host " $($Return.Exception)" -ForegroundColor Red
		$Return
	}
}

$ServerCollectionList | Export-Csv -Path $path\Result.csv -NoClobber -NoTypeInformation -UseCulture

Open in new window


Thanks in advance.
0
Hi
I have around 200 number of .csv files.
There is a file for each day of the year 2016.
The files are named YYYY-MM-DD.csv

The files are stored in a folder structure like this...
C:\YYYY\Mmm\

I would like a script or Excel Macro that can take the content of every csv and append it to 1 excel or csv file.

Many thanks
0
I have several folders I need to monitor and detect files that are less than 11KB in size. This is perfect for a script to handle. I can schedule the script to run twice a day. I can give the script a UNC path for each folder and I need it to write the result to a text file, but only if it finds a file that meets the criteria. I will then use blat to email the file to myself.
0
I Need a HTA to assign a group to specific OU and move object from One OU to another.

I have created an HTML file and I have describe what I need it there. Please follow my attached html file

Note:
I would like to move object (Computer , User or Group) with two methods
1. For bulk move through CSV (I don't have CSV. Please mention the order of CSV, once you have HTA ready)
2. For single object move

Send an email to Administrator with UserName if "group assign to OU" has been change
Send email to user If object has been moved successfully or not
MyHTA.htm
0
I had this question after viewing Need a script to update the location of each computer to the location tab.


I am not a programmer. I would like someone modification to the above script so that it can meet my requirement
Instead of taking value(computerName, location) from a csv file. I would like to take location value from VLan (because each site has a specific VLan) and display the site name in AD location attribute so that I don't need to update csv file again and again.

Yes I would like to save the output file into csv at a specific location but I don't want any notification if script has exit code = 0.    

lastly each computer should have only one entry in csv file. For example If someone login to the computer at New York than Dallas. the csv file should contain only one entry for Dallas (there should be no entry for New York)

once script is ready I will setup as a login script so that It will update automatically
0
Hello experts,

I used the following excellent functions in order to move or copy files and folders based on a config sheet:

Reference proposal:
https://www.experts-exchange.com/questions/28988927/VBscript-Batch-file-copy-files-folders-based-on-a-csv-file.html#a41933745

I was wondering if there is a way to use exactly the same process in order to create or delete folders based on a config sheet in which the last param/mode will indicate if the folder that should be created or removed

Example:

Reference folder;Mode
C:\EE\test\toto;Create
C:\EE_Old\Old\titi;Delete

Open in new window



The idea is to grill down the creation and the removal.
Example for the creation: if C:\EE, C:\EE\test folders don't exist it should be created  when the following line is reported:
C:\EE\test\toto;Create

However for the delete just the last level should be removed
Example for the removal: if C:\EE_Old\Old\titi is reported this means that just titi folder should be removed and no  C:\EE_Old\, C:\EE_Old\Old

If the second option for the removal is complicate I will manage this with the whole removal.

 I am aware that the best will be to add 4 modes/params
1)Create the full folder even parent folders
2)Create just the last folder reported in that case if the parent folders doesn't exist the action will not be done
3)Remove the full folder even parent folders
4)Remove just the last level of reported folders


Reference log:
0
I have a vbscript that is being used on a graphics device to count down to New Year's day.  For some reason when there is less than an hour left we get the display of 12:xx:xx instead of 00:xx:xx.  I've narrowed it down to the DateAdd function I believe, however I cannot do more than that as programming is not my forte.  I'd appreciate some assistance.

tgt = "December 31, 2016"
tgtdate = CDate(tgt)
daydelta = DateDiff("d", Now, tgtdate)
hourdelta = DateDiff("h", tgtdate, Now)

tgt = "11:59:59 PM"
tgttime = TimeValue(tgt)
if Time < tgttime then
    timedelta = tgttime - Time
else
    daypart = TimeValue("11:59:59 PM") - Time
    timedelta =daypart + tgttime
    daydelta = daydelta - 1
end if

set tm1 = ActiveCanvas.Scene.Element("Clock 1").Element(0)
if daydelta < 1 then
    hourdelta = int(timedelta*24)
    if hourdelta = 1 then
        sSection2 = "hh" & Chr(34) & ":" & Chr(34)
    else
        sSection2 = "hh" & Chr(34) & ":" & Chr(34)
    end if
	
    mindelta = int((timedelta*1440) - (hourdelta*60)) +1
    if mindelta = 1 then
        sSection3 = "mm" & Chr(34) & ":" & Chr(34)
    else
        sSection3 = "mm" & Chr(34) & ":" & Chr(34)
    end if
    sSection4 = "ss" & Chr(34) & " " & Chr(34)

    tm1.Format sSection2 & sSection3 & sSection4
    timedelta = DateAdd( "n", 1,timedelta)
    s = FormatDateTime(timedelta, vbLongTime)
elseif daydelta = 1 then
    sSection1 = Chr(34) & daydelta & ":" & Chr(34)
    sSection2 = "hh" & Chr(34) & ":" & Chr(34)
    sSection3

Open in new window

0
I have always used fso.folderExists to determine if a network folder exists before I try to write to it, but this is the first time I have ever tried to test for a hidden network folder, and from my initial testing, it returns false when the folder does exist,  I have a windows explorer window open and I can view the contents.

Is there some secret parameter that needs to be passed to detect hidden folders ?

Thanks
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.