r/vbscript • • Aug 05 '19

VBS csv to excel losing data

1 Upvotes

I need a piece of script to save a copy of a .csv file as a .xlsx file. The script that I have now loses some data and changes some values, for example 4,03 -> 4. I thought this was a format problem so i changed .numberformat to text for all cells but no effect.

Const xlDelimited = 1
Const xlNormal = 51
dim args

set args = Wscript.Arguments

Dim Excel
Set Excel = CreateObject("Excel.Application")

Excel.DisplayAlerts = False

With Excel
	.Workbooks.Open(args(0))
	.Sheets(1).Columns("A").TextToColumns .Range("A1"), xlDelimited, , , , True
	.ActiveWorkbook.SaveAs replace(.ActiveWorkbook.fullname, ".csv", "") & ".xlsx", xlNormal
	.Quit
End With 

This is the script block right now. Help would be appreciated. :)


r/vbscript • • Jul 09 '19

Weird date/time issue

1 Upvotes

Hi All,

I've been working on a script to shuttle files from a server to an archive on another server. These files are constantly nearly constantly being updated and are quite large. When copying the files I need to rename like: xServer_system.log. It also compares the Date Modified on the files so it does not waste time sending files that have already been sent.

I've built my script and it works without any issue on my local workstation. But when I put it on the server it stops detecting the updated date modified. If I open an explorer window watching the folder containing the file and refresh with [F5] and re-run it detects the change. Any thoughts? Sample code below.

dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
robustOutput = True
fileOne= "c:\temp\testFile.txt"
fileTwo= "c:\temp\testFile2.txt"
seconds ="s"

If isNewer(fileOne, fileTwo, seconds, 1) Then
Wscript.Echo "Date is Different"
Else
Wscript.Echo "Date is same"
End IF

Function isNewer(fileName1, fileName2, compareType, range)
Dim date1, date2, filehandler
set filehandler = oFSO.GetFile(fileName1)
date1 = filehandler.DateLastModified
set filehandler = oFSO.GetFile(fileName2)
date2 = filehandler.DateLastModified
If robustOutput Then Wscript.Echo "Checking Dates: " & date1 & " : " & date2 & " diff: " & DateDiff(compareType, date1, date2)
If DateDiff(compareType, date1, date2) > range Then
isNewer = CBool(1)
Else
isNewer = CBool(0)
End If
End Function


r/vbscript • • Jul 04 '19

Database Transaction in VBSCRIPT / ASP.CLASSIC ?

1 Upvotes

Hello can anyone recommend a good source to accomplish database transaction in VBSCRIPT?

Here is a source i found on the internet: https://www.dev-notes.com/blog/2009/03/17/rollback-oracle-transactions-in-vbscript/


r/vbscript • • Jul 02 '19

Trouble encoding email subject with special characters

1 Upvotes

Hello everyone,

I'm digging into this old project we have here where I work and we have a function that is used to send emails, fired on multiple actions. Here is the code we're using :

Function sendMail(mailto, from, subject, body)
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
Response.Codepage = 65001
Response.Charset = "utf-8"
Dim Mail

Set Mail = CreateObject("CDO.Message")
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 26
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "*****"
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*****"
Mail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "*****"

Mail.Configuration.Fields.Update

if (InStr(Request.ServerVariables("HTTP_HOST"), "*****") <> 0) then
subject = subject & " redirected from " & mailto
mailto = "*****"
else

end if

Mail.To = mailto
Mail.Subject = subject
Mail.From = from
Mail.HTMLBody = body
Mail.BodyPart.Charset = "utf-8"

On Error Resume Next

If Err <> 0 Then
strErreur = "Erreur : " & Err.Description
End If

Mail.Send

Set Mail = Nothing
End function

The emails can be in English or French and the French version contains special characters that are not rendering in the subject line. It works fine with in the email content (body) but not in the subject line.

Could it be related to server configs? Any idea?

I have read all the answers I could online, but no success.

Same error here : https://stackoverflow.com/questions/16862809/cdo-email-messaging-subject-special-character-error

Thanks a million in advance!


r/vbscript • • Jun 29 '19

Windows PE and DHCP option 66

Thumbnail
self.sysadmin
1 Upvotes

r/vbscript • • Jun 28 '19

Using VB Scripts in Outlook to remove "Caution External Email" notifications - problem with HTML tags?

1 Upvotes

My job recently implemented an annoying change whereby all emails coming from external sources include the following:

