Technical Article

SMS Script


Problem Description:-

I have 150 users using standalone application on there Windows XP destops. Each destops as .ini file for that application which points to Server abc. i want to do SMS push to those 150 users which will modify\update .ini file so that instead of pointing\connecting to Server abc it will then connect to Server xyz and not to Server abc.

How to use this script:-

you just have to change the name of the original server, the new Server and the path and name of the ini file and it should work. Just copy and paste this text into a notepad session and rename it to .vbs. Then push out the vbs script to the clients. Or put it into a script window within SMS.

On Error Resume Next

Const ForReading = 1
Const ForAppending = 8
strServerABC = "ServerABC" 'Replace with the name of the original server
strServerXYZ = "ServerXYZ" 'Replace with the name of the new server
strPath = "c:\" 'Replace this with the path to the ini file on the remote machine. Make sure you put a \ at the end of the path.
strOriginalIni = "original.ini" 'Replace with the name of the Ini File
strTempIni = "temp.ini"
strBackupIni = Replace(strOriginalIni, ".ini", ".old")
Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists (strPath & strOriginalIni) Then 
 objFSO.CopyFile strPath & strOriginalIni, strPath & strBackupIni, True 'This will make a backup copy of the ini file just in case of recovery
 If objFSO.FileExists (strPath & strTempIni) Then 'Check to see if the temp file exists from a previous run
 objFSO.DeleteFile(strPath & strTempIni) 'If so them remove it so that we can recreate it.
 End If
 Set objTempIniFileWrite = objFSO.OpenTextFile (strPath & strTempIni, ForAppending, True)
 Set objOriginalIniFileRead = objFSO.OpenTextFile(strPath & strOriginalIni, ForReading)

 Do While objOriginalIniFileRead.AtEndOfStream <> True
 strLineRead = objOriginalIniFileRead.Readline
 If InStr(strLineRead, strServerABC) > 0 Then
 strReplaceLine = Replace(strLineRead, strServerABC, strServerXYZ) 'This will replace the original server name with the new server name
 End If
 WScript.Quit 'The Original INI file was not found on the system so therefore exit. You can put return codes here if you want or comments.
End If


objFSO.CopyFile strPath & strTempIni, strPath & strOriginalIni, True 'This will then copy the temporary file back over top of the original file
objFSO.DeleteFile (strPath & strTempIni)