How to suppress the message box?
Hello,
I know nothing about VBScript and need your expertise. I am trying to use this "modifiy service script" that I got from AppDeploy, but the script ends with the message box asking you to click "OK" to exit.
Does anyone know how to edit it to suppress the message that pops up in the end?
Thanks for the help!
' ****************************************************************************
' Name : ModService.vbs
' Description : Handles inserting services at installation time
' Usage : Used at packaging to insert CA to adapt services file
' Modifications :
'
'
' Date Version User Description
' ****************************************************************************
' 25/04/2006 V1.0 J. McFadyen Created initial script
'
' ****************************************************************************
' Script details: This script requires two or three command line args
' : if two args are supplied the script will delete an
' : entry from the services file
' : if three args are supplied the script will add an
' : entry to the services file
'
' Examples :
' ModService.vbs <Filename> <ServiceName> <ServicePort>
' ModService.vbs <Filename> <ServiceName>
'
' Adding an entry
' ModService.vbs c:\windows\system32\drivers\etc\services Test1 100/tcp
' ModService.vbs c:\windows\system32\drivers\etc\services Test1 100/udp
'
' Deleting an entry
' ModService.vbs c:\windows\system32\drivers\etc\services Test1
'
' ****************************************************************************
On Error Resume Next
Dim FileSysObj, strFileContents, intLocation, objArgs
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
'3 Arguments is Set, 2 is Delete
If objArgs.Count = 2 Then
DeleteService objArgs(0), objArgs(1)
Else
SetService objArgs(0), objArgs(1), objArgs(2)
End If
'Opens the file, gets the contents and searches for the host name on a non-comment line
'Leaves strFileContents with the contents and intLocation pointing to the start of the line
Sub LocateService(strFileName, strServiceName)
Err.Clear
Dim objFile, strLine
Set objFile = FileSysObj.OpenTextFile(strFileName, 1)
strFileContents = objFile.ReadAll()
intLocation = 0
Do
'Search for ServiceName
intLocation = InStr(intLocation+1, strFileContents, strServiceName, 1)
'Not found
If intLocation = 0 Then Exit Do
'Search back for the NewLine
intLocation = InStrRev(strFileContents, Chr(10), intLocation) + 1
'Grab the line
strLine = Trim(Mid(strFileContents, intLocation, InStr(intLocation, strFileContents, Chr(10)) - intLocation))
'Accept - unless it's comment, even if it does have our hostname
If Left(strLine, 1) <> "#" Then Exit Do
'Move forward
intLocation = InStr(intLocation, strFileContents, Chr(10))
'No more lines
If intLocation = 0 Then Exit Do
Loop
objFile.Close
End Sub
'Sets a service to a port value if it exists, adds it if it does not
Sub SetService(strFileName, strServiceName, strPort)
Dim objFile, strNewLine, intLineEnd
strNewLine = strServiceName & space((25-len(strServiceName))-len(strPort)) & strPort
msgbox strNewLine
LocateService strFileName, strServiceName
If intLocation > 0 Then
'Modify
intLineEnd = InStr(intLocation, strFileContents, Chr(10))
Set objFile = FileSysObj.OpenTextFile(strFileName, 2)
objFile.Write Left(strFileContents, intLocation-1)
objFile.WriteLine strNewLine
objFile.Write Mid(strFileContents, intLineEnd+1)
Else
'Append
Set objFile = FileSysObj.OpenTextFile(strFileName, 8, True)
objFile.WriteLine strNewLine
End If
objFile.Close
End Sub
'Deletes a line containing a service name
Sub DeleteService(strFileName, strServiceName)
Dim objFile, intLineEnd
LocateService strFileName, strServiceName
If intLocation > 0 Then
'Remove here
intLineEnd = InStr(intLocation, strFileContents, Chr(10))
Set objFile = FileSysObj.OpenTextFile(strFileName, 2)
objFile.Write Left(strFileContents, intLocation-1)
objFile.Write Mid(strFileContents, intLineEnd+1)
End If
End Sub
I know nothing about VBScript and need your expertise. I am trying to use this "modifiy service script" that I got from AppDeploy, but the script ends with the message box asking you to click "OK" to exit.
Does anyone know how to edit it to suppress the message that pops up in the end?
Thanks for the help!
' ****************************************************************************
' Name : ModService.vbs
' Description : Handles inserting services at installation time
' Usage : Used at packaging to insert CA to adapt services file
' Modifications :
'
'
' Date Version User Description
' ****************************************************************************
' 25/04/2006 V1.0 J. McFadyen Created initial script
'
' ****************************************************************************
' Script details: This script requires two or three command line args
' : if two args are supplied the script will delete an
' : entry from the services file
' : if three args are supplied the script will add an
' : entry to the services file
'
' Examples :
' ModService.vbs <Filename> <ServiceName> <ServicePort>
' ModService.vbs <Filename> <ServiceName>
'
' Adding an entry
' ModService.vbs c:\windows\system32\drivers\etc\services Test1 100/tcp
' ModService.vbs c:\windows\system32\drivers\etc\services Test1 100/udp
'
' Deleting an entry
' ModService.vbs c:\windows\system32\drivers\etc\services Test1
'
' ****************************************************************************
On Error Resume Next
Dim FileSysObj, strFileContents, intLocation, objArgs
Set FileSysObj = CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
'3 Arguments is Set, 2 is Delete
If objArgs.Count = 2 Then
DeleteService objArgs(0), objArgs(1)
Else
SetService objArgs(0), objArgs(1), objArgs(2)
End If
'Opens the file, gets the contents and searches for the host name on a non-comment line
'Leaves strFileContents with the contents and intLocation pointing to the start of the line
Sub LocateService(strFileName, strServiceName)
Err.Clear
Dim objFile, strLine
Set objFile = FileSysObj.OpenTextFile(strFileName, 1)
strFileContents = objFile.ReadAll()
intLocation = 0
Do
'Search for ServiceName
intLocation = InStr(intLocation+1, strFileContents, strServiceName, 1)
'Not found
If intLocation = 0 Then Exit Do
'Search back for the NewLine
intLocation = InStrRev(strFileContents, Chr(10), intLocation) + 1
'Grab the line
strLine = Trim(Mid(strFileContents, intLocation, InStr(intLocation, strFileContents, Chr(10)) - intLocation))
'Accept - unless it's comment, even if it does have our hostname
If Left(strLine, 1) <> "#" Then Exit Do
'Move forward
intLocation = InStr(intLocation, strFileContents, Chr(10))
'No more lines
If intLocation = 0 Then Exit Do
Loop
objFile.Close
End Sub
'Sets a service to a port value if it exists, adds it if it does not
Sub SetService(strFileName, strServiceName, strPort)
Dim objFile, strNewLine, intLineEnd
strNewLine = strServiceName & space((25-len(strServiceName))-len(strPort)) & strPort
msgbox strNewLine
LocateService strFileName, strServiceName
If intLocation > 0 Then
'Modify
intLineEnd = InStr(intLocation, strFileContents, Chr(10))
Set objFile = FileSysObj.OpenTextFile(strFileName, 2)
objFile.Write Left(strFileContents, intLocation-1)
objFile.WriteLine strNewLine
objFile.Write Mid(strFileContents, intLineEnd+1)
Else
'Append
Set objFile = FileSysObj.OpenTextFile(strFileName, 8, True)
objFile.WriteLine strNewLine
End If
objFile.Close
End Sub
'Deletes a line containing a service name
Sub DeleteService(strFileName, strServiceName)
Dim objFile, intLineEnd
LocateService strFileName, strServiceName
If intLocation > 0 Then
'Remove here
intLineEnd = InStr(intLocation, strFileContents, Chr(10))
Set objFile = FileSysObj.OpenTextFile(strFileName, 2)
objFile.Write Left(strFileContents, intLocation-1)
objFile.Write Mid(strFileContents, intLineEnd+1)
End If
End Sub
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
anonymous_9363
13 years ago
Posted by:
oogiejun
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.