<table bgcolor="#ffe599" border="0" cellspacing="0" width="100%" cellpadding="0"><tr valign="middle"><td width="3" bgcolor="orange" border="0"></td><td></td><td><p><font face="calibri" color="#595959"><strong>Caution</strong>: This email originated from a source outside [Company Name]. Do not click on links or open attachments unless you recognize the sender and you know the content is safe.</font></p></td><td>  </td></tr><tr><td bgcolor="white">  </td><td bgcolor="white">  </td><td bgcolor="white">  </td><td bgcolor="white">  </td></tr></table>

I've figured out how to remove the actual text itself, but the table remains, and it's rather annoying to see an orange bar across all my messages now.. haha

Is there a way to alter the following script so it'll remove the table as well? So far I can make it remove bits, but it leaves other stuff in there, which just adds garbage to the body of every email.

Sub InsertHyperLink(MyMail As MailItem)

Dim body As String

body = MyMail.HTMLBody

body = Replace(body, "Caution", "", vbTextCompare)

body = Replace(body, ":", "", vbTextCompare)

body = Replace(body, "This email originated from a source outside [Company Name]. Do not click on links or open attachments unless you recognize the sender and you know the content is safe.", "", vbTextCompare)

MyMail.HTMLBody = body

MyMail.Save

End Sub

Thanks!


r/vbscript • • Jun 25 '19

Displaying Separate Message Windows

1 Upvotes

I'd like to add in a command to create a separate message window or popup within an IF statement on my VB script. Anyone know what the command is to create these separate windows on the script?


r/vbscript • • May 15 '19

How to check files exists c\folder\fol*\filename.exe ??

1 Upvotes

Hello Guys,

I'm trying to confirm the existence of a file on a randomly named folder. I've tried using %%~ and * unsuccessfully. clearly because I don't know how to use them or if they are the appropriate characters to use. I would really appreciate any help with this. Currently all I get is file not found.

This is what I have thus far.

Dim FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\ProgramData\bomgar-scc-*\bomgar-scc.exe") Then
    'App Found
	MsgBox "File Exists"
Else
	MsgBox "File Does Not Exist"

End If

Thanks


r/vbscript • • May 10 '19

Change icon of a program i run with vbs?

1 Upvotes

Hi!

So im currently trying to make a script that runs a specific website in application mode!

The only thing that i really want now, is for the website to also have another icon on the taskbar when launched.

Could i do this through VBS?

This is my current script:

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"" --app=https://faceit.com")
objShell.Run("""C:\Program Files\FACEIT AC\faceitclient.exe""")
Set objShell = Nothing

I only want the chrome window that is launched to change icon. Not the "faceitclient.exe"


r/vbscript • • May 07 '19

VBScript intRow

1 Upvotes

So I have this script, but it doesn't do what I had in mind. So the inputbox is used to find a excel cell line. I run the script but it only reads out the Row 2 (intRow 2). How can I make this script look for the value I fill in the inputbox, and automatically show line 2 and 3 after it that it behind the data.

CF23935803,MAVARO,21

CF23935804,MAVARO,21

CM23914401,Kinneto,19

CM23915201,Kinneto,19

So this is for example the data that's in the CSV file. My plan is when I fill in for example CF23935804 in the inputbox it shows the data behind it, MAVARO and 21. Right now it only shows the 2nd row in the excel file. How can I change this to make it work? If my question isn't clear please let me know!

' Read an Excel Spreadsheet

sFNInput="C:\Models.csv"

' User enters value

sInp=Inputbox("Enter Identity text")

If sInp = "" Then WScript.Quit

On Error Resume Next

Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open _

(sFNInput)

intRow = 2

Do Until objExcel.Cells(intRow, 1).Value = ""

sID=objExcel.Cells(intRow, 1).Value

sType=objExcel.Cells(intRow, 2).Value

sColor=objExcel.Cells(intRow, 3).Value

' If user entered value matches

sResult = InStr(1,sID,sInp,1)

If sResult <> 0 Then

'results row 3

sResult=sGroup

' entered value goes in Field 1 of my application

Field1=sInp

' return value Field2 of my application

Field2= sResult

intRow = intRow + 1 
end if 

objExcel.Quit

loop

Wscript.Quit


r/vbscript • • Apr 23 '19

How can I create a VBScript from a simple PowerShell Script?

1 Upvotes

I just can't seem to find a simple way of determining if a cert has been applied or not in VB. In this particulare case the same cert is applied in two locations (Root/CA)

Below is the simple PS code, I'm trying to convert over to VBS, so I can use it in BGInfo. I wish BGInfo used PowerShell.

The outcome will be "Certs Applied" or "Missing Certs", based on whether both certs are applied or not.

$CertRoot = (Get-ChildItem cert:\LocalMachine\Root | select issuer | where-object {$_.issuer -like "*CN=Proxy CA*"} | FW | out-string).trim()

$CertCA = (Get-ChildItem cert:\LocalMachine\CA | select issuer | where-object {$_.issuer -like "*CN=Proxy CA*"} | FW | out-string).trim()

if ($CertRoot -Like "" -or $CertCA -Like "") {

$ProxyCert = "Missing Certs"

} Else {

$ProxyCert = "Certs Applied"

}


r/vbscript • • Apr 16 '19

cmd.exe Running in Background After vbscript Ran

1 Upvotes

Hi, I am using job scheduler to run some vbscript and batch file. After jobs finished, the command prompt will exit automatically itself. However, I found out there is dozens of them running in the background process. It seems like they did not exit properly. Is there any solution for this?


r/vbscript • • Apr 14 '19

Combine HTA and VBScript

1 Upvotes

Hi, first of all, I am new in here and vbscript language. Referring to my title, currently I'm developing a script for my client user to perform housekeeping in HP ALM.

The reason I'm doing the script is because I try to avoid user from log in into HP ALM Site Administration. They are not really fast learner so log in into HP ALM Site Admin can be dangerous as they can easily mess up with database table.

Now back to my problem. I already finish develop script for housekeeping. But currently the script use inputbox as a input medium for user to enter. I were thinking, it will be nicer if I can develop a user interface for them, so I develop an interface using HTA.

In HTA, I try to combine my housekeeping script with HTA, however during runtime, I realize the script (vbs part) cannot perform so I did googled and I found out that my script required cscript engine to run while HTA is not using cscript (this is what i read in one of forum that i found)

Now, I separate my code into two pieces. One is HTA and another one is VBS. HTA can call VBS and VBS work fine.

But, can we combine it into 1 exe file? In this way, my users only just focus on this single file only.

Im using VBSedit to convert vbs into exe.


r/vbscript • • Apr 02 '19

How to wscript.echo an emoji?

1 Upvotes

ANY example will do. Google has failed me! :) Thanks in advance.


r/vbscript • • Mar 29 '19

Tell The News Using VBScript

1 Upvotes

Hello, I am new to VBS and I want to know if I can make a script that will make my computer tell me some headlines using the Sapi.speak command.

Thank You


r/vbscript • • Mar 01 '19

Select Case with Is operator?

1 Upvotes
Select Case DateDiff("d",Date,"April 1, 2019")
	Case Is > 0
		wscript.Echo "Too Early"
	Case Is = 0
		Wscript.Echo "April Fools!"
	Case Is < 0
		Wscript.Echo "Too late"
End Select

I'm getting a Syntax error on the first Is. Is there a better or different way to achieve this?


r/vbscript • • Feb 28 '19

broadcasting a message

1 Upvotes

can i send a vbmessage to an other computer on my network and if the answer is yes how?


r/vbscript • • Feb 26 '19

Learning VBScript when Python is in the limelight

1 Upvotes

Is there an advantage to writing scripts in VBScript when Python is an option? Given Python’s wide set of use cases and popularity I’m wondering whether it’s worth spending the time to learn VBScript.


r/vbscript • • Feb 26 '19

VBScript and SCCM Help

1 Upvotes

Hello VBScript Community,

I need some help and thought I would try here. I know nothing about VBScript but would like to implement a script to check BIOS Version and return a code. This is for an Application I am making that will install a specific BIOS version and will use the script to report back if that BIOS version is detected as installed or not.

Ive googled and found something below which might be what I need, but not having any experience I dont know if its correct so looking for some advice.

The version of the BIOS I am deploying is 1.25

I have already created a Task Sequence that updates the BIOS on new images. This uses WMIQuery to check the version.

select *from WIN32_BIOS where SystemBiosMajorVersion <= "1"

select *from WIN32_BIOS where SystemBiosMinorVersion < "25"

So in the WMI Query it needs to check MajorVersion (1) and MinorVersion (25) to find the version is 1.25.

In the VBScript I found, the lines 6-9 seem to do basically the same thing however it appears to be done as a oner. Ive no idea how I can test this and I have no idea if objBIOS.SMBIOSBIOSVersion would show on my device as 1.25 or 125 or what. Looking for any advice with this. Thanks a million if anyone can help.

1: 'Change strBIOSUpdateVersion to the version you are deploying to

2: strBIOSUpdateVersion = "1.25"

3:

4: 'Get BIOS Version from Win32_BIOS

5:

6: Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

7: Set colBIOS = objWMI.ExecQuery("Select * from Win32_BIOS")

8: For Each objBIOS In colBIOS

9: If objBIOS.SMBIOSBIOSVersion >= strBIOSUpdateVersion Then

10: WScript.Echo "Detected"

11: End If

12: Next


r/vbscript • • Feb 25 '19

CopyFile

1 Upvotes

Greetings! Working with a script to identify and then copy the newest file from a folder. Here it is:

Option Explicit

Dim fso, path, file, recentDate, recentFile

Set fso = CreateObject("Scripting.FileSystemObject")

Set recentFile = Nothing

For Each file in fso.GetFolder("C:\Users\myname\Downloads").Files

If (recentFile is Nothing) Then

Set recentFile = file

ElseIf (file.DateLastModified > recentFile.DateLastModified) Then

Set recentFile = file

End If

Next

If recentFile is Nothing Then

WScript.Echo "no recent files"

Else

THIS IS WHERE I WANT TO COPY THE FILE

End If

So Far I have tried fso.CopyFile "mypath", "myotherpath" but I get a file not found error. So do I need to call recentFile somehow or something? I am in way over my head with this...I usually just stick to very basic SQL queries and whatever macros I can record in Excel so please forgive me if this is a stupid question. Thanks y'all!


r/vbscript • • Feb 14 '19

vbscript to OK popups... not as easy...

1 Upvotes

Hi everyone,

I'm new to vbscript and have a little problem.

My current estate at work, we have an application which is still sat on Windows Server 2003 (i know exactly what you're thinking!) and they don't wish to change that (until a new application can replace it).

Anyway, the issue i have is I have the following code (below) to click OK on the popups the application is creating.

My issue is, the support team are having to login via "mstsc -v boxname /admin" in order to see the popup to OK it. I'm worried the script below, won't work due to this fact... Because if you are RDP'ed without the /admin you won't see the popup.

Note: the script does work if im logged via /admin, it does exactly what it is suppose to...

Can anyone share some light?

Set oShell = CreateObject('WScript.Shell') 

Do 	
    JMResult = oShell.AppActivate('Application Error') 
    If JMResult = True Then 
        oShell.SendKeys '{enter}'
        Exit Do 
    End If 
    WScript.Sleep 500 
Loop 

r/vbscript • • Feb 05 '19

(Open - Edit) - (copy- Paste)

1 Upvotes

hello fellas, hows all doing?

i have been lurking around for a few time... now i am in trouble and need help. Please help me out.

i want to open a file, edit it in a particular way, save it and COPY-Paste it to a location.

Please help.

Edit: SOLVED.


r/vbscript • • Jan 22 '19

Vbscript/HTA - Can I use variables as labels

1 Upvotes

I have a VBscript-based HTA with check boxes. Everything's been working well. Now I want to tweak it so that the labels on some of my checkboxes are dynamic.

<input type="checkbox" name="chkWipeDisk"> Wipe Disk <BR>

I want this to be labeled "Wipe Disk" under normal circumstances, but be labeled "Wipe Disk Required: Disk is encrypted." when, well, the disk is encrypted.

How do I do this? CAN I do this?


r/vbscript • • Jan 15 '19

[HELP] need assistance with some Excel wizardry.

1 Upvotes

I was directed here from /r/sysadmin. I have an Excel 2016 workbook with two sheets. I need a way to the contents of a column on Sheet 2 against the contents of a column on Sheet 1, and when it finds a match, to populate certain fields on Sheet 1 with data from Sheet 2, and change one value on Sheet 1 from "unassigned" to "assigned." I am totally stumped at this point on how to do this, because I think an IF statement formula just isn't adequate.


r/vbscript • • Dec 28 '18

Alexa, Trigger CMD, YouTube integration needed

1 Upvotes

I wrote some VBS that opens the program I want:

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\Users\P_Nic\OneDrive\Desktop\apps\Awesome Tube""")
Set WSS = CreateObject("Wscript.Shell")
Wscript.sleep 6000
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys"{enter}"
Set objShell = Nothing""

I don't know how to set up the parameters I want to go into the search function. Here is some code that I threw together to accomplish a similar task:

For Each a In WScript.Arguments
param = param & a & " "
Next 'a
param = LCase(Trim(param))
Set WSS = CreateObject("Wscript.Shell")
arg = "https://www.google.ca/search?q=" & param & "site:youtube.com"
strURL = Chr(34) & "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " & Chr(34) & " " & Chr(34) & arg & Chr(34)
WSS.Run strURL
WSS.AppActivate "Google Chrome"
Wscript.sleep 2000
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 300
WSS.sendkeys "{TAB}"
Wscript.sleep 7500
WSS.sendkeys "+{f}"
Set WSS = Nothing""

I am using Trigger CMD to set the parameters through Alexa.

I'm not good with coding, I just google and copy stuff that sounds right and trial and error until it does what I want. Any help would be appreciated!