Solved

Need to modify a working VBScript to use variables

Posted on 2014-09-26
3
149 Views
Last Modified: 2014-09-26
Hello again everyone,

RobSamson was kind enough to author a VScript for me.
It works great and I am very pleased.

Here's what the short script looks like:
Set objShell = CreateObject("WScript.Shell")
strCommand = "cmd /c C:\BETASys\exf.exe  -c ""C:\BETASys\BETASys.md5"" > ""%USERPROFILE%\AppData\Local\Test\Intergrity_check_results.txt"""
objShell.Run strCommand, 1, True

Now, I should like to request a bit of help modifying RobSamson's work some. (If I might.)

The current script has three parameters:
The first parameter is the location and name of an executable that I want to run:
C:\BETASys\exf.exe  
The second parameter is the location and name of an input file, that the executble in the first parameter will use:
-c ""C:\BETASys\BETASys.md5
And the thrid parameter, is where to send the output when the executable defined in the first parameter is run.
> ""%USERPROFILE%\AppData\Local\Test\Intergrity_check_results.txt"""

Now for my issue:
The folder locations for the first two parameters could be different each time I run this script.

What I would like to do (if it makes sense) is ....
Early in the script, I will populate a variable with what I want the first parameter to look like.
And I'll do the same for the second parameter.
I have some VBScript skills and I can do this.

Assuming the first variable is named "var1" and the second, is named "var2", how would I use var1 and var2, in the current line of strCommand = "cmd /c C:\BETASys\exf.exe  -c ""C:\BETASys\BETASys.md5"" > ""%USERPROFILE%\AppData\Local\Test\Intergrity_check_results.txt""" ?

Does that makes sense ?
........
........
Yes.
Yes, I think it does.

Thank so very much for any replies.

Good morning.
0
Comment
  • 2
3 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 40346239
Try this:

Set objShell = CreateObject("WScript.Shell")
var1 = "C:\BETASys\BETASys.md5"
var2 = "%USERPROFILE%\AppData\Local\Test\Intergrity_check_results.txt"
strCommand = "cmd /c C:\BETASys\exf.exe  -c " & chr(34) & var1 & chr(34) & " > " & chr(34) & var2 & chr(34) 
objShell.Run strCommand, 1, True

Open in new window

0
 
LVL 1
ID: 40346408
And this worked perfectly.

You are the greatest !
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 40346627
Happy to help.  Thanks for the grade. :^)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now