cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Action VB Script...

I get an error stating 'loop' without 'do'. What is wrong with this?

Set FSO = CreateObject("Scripting.FileSystemObject")
CfgPath = Session.Property("SystemFolder") & "drivers\etc\services"
CfgTmp = "C:\Winnt\System32\Drivers\Etc\services.tmp"
Set Fin = FSO.OpenTextFile(CfgPath, 1, False, 0)
Set Fout = FSO.CreateTextFile(CfgTmp, false, false)
Do While Fin.AtEndOfStream <> True
szLine = Fin.ReadLine

' "Change the text on the line below between the quotes to match the text you wanna remove"

if (szLine1 <> "sapdp00 3200/tcp") then
Fout.WriteLine szLine1
end if
Loop
Fin.Close
Fout.Close

if (szLine2 <> "sapdp01 3201/tcp") then
Fout.WriteLine szLine2
end if
Loop
Fin.Close
Fout.Close

if (szLine3 <> "sapdp02 3202/tcp") then
Fout.WriteLine szLine3
end if
Loop
Fin.Close
Fout.Close

if (szLine4 <> "sapdp03 3203/tcp") then
Fout.WriteLine szLine4
end if
Loop
Fin.Close
Fout.Close

if (szLine5 <> "sapdp04 3204/tcp") then
Fout.WriteLine szLine5
end if
Loop
Fin.Close
Fout.Close

FSO.DeleteFile CfgPath, true
FSO.MoveFile CfgTmp, CfgPath

Set Fin = Nothing
Set Fout = Nothing
Set FSO = Nothing

Thanks,

Bryan
(5) Replies
This block of code defines one loop---
' ...
Do While Fin.AtEndOfStream <> True
szLine = Fin.ReadLine

' "Change the text on the line below between the quotes to match the text you wanna remove"

if (szLine1 <> "sapdp00 3200/tcp") then
Fout.WriteLine szLine1
end if
Loop
' etc....
---but the Loop statements that follow this block don't have a beginning of the loop (so the Loop statement doesn't know where to jump back to)...

(As an aside, it doesn't appear that szLine1, szLine2, etc., have been defined, so the If-statements will presumably never succeed...)
Robert,

Just an FYI, this script is supposed to remove entries that are inserted into the services file during installation when the program is uninstalled. I tried modifying the "CfgPath = Session.Property("SystemFolder") & "drivers\etc\services" to "CfgPath = "C:\Winnt\System32\Drivers\etc\services" to allow it to run locally. It runs but doesnt do anything to the services file. I'm still pretty new to VBS so please bear with me!

Would this be correct?

Set FSO = CreateObject("Scripting.FileSystemObject")
CfgPath = Session.Property("SystemFolder") & "drivers\etc\services"
CfgTmp = "C:\Winnt\System32\Drivers\Etc\services.tmp"
Set Fin = FSO.OpenTextFile(CfgPath, 1, False, 0)
Set Fout = FSO.CreateTextFile(CfgTmp, false, false)

Do While Fin.AtEndOfStream <> True
szLine1 = Fin.ReadLine
if (szLine1 <> "sapdp00 3200/tcp") then
Fout.WriteLine szLine1
end if
Loop

Do While Fin.AtEndOfStream <> True
szLine2 = Fin.ReadLine
if (szLine2 <> "sapdp01 3201/tcp") then
Fout.WriteLine szLine2
end if
Loop

Fin.Close
Fout.Close
FSO.DeleteFile CfgPath, true
FSO.MoveFile CfgTmp, CfgPath
Set Fin = Nothing
Set Fout = Nothing
Set FSO = Nothing

Also, would this be a "deferred execution" with a condition of REMOVE="ALL"?

Thanks for your time,

Bryan
The code looks better, but (without my having tried it) you might need to close and reopen "Fin" to restart the searches.

And yes, since the action is making system changes, deferred execution with that condition is appropriate; the only trouble might be that properties generally aren't available during deferred execution, so you might need to use CustomActionData to store the value of SystemFolder (to contruct the file's path)...
Grrrrr,

Anyone else have any suggestions? I've tried numerous things to get this script working. So far what I have is a script that I can run locally but it doesn't remove the two entries from the "services" file. I have approximately 100 or so entries I would like to remove from the "services" file when a client uninstalls this package.

I would also like to have a script that looks at the "services" file for these exact same entries and if present it wouldn't run the script I have that inserts them.

Thanks guys,

Bryan
If I understand what you're trying to do, you might want to create a loop like this:

Do Until Fin.EndOfStream
szLine = Fin.ReadLine

If ((szLine<>"string1") AND (szLine<>"string2") AND (szLine<>"string3")) Then
' copy the line
Fout.WriteLine szLine
End If
Loop