Question

What I'm trying to create is a 2 part script. The first part of the script will search for the install path of an application and save it as the variable strValue. This part of the script works great. I would like the next part of script to launch a batch file from the location that is stored in strValue. This is the part that is tripping me up. I feel like I'm making this much more complicated than it needs to be. Please advise.

Here is my script so far:

Option Explicit

Dim strComputer, oReg, strKeyPath, strValueName, strValue, WshShell, ObjEnv, objExec,     strFolderPath, 


Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Greenshot_is1"
strValueName = "InstallLocation"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

'Uncomment the following line to verify the install location is chosen properly
Wscript.Echo "Current Install Location: " & strValue
'
''''''''''''''''''''''''''''''''''''''''''''''''
'run batch file from strValue location
Was it helpful?

Solution

Assuming that strValue contains the full path to the batch file, you could use the Run method:

CreateObject("WScript.Shell").Run """" & strValue & """", 0, True

The double quotes around strValue take care of paths with spaces.

If strValue contains just the path without the filename, you can construct the full path like this:

CreateObject("WScript.Shell").Run """" & strValue & "\batchfile.bat""", 0, True
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top