Jump to content

Recommended Posts

I wonder if it's possible to run yanklines.vbs totally in background without any console windows popping up.

Here is the part of the code which is responsible for this behaviour:

'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString

By changing

cmd.exe /k

to

cmd.exe /c

I managed to get it closed as soon as it pops up. What I would like to do is to prevent any windows from being displayed while running the script.

Link to comment
Share on other sites


You need :

- to comment the line

RunMeWithCScript()

- to comment all lines with wscript.echo (unless you want popup for each line).

- to launch the script with wscript.exe instead of cscript if you're launching it from another script.

Edited by allen2
Link to comment
Share on other sites

  • 6 months later...

It's a late reply but...

as I don't know anything about VBS scripting I tried a different method:

1) I downloaded hidcon.

2) I changed

'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
scriptCommand = "cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString

to

'Create a persistent command prompt for the cscript output window and call the script with its original arguments    
scriptCommand = "hidcon.exe cmd.exe /k " & engineFolder & "cscript.exe """ & Wscript.ScriptFullName & """" & argString

Everything is run in background now.

Link to comment
Share on other sites

The duplicate lines I'm talking about are something like these:

 CopyFiles = System32.files
CopyFiles = System32.Files
CopyFiles = Fonts.Files
CopyFiles = Fonts.files

Link to comment
Share on other sites

Locate this:

Set objDict = CreateObject("Scripting.Dictionary")
j = 0

and change it thus:

Set objDict = CreateObject("Scripting.Dictionary")
objDict.CompareMode = 1 'Text i.e. case insensitive
j = 0

I'd also keep the "cmd /c" instead of "cmd /k" like you did in your first post, in addition to using hidcon.

PS: setting:

objDict.CompareMode = 0 'Binary i.e. case sensitive

would restore case sensitivity.

However, making it case insensitive does not ensure a consistent casing... Your example above results in:

CopyFiles = System32.files
CopyFiles = Fonts.Files

because always the first occurence is the one preserved, regardless of casing, so do take care.

Link to comment
Share on other sites

Since I think the case-insensitive version is more useful than the previous one, I've updated my original Yanklines.VBS post, to reflect this. Thanks for calling my attention to the problem!

With all due respect :), the idea of updating is generally to "better" in the sense of "adding features/choices" or correct "wrong" behaviour, wouldn't it be more desirable to have a /I command line parameter/switch (not entirely unlike the batch IF /I one)?

(or reversing the default a /CS one)?

jaclaz

Link to comment
Share on other sites

Here is a script I wrote that will remove duplicate lines and blank lines from INI INF TXT file types. You can use this script 2 ways

1:\ Drag and Drop the file onto the script

2:\ Cmd Line

cscript %UserProfile%\Desktop\RemoveLines.vbs D:\MyTemp\Test1.Txt

This will then produce a file called New_FileName.Extension

Test File Contents

[section 01 Test]

Line 01 Test

LINE 01 TEST

LINE 01 Test

Line 01 TEST

line 01 test

lINE 01 tEST

Line 01 Test

LINE 01 TEST

LINE 01 Test

Line 01 TEST

line 01 test

lINE 01 tEST

[section 02 Test]

Line 02 Test

Line 02 Test

[section 03 Test]

Line 03 Test

Line 02 Test

[section 04 Test]

Line 04 Test

Line 03 Test

[section 05 Test]

Line 05 Test 1

Line 05 Test 2

[section 06 Test]

Line 06 Test

Line 03 Test

Results Of Script

[section 01 Test]

Line 01 Test

[section 02 Test]

Line 02 Test

[section 03 Test]

Line 03 Test

[section 04 Test]

Line 04 Test

[section 05 Test]

Line 05 Test 1

Line 05 Test 2

[section 06 Test]

Line 06 Test

Save As RemoveLines.vbs


Dim Dic :Set Dic = CreateObject("Scripting.Dictionary")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Drag One File
If WScript.Arguments.Count = 1 Then
'-> Process INF, INI,TXT
Select Case LCase(Right(WScript.Arguments.Item(0),3))
Case "inf","ini","txt"
TextChange(WScript.Arguments.Item(0))
Case Else
'-> Not Correct File Type
MsgBox "This file is not a valid file type : " & _
Right(WScript.Arguments.Item(0),3) & vbCrLf & _
"Drag And Drop These Types INF INI TXT",4128,_
"Error Wrong File Type"
WScript.Quit
End Select
'-> No File Drag
ElseIf WScript.Arguments.Count = 0 Then
ErrorMsg("Error File Total : " & WScript.Arguments.Count)
'-> To Many Files Drag
ElseIf WScript.Arguments.Count >= 2 Then
ErrorMsg("Error File Total : " & WScript.Arguments.Count)
End If
'-> Function To Handle To Many Or Zero Files
Function ErrorMsg(N)
MsgBox _
"There must be only 1 Text File Type Drag And Drop" & vbCrLf & _
"onto this script. " & N,4128, N
WScript.Quit
End Function
'-> Remove Duplicate Lines
Function TextChange(File)
Dim Ts, Tx
Set File = Fso.GetFile(File)
Set Ts = Fso.OpenTextFile(File.Path)
'-> 1 = Case Insensitive , 0 = Case Sensitive
Dic.CompareMode = 1
Do Until Ts.AtEndOfStream
Tx = Ts.ReadLine
If Not Dic.Exists(Tx) Then Dic.Add Tx, Tx
Loop
Ts.Close
Set Ts = Fso.CreateTextFile( _
Replace(File.Path,File.Name, "New_" & File.Name))
For Each Tx In Dic.Keys
If Not Tx = "" Then Ts.WriteLine Tx
Next
Ts.Close
End Function

Sorry for the double attach file I am on Windows 8 and I can not remove one from the post,

the site not quite right on Win 8

Link to comment
Share on other sites

Since I think the case-insensitive version is more useful than the previous one, I've updated my original Yanklines.VBS post, to reflect this. Thanks for calling my attention to the problem!

With all due respect :), the idea of updating is generally to "better" in the sense of "adding features/choices" or correct "wrong" behaviour, wouldn't it be more desirable to have a /I command line parameter/switch (not entirely unlike the batch IF /I one)? (or reversing the default a /CS one)?

Yes, I considered that. However, I do think the case-insensitive behaviour is in line with the general behaviour of both DOS and Windows (FIND is an exception, there must be others...) and generally more useful. Now, since to restore the original case sensitive behaviour of the script is just a matter of changing a single "1" to "0" inside the script (and it's documented by a comment at that point), I decided adding a command-line parameter to control it would be an overkill, since it would entail many lines of code for a robust parsing of the command-line, which would add unneeded complexity to the code. That's just my 2 ¢, of course.

Link to comment
Share on other sites

Tasks like this (or others like sorting data) is why I'm moving away from VBScript for scripting/admin/automating stuff, mainly towards PowerShell and C#. It took over 80 lines of VBScript to do, whereas in PowerShell it's a very simple one-liner:

gc in.txt|select -unique|out-file out.txt

I have nothing to say against your script (I only had a *very* quick glance). It's the scripting technology itself that's reached the point where new offerings do the job better and quicker most of the time. So I just wanted to point out how much quicker/simpler it is now.

Link to comment
Share on other sites

I really could not get the so called one line solution to work correctly

The only output I could was from my last try with Power Shell

Contents Of Test1.txt

[section 01 Test]

Line 01 Test

LINE 01 TEST

LINE 01 Test

Line 01 TEST

line 01 test

lINE 01 tEST

Line 01 Test

LINE 01 TEST

LINE 01 Test

Line 01 TEST

line 01 test

lINE 01 tEST

[section 02 Test]

Line 02 Test

Line 02 Test

[section 03 Test]

Line 03 Test

Line 02 Test

[section 04 Test]

Line 04 Test

Line 03 Test

[section 05 Test]

Line 05 Test 1

Line 05 Test 2

[section 06 Test]

Line 06 Test

Line 03 Test

PowerShell Output To New_Test1.txt

C:\Users\Gunsmokingman\Desktop\Test1.Txt

post-5386-0-34758500-1331603692_thumb.pn

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...