Solved

Trouble getting VBS code to work

Posted on 2014-09-15
5
281 Views
Last Modified: 2014-09-24
I am having trouble getting a VBS to run. Can someone take a look at line 8 and let me know how its supposed to be written? It doesn't error out but it doesn't run either.. Thank you.

Dim WshShell, fso
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell") 
GetTheParent = fso.GetParentFolderName(Wscript.ScriptFullName)
REM WshShell.Run "msiexec.exe /i ""SQLSERVER2012_AMO11x86.msi""", 0, True
REM WshShell.Run "msiexec.exe /i ""SQLSERVER2012_ASADOMD11x86.msi""", 0, True
REM WshShell.Run "cmd /c ""vstor40_x64.exe""", 0, True
WshShell.Run "msiexec.exe /i GetTheParent & ""\"" & ""name of.msi""", 0, True

Open in new window

0
Comment
Question by:prologic08
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40324112
You have to replace 'name of.msi' with the msi you want it to load
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40324162
You have missed some quotes from the front of the string, and too many in the middle.

WshShell.Run "msiexec.exe /i " & """ & GetTheParent & "\" & "name of.msi""", 0, True
0
 
LVL 12

Expert Comment

by:jkaios
ID: 40324183
What is GetTheParent? Is it a separate function in your script or is it a variable?  In either case, it seems to be part of the string and that's probably why nothing happens as expected.

Try this:

WshShell.Run "msiexec.exe /i " & getTheParent & "\" & """name of.msi""", 0, True
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40324210
What you are looking for is a command like this

WshShell.Run msiexec.exe /i "myfolderpath\myfilename.msi" , 0, True

Where myfolderpath is the full path to the file and myfilename is the file that you want to run.

In my initial post, this is what each bit does.

"msiexec.exe /i "  - start of command

""" - puts the " at the start of the filename

GetTheParent  - your variable that is the full path to the file. NB check that this is just the path and not the whole file name and does not end with a \. If it does the next bit is not needed.

"\" - Adds the backslash between the folder path and the filename

"name of.msi""" - Enter your actual file name. The """ at the end puts a final " in the whole string

, 0, True  - The end of the command.
0
 
LVL 12

Expert Comment

by:zalazar
ID: 40324230
You might want to change the GetTheParent line because if the script runs from the root of the drive it will return an extra backslash e.g. C:\   which will result in two times a "\" in the .Run command.
Using:
GetTheParent = Mid(Wscript.ScriptFullName, 1, InstrRev(Wscript.ScriptFullName, "\") - 1)

Open in new window

will return only e.g. C:  without a "\" for all script locations.
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Simple Linear Regression

726 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