Link to home
Start Free TrialLog in
Avatar of Wiretwisterz
WiretwisterzFlag for United States of America

asked on

Batch file to create VBS script

I have a vbs script that modifies the registry to change one setting for Adobe Reader and the script works fine on its own.  What I wanted to do, was to create a batch file, that created a Schedule Task (this part already works), then creates a VBS file on the root of the users C:\ drive, which the Scheduled Task that was created will use.

The working VBS script is this:

 
const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set StdOut = WScript.StdOut
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 

strKeyPath = "Software\Adobe\Acrobat Reader\9.0\Originals"
strValueName = "bBrowserIntegration"
strValue = "1"
oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
 
strValueName = "bBrowserIntegration"
dwValue = 1
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue

MsgBox "Adobe Reader was fixed"

Open in new window


The problem comes in when I'm writing lines to the vbs file in the batch file, when it encounters an &, everything that comes after it is blank.  I haven't found a way around this yet and hoping someone knows a simple answer.  This is what the batch file looks like.

@echo off
schtasks /create /ru Domain\UserName /rp * /sc ONLOGON /tn FixAdobe /tr "C:\FixAdobe.vbs"

Set VBS=%systemdrive%\FixAdobe.vbs

>> %vbs% Echo const HKEY_CURRENT_USER = &H80000001
>> %vbs% Echo strComputer = "." 
>> %vbs% Echo Set StdOut = WScript.StdOut
>> %vbs% Echo Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
>> %vbs% Echo strComputer & "\root\default:StdRegProv")
>> %vbs% Echo strKeyPath = "Software\Adobe\Acrobat Reader\9.0\Originals"   
>> %vbs% Echo strValueName = "bBrowserIntegration"  
>> %vbs% Echo strValue = "1"
>> %vbs% Echo oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
>> %vbs% Echo strValueName = "bBrowserIntegration" 
>> %vbs% Echo dwValue = 1
>> %vbs% Echo oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
>> %vbs% Echo MsgBox "Adobe Reader was fixed"

Open in new window


So on the first line.. the file gets created, but first line is missing the , &H80000001 part, the 5th line is missing "\root\default:StdRegProv") part.

Any ideas what I can do to fix this?
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wiretwisterz

ASKER

Excellent, thanks learned something new.