Vicki05
asked on
Write to text file with input box to change a specific value
I need to create a batch file and write to it. The wording remain the same but the /Value=? needs to change by provding the person a input box to enter the value? The file needs to be created in c:\Program Files (x86)\test\Worktest\Test.b at
I need to write the following with the ability to change the Value=apple to what ever the user inputs. I want to be able to change that by using the inputbox.
echo off
"C:\Program Files (x86)\Common Files\test\Interface\Contr ol\hello.j ack.test.e xe" /Value=apple /playnow
Please advice
I need to write the following with the ability to change the Value=apple to what ever the user inputs. I want to be able to change that by using the inputbox.
echo off
"C:\Program Files (x86)\Common Files\test\Interface\Contr
Please advice
Try this:
echo off
set /p strValue= Please enter a value.
"C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe" /Value=%strValue% /playnow
Small correction for the plain batch (forgot to replace apple, too much copy and paste):
@echo off
setlocal
set Value=
set /p Value=Please enter the value (or an empty value to exit):
if "%Value%"=="" goto :eof
"%ProgramFiles(x86)%\Common Files\test\Interface\Control\hello.jack.test.exe" /Value="%Value%"/playnow
And for the fun of it, a batch with an input box:
@echo off
setlocal
set Title=Title
set Prompt=Prompt
set TempFile=%Temp%\Input.vbs
>"%TempFile%" echo Wscript.Echo InputBox("%Prompt%", "%Title%")
set Value=
for /f "delims=" %%a in ('cscript.exe //nologo "%Temp%\Input.vbs"') do (set Value=%%a)
del "%TempFile%"
if "%Value%"=="" goto :eof
"%ProgramFiles(x86)%\Common Files\test\Interface\Control\hello.jack.test.exe" /Value="%Value%"/playnow
ASKER
Sorry, I meant to say that I need a vbscript to write a text or a batch file that will let me change the value.
Please repost the exact text you need written to a text/batch file, put the variable text only in bold.
ASKER
Here is the vbscript that I am working on. I need to be able to change the value using a inputbox instead of msgbox
strComputer = "."
Set objShell = CreateObject("WScript.Shel l")
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Const ForReading = 1
Const ForWriting = 2
intAnswer = _
Msgbox("This utility gives the ability to Update the Value." & vbCrLf & "Do you want to turn Change Value?", _
vbYesNo, "Run Program")
If intAnswer = vbYes Then
If objFSO.FileExists("C:\Prog ram Files (x86)\test\Worktest\Test.b at") Then
objFSO.DeleteFile "C:\Program Files (x86)\test\Worktest\Test.b at"
End If
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Set outFile = objFSO.OpenTextFile("C:\Pr ogram Files (x86)\test\Worktest\Test.b at", 8, True)
For i = 1 to 7
Next
outfile.WriteLine "@echo off"
outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Contr ol\hello.j ack.test.e xe""/Value =apple /playnow"
msgbox"Done"
End If
strComputer = "."
Set objShell = CreateObject("WScript.Shel
Set objFSO = CreateObject("Scripting.Fi
Const ForReading = 1
Const ForWriting = 2
intAnswer = _
Msgbox("This utility gives the ability to Update the Value." & vbCrLf & "Do you want to turn Change Value?", _
vbYesNo, "Run Program")
If intAnswer = vbYes Then
If objFSO.FileExists("C:\Prog
objFSO.DeleteFile "C:\Program Files (x86)\test\Worktest\Test.b
End If
Set objFSO = CreateObject("Scripting.Fi
Set outFile = objFSO.OpenTextFile("C:\Pr
For i = 1 to 7
Next
outfile.WriteLine "@echo off"
outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Contr
msgbox"Done"
End If
Perhaps if I understood your goal I could advise you of a better way...
strValue = InputBox("Enter desired value.")
outfile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe""/Value=" & strValue & " /playnow"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Macro,
I get an error on line2 character 1. Object required "outfile"
I get an error on line2 character 1. Object required "outfile"
ASKER
Thanks for the solution. It worked.
Just noted that for the sake of completeness, there should be an "outFile.Close" after line 21. And for the fun of it, here's a version that fixes this and displays the current value in the input box:
strOutputFile = "C:\Program Files (x86)\test\Worktest\Test.bat"
strTitle = "Run Program"
strPrompt = "This utility gives the ability to update the value." & vbCrLf & _
"Enter the value you want to set, or an empty value to skip." & vbCrLf
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
' Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strOutputFile) Then
strSearch = "/Value="
Set outFile = objFSO.OpenTextFile(strOutputFile, ForReading)
Do While Not outFile.AtEndOfStream
strLine = outFile.ReadLine()
intPosValue = InStr(strLine, strSearch)
If intPosValue > 0 Then
intPosPlayNow = InStr(strLine, "/playnow")
If (intPosPlayNow > 0) And (intPosPlayNow > intPosValue) Then
strOldValue = Mid(strLine, intPosValue + Len(strSearch) + 1, intPosPlayNow - intPosValue - Len(strSearch) - 3)
End If
End If
Loop
strPrompt = strPrompt & vbCrLf & "The current value is '" & strOldValue & "'."
outFile.Close
End If
strValue = InputBox(strPrompt, strTitle, strOldValue)
If (strValue <> "") And (strValue <> strOldValue) Then
Set outFile = objFSO.OpenTextFile(strOutputFile, ForWriting, True)
For i = 1 to 7
Next
outFile.WriteLine "@echo off"
outFile.WriteLine """C:\Program Files (x86)\Common Files\test\Interface\Control\hello.jack.test.exe"" /Value=""" & strValue & """ /playnow"
outFile.Close
MsgBox "Value changed to '" & strValue & "'."
End If
ASKER
Thanks
Open in new window