That was it. Web page didn't specify and I don't have the experience to know 
the difference.

Thanks again

From: listsad...@lists.myitforum.com [mailto:listsad...@lists.myitforum.com] On 
Behalf Of Aakash Shah
Sent: Tuesday, September 12, 2017 3:26 PM
To: scripting@lists.myitforum.com
Subject: [scripting] RE: bat file will only run one time

That looks like VB code and should have the .vbs extension.  I haven't checked 
the script itself, but see if using the .vbs extension instead of .bat helps.

-Aakash Shah

From: listsad...@lists.myitforum.com<mailto:listsad...@lists.myitforum.com> 
[mailto:listsad...@lists.myitforum.com] On Behalf Of David Landry
Sent: Tuesday, September 12, 2017 11:15 AM
To: scripting@lists.myitforum.com<mailto:scripting@lists.myitforum.com>
Subject: [scripting] bat file will only run one time

Hi All,

I will admit up front, my script write abilities are slim. I have this script 
that I found to insert a new line of text into an .ini file and it works 
perfectly .... But for just one time. During my testing I removed the inserted 
line and text and then reran the script. Only this time it didn't do anything. 
Nothing got inserted. After rerunning this a dozen times or so I can't figure 
out why.

I tried this on a Windows 10 and a Windows 7 system with same behavior. It ran 
only once on each system.

set objWS = CreateObject("Wscript.Shell")
Set fsob=CreateObject("Scripting.FileSystemObject")

strNewLine = "AdminPassword=@dm1n1$trat0r!"
strFileName = "C:\test\script\CustomSettings.ini" ' for example c:\textfile.txt

Const FOR_READING = 1
Const FOR_WRITING = 2
strCheckForString = UCase("SkipAdminPassword=YES")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objTS = objFS.OpenTextFile(strFileName, FOR_READING)
strContents = objTS.ReadAll
objTS.Close
arrLines = Split(strContents, vbNewLine)
Set objTS = objFS.OpenTextFile(strFileName, FOR_WRITING)
For Each strLine In arrLines
  If (Left(UCase(LTrim(strLine)),Len(strCheckForString)) = strCheckForString) 
Then
    objTS.WriteLine strLine
    objTS.WriteLine strNewLine
  else
    objTS.WriteLine strLine
  End If

Can anyone explain this to me? What needs to be changed?

Thanks in advance

Dave L.





Reply via email to