How to change the database location depends on the first 3 letters of the machine name?
Note: I know that I need to make use of script to check the machine name and then the database name needs to change. But I don't know how to write a script. Please help me with the script.
Hi I have an application where I need to change the database folder depends on the Machine Location,
Check the “Computer name” to determine the correct path. The path will be determine by the first 3 letters of “Computer name” as follows:
- Computer name: HAC, choose \\hacssfs001\apps\WoodMac\GlobalEconomicModel\GEM
- Computer name: NYC, choose \\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM
- Computer name: WDB, choose \\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM
- Computer name: LOS, choose \\losssfs002\applications\WoodMac\GlobalEconomicModel\GEM
- Computer name: KUL, choose \\kulssfs001\applications\WoodMac\GlobalEconomicModel\GEM
- Computer name: BKK, choose \\kulssfs001\applications\WoodMac\GlobalEconomicModel\GEM
- Computer name: JAK, choose \\jakssfs001\applications\WoodMac\GlobalEconomicModel\GEM
- Computer name: BEJ, choose \\bejssfsgenp01\applications\WoodMac\GlobalEconomicModel\GEM
depends on tyhe first 3 letters of the Machine name we need to choose the database location. How to do this and I'm using adminstudio 11.5.
Please help me with this.
Thanks in advance.
Answers (3)
Try with this
Option Explicit
Dim objShell, ComputerName, LeftString
objShell=CreateObject("WScript.Shell")
ComputerName=objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
LeftString=Left(ComputerName, 3)
If LeftString="HAC" Then
.........\\hacssfs001\apps\WoodMac\GlobalEconomicModel\GEM....
ElseIf LeftString="NYC" Then
......... \\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM
ElseIf....
ElseIf.....
End If
Set objShell=Nothing
Comments:
-
Thank You jagadeish,
I have some doubts regarding to the above script,
We mentioned to find the machine first 3 letters and depends on that to change the database location. But we didn't mentioned where to copy the database name.
In the middle of the installation it'll ask the database name.
is this vbscript or wisescript and i'm really sorry that I don't have basic knowledge on scripting.
Please help me with this. - vinodreddy10 11 years ago -
the above script is just an idea.. I thought you can complete it.. you have not mentioned that what files you are going to copy and from where... - jagadeish 11 years ago
-
Jagadeish,
I have an application and it'll ask for the database location.
The database location changes from location to location.
First we need to check the machine name where we are installing the application. If the machine mane starts with HAC then the database should be \\hacssfs001\apps\WoodMac\GlobalEconomicModel\GEM and if the machine name starts with NYC, the database should be \\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM and so on.
This is the one so please help me. - vinodreddy10 11 years ago -
Do you have any property to specify database location in your msi - jagadeish 11 years ago
-
or Where this is getting stored once you enter the location of the database.. Any registry or files..?? - jagadeish 11 years ago
-
Jagadeish, I know how to find it where it is stored. But, the way which I used generally didn't work here.
I will open that winow and take 1st snapshot using systracer and change that and then take 2nd snapshot. But, it's not showing anything. Can I have your suggestion how to find it. Some one told to use dialog editor to find it. but, I'm not clear.
In the middle of installation it'll prompt you to give the database location.
Please let me know how to find it? Thank you jagadeish. - vinodreddy10 11 years ago
Whilst I appreciate that the code was probably off the cuff, endless "If...ElseIf...End If" is pretty poor programming. Use a dictionary with the 3 letters as the key and the database source as the value.
Also, I need to again bring up the use of irrelevant tags in posts. What does this post have to do with 'Virtualization' or 'Best Practices'?
Comments:
-
endless "If...ElseIf...End If"????!!!!!!!!!!!!!!!! - jagadeish 11 years ago
-
jagadeish, VBScab is just stating that multiple If statement's may be able to be used for this scenario, but it may not be the most efficient way since a dictionary object can be used. With the dictionary object being utilized, the code can be simplified with a single call to the dictionary object for the value associated with the three letter key once it is obtained using code similar to what you gave to get the computer name. - M P 11 years ago
-
MP, could you please help me with the script to do this? - vinodreddy10 11 years ago
This is a pretty simple task. Try Google next time.
Option Explicit
Dim objDic, objShell, strSiteCode, strPath
Set objDic = CreateObject("Scripting.Dictionary")
With objDic
.CompareMode = vbTextCompare
.Add "HAC", "\\hacssfs001\apps\WoodMac\GlobalEconomicModel\GEM"
.Add "NYC", "\\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM"
.Add "WDB", "\\nycssfs002\apps\WoodMac\GlobalEconomicModel\GEM"
.Add "LOS", "\\losssfs002\applications\WoodMac\GlobalEconomicModel\GEM"
.Add "KUL", "\\kulssfs001\applications\WoodMac\GlobalEconomicModel\GEM"
.Add "BKK", "\\kulssfs001\applications\WoodMac\GlobalEconomicModel\GEM"
.Add "JAK", "\\jakssfs001\applications\WoodMac\GlobalEconomicModel\GEM"
.Add "BEJ", "\\bejssfsgenp01\applications\WoodMac\GlobalEconomicModel\GEM"
End With
Set objShell = CreateObject("WScript.Shell")
strSiteCode = Left(objShell.ExpandEnvironmentStrings("%COMPUTERNAME%"), 3)
If objDic.Exists(strSiteCode) Then
strPath = objDic.Item(strSiteCode)
' Insert function to use strPath
WScript.Echo strPath
Else
WScript.Echo "ERROR: Site Code """ & strSiteCode & """ not found."
End If
Set objDic = Nothing
Set objShell = Nothing
Set strSiteCode = Nothing
Set strPath = Nothing
Comments:
-
Thanks MP, I'll check it out.
I've a question, we donno where it stores the Database name right? so where it will copy then. I'll find whether registry or file is getting update that stores database name. Where I need to mention in the script about the reg or file which has database name. - vinodreddy10 11 years ago-
The line in the script that says " ' Insert function to use strPath" (no quotes) is where you would be able to use the path to the database from. The "strPath" variable holds the full path to the database. I simply placed an Echo call after the statement to show the functionality of the script, so you can cut out that line and place your function in its place. - M P 11 years ago