Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I code this BAT into VBS? 2

Status
Not open for further replies.

SHardy

Programmer
May 9, 2001
231
0
0
GB
Hi,

I am in the process of setting up a new Business Objects repository, as a replacement for the existing one. This needs to be rolled out to all of our Business Objects users as transparently, and as smoothly, as possible.

I started writing a script to update all the necessary files on each users local machine. This was done as a BAT file. However, the users will also need a new ODBC system DSN setup. I found a way to do this via VBScript. S onow I have two different script files.

I would like to tidy these up into a single script. As such, I would like to know how the BAT file would need to be written in VBScript to produce the same results.

The current scripts are as follows:

1 - VBScript to create new DSN:

Dim oWshShell
Const cRegKey1 = "HKLM\Software\ODBC\ODBC.INI\BORep\"
Const cRegKey2 = "HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources\"

Set oWshShell = CreateObject ("WScript.Shell")

oWshShell.RegWrite cRegKey1 & "Driver","C:\\WINDOWS\\System32\\sqlsrv32.dll"
oWshShell.RegWrite cRegKey1 & "Server","MAINT34"
oWshShell.RegWrite cRegKey1 & "LastUser","BOREP"
oWshShell.RegWrite cRegKey1 & "Description","Business Objects Repository"

oWshShell.RegWrite cRegKey2 & "BORep","SQL Server"

set oWshShell = Nothing


2 - BAT file to delete and copy Bus Obj files:

REM Update local files to redirect Business Objects to the new repository

REM ** rename the old LSI files **

rename "%userprofile%\Application Data\Business Objects\Business Objects 6.0\lsi\*.lsi" *.old

REM ** copy the new shared connections **

copy G:\BIS\Update\sdac.lsi "%userprofile%\Application Data\Business Objects\Business Objects 6.0\lsi\"

REM ** rename the old BOMAIN.KEY file **

rename "C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\bomain.key" bomain.old

REM ** copy the new BOMAIN.KEY file **

copy G:\BIS\Update\bomain.key "C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\"

REM ** clear out all previously downloaded universes **

rmdir /S /Q "%userprofile%\Application Data\Business Objects\Business Objects 6.0\universes\Universe\"

del /Q "%userprofile%\Application Data\Business Objects\Business Objects 6.0\universes\*.*"



Any help with this would be greatly appreciated.


Many thanks,
Simon
 
OK, thanks for this. I have made an attempt at scripting the whole thing in VBScript. However, I get a runtime error as follows:

Line: 19
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error

I am assuming that this is because I cannot use the %USERPROFILE% variable? How would I reference this environment variable within VBScript?

FYI, my (error producing) code is as follows:


Dim oWshShell
Const cRegKey1 = "HKLM\Software\ODBC\ODBC.INI\BORep\"
Const cRegKey2 = "HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources\"

Set oWshShell = CreateObject ("WScript.Shell")

oWshShell.RegWrite cRegKey1 & "Driver","C:\\WINDOWS\\System32\\sqlsrv32.dll"
oWshShell.RegWrite cRegKey1 & "Server","MAINT34"
oWshShell.RegWrite cRegKey1 & "LastUser","BOREP"
oWshShell.RegWrite cRegKey1 & "Description","Business Objects Repository"

oWshShell.RegWrite cRegKey2 & "BORep","SQL Server"

set oWshShell = Nothing

DIM fso
Set fso = CreateObject("Scripting.FileSystemObject")

fso.DeleteFile("%USERPROFILE%\Application Data\Business Objects\Business Objects 6.0\lsi\*.lsi")

fso.DeleteFile("C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\bomain.key")

fso.CopyFile "G:\BIS\Update\sdac.lsi", "%userprofile%\Application Data\Business Objects\Business Objects 6.0\lsi"

fso.CopyFile "G:\BIS\Update\bomain.key", "C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData"

fso.DeleteFolder("%userprofile%\Application Data\Business Objects\Business Objects 6.0\universes\Universe\")

fso.DeleteFile("%userprofile%\Application Data\Business Objects\Business Objects 6.0\universes\*.*")



regards,
Simon
 
Get the profile string:
Code:
strProfile = oWshShell.ExpandEnvironmentStrings("%USERPROFILE%")

Should yield a string like:
"c:\documents and settings\username"

Modify your line like so:
Code:
fso.DeleteFile(strProfile & "\Application Data\Business Objects\Business Objects 6.0\lsi\*.lsi")

I think that's all you should have to do.
 
Hi,

Thanks for the help. It's now recognising the path correctly. However, it does not seem to be using the wild card for the delete (*.lsi). The files are not being deleted. It is overwriting over one of them with the file copy, but the others are still there.

Have I used the correct method of using a wild card to delte multiple files?

Thanks,
Simon
 
Ok, I got to the bottom of that one. BAT files & VBScripts have opposing ideas about when yuo do or don't need a "\" in a path.

The following is my final code, and it works a treat. Many thanks for all your help.

Simon

Final code:

'Update local files & settings to redirect Business Objects 6.5 to the new repository

'*** Create new System DSN required (BORep) ***

Dim oWshShell
Const cRegKey1 = "HKLM\Software\ODBC\ODBC.INI\BORep\"
Const cRegKey2 = "HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources\"

Set oWshShell = CreateObject ("WScript.Shell")

oWshShell.RegWrite cRegKey1 & "Driver","C:\\WINDOWS\\System32\\sqlsrv32.dll"
oWshShell.RegWrite cRegKey1 & "Server","MAINT34"
oWshShell.RegWrite cRegKey1 & "LastUser","BOREP"
oWshShell.RegWrite cRegKey1 & "Description","Business Objects Repository"

oWshShell.RegWrite cRegKey2 & "BORep","SQL Server"


Dim strProfile
Dim fso

Set fso = CreateObject("Scripting.FileSystemObject")

strProfile = oWshShell.ExpandEnvironmentStrings("%USERPROFILE%")

'*** Delete all existing LSI files ***

fso.DeleteFile(strProfile & "\Application Data\Business Objects\Business Objects 6.0\lsi\*.lsi")

'*** Delete existing BOMAIN.KEY file ***

If fso.FileExists("C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\bomain.key") Then
fso.DeleteFile("C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\bomain.key")
End If

'*** Copy new shared connections (SDAC.LSI) ***

fso.CopyFile "\\Maint4\g drive\BIS\Update\sdac.lsi", strProfile & "\Application Data\Business Objects\Business Objects 6.0\lsi\"

'*** Copy new BOMAIN.KEY file ***

fso.CopyFile "\\Maint4\g drive\BIS\Update\bomain.key", "C:\Program Files\Business Objects\BusinessObjects Enterprise 6\LocData\"

'*** Clear all previously downloaded universes and related files ***

If fso.FolderExists(strProfile & "\Application Data\Business Objects\Business Objects 6.0\universes\Universe\") Then
fso.DeleteFolder(strProfile & "\Application Data\Business Objects\Business Objects 6.0\universes\Universe")
End If

fso.DeleteFile(strProfile & "\Application Data\Business Objects\Business Objects 6.0\universes\*.*")

set oWshShell = Nothing
set fso = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top