/build/static/layout/Breadcrumb_cap_w.png

running cmd from custom action problem

hi guys,
this should be straight forward but i am struggling. All i want to do is append some text to the c:\windows\system32\drivers\etc\services file.
Due to my environments package validation, this must be done by custom action, properties, system search etc, but no files in the installation with hard coded paths like batch files etc.
I have tried:
CA with : "Execute program from path" with property set to "%COMSPEC% and command line set to "echo SapmsPC1 3602/tcp #SAP w050 c:\windows\system32\drivers\etc\services". I also created a property in property table called "%COMSPEC%" and value of "cmd.exe" but nothing happens.

any ideas what is wrong or how i can do this?

0 Comments   [ + ] Show comments

Answers (5)

Posted by: anonymous_9363 15 years ago
Red Belt
0
I wouldn't recommend that route to append text to a file.

There are innumerable scripts around which will append text to a file and you would be well advised to use one of those, perhaps stored in the Binary table. Remember that quality of scripts vary. Try to find one which at least has *some* error-trapping e.g. testing for file's existence before blindly crashing in trying to update it. There's a very good one knocking about which ensures that you're not adding a duplicate entry, too.

Try Googling for "VBScript +services" and see what turns up.
Posted by: chris16v 15 years ago
Senior Yellow Belt
0
Will do. i will also post resolution here (when i find one) for others.
Posted by: anonymous_9363 15 years ago
Red Belt
0
If you intend to post the actual code, remember to use the 'code' tag, accessible by clicking the button marked '<%' in the 'Reply to Message' window.
Posted by: dannyarya 15 years ago
Senior Purple Belt
0
if u can use VBScript , i have one script to append data into file c:\windows\system32\drivers\etc\services.
Posted by: jmcfadyen 15 years ago
5th Degree Black Belt
0
heres some code to do it. free of all the pesky error handling Ian loves so much..

if you get excited you can add some.


' ****************************************************************************
' 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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