tomasz86 Posted August 9, 2011 Share Posted August 9, 2011 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 & """" & argStringBy changingcmd.exe /ktocmd.exe /cI 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 More sharing options...
allen2 Posted August 9, 2011 Share Posted August 9, 2011 (edited) You need :- to comment the lineRunMeWithCScript()- 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 August 9, 2011 by allen2 Link to comment Share on other sites More sharing options...
tomasz86 Posted February 29, 2012 Author Share Posted February 29, 2012 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 & """" & argStringto'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 & """" & argStringEverything is run in background now. Link to comment Share on other sites More sharing options...
tomasz86 Posted March 5, 2012 Author Share Posted March 5, 2012 By the way, does anyone know how to make the script case insesitive? Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 5, 2012 Share Posted March 5, 2012 Could you post the part of the script that you want to make case insensitive Link to comment Share on other sites More sharing options...
tomasz86 Posted March 6, 2012 Author Share Posted March 6, 2012 Well, I'd just like the script to remove all duplicates regardless of their case. I don't know which part of yanklines is responsible for this... Link to comment Share on other sites More sharing options...
tomasz86 Posted March 6, 2012 Author Share Posted March 6, 2012 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 More sharing options...
dencorso Posted March 9, 2012 Share Posted March 9, 2012 Locate this:Set objDict = CreateObject("Scripting.Dictionary")j = 0and change it thus:Set objDict = CreateObject("Scripting.Dictionary")objDict.CompareMode = 1 'Text i.e. case insensitivej = 0I'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 sensitivewould restore case sensitivity.However, making it case insensitive does not ensure a consistent casing... Your example above results in:CopyFiles = System32.filesCopyFiles = Fonts.Filesbecause always the first occurence is the one preserved, regardless of casing, so do take care. Link to comment Share on other sites More sharing options...
tomasz86 Posted March 11, 2012 Author Share Posted March 11, 2012 Thank you very much. Fortunately in this case it doesn't matter whether casing is consistent or not. Link to comment Share on other sites More sharing options...
dencorso Posted March 12, 2012 Share Posted March 12, 2012 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! Link to comment Share on other sites More sharing options...
jaclaz Posted March 12, 2012 Share Posted March 12, 2012 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 More sharing options...
gunsmokingman Posted March 12, 2012 Share Posted March 12, 2012 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 script2:\ Cmd Linecscript %UserProfile%\Desktop\RemoveLines.vbs D:\MyTemp\Test1.TxtThis will then produce a file called New_FileName.ExtensionTest File Contents[section 01 Test]Line 01 TestLINE 01 TESTLINE 01 TestLine 01 TESTline 01 testlINE 01 tESTLine 01 TestLINE 01 TESTLINE 01 TestLine 01 TESTline 01 testlINE 01 tEST[section 02 Test]Line 02 TestLine 02 Test[section 03 Test]Line 03 TestLine 02 Test[section 04 Test]Line 04 TestLine 03 Test[section 05 Test]Line 05 Test 1Line 05 Test 2[section 06 Test]Line 06 TestLine 03 TestResults 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 1Line 05 Test 2[section 06 Test]Line 06 TestSave As RemoveLines.vbsDim 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 More sharing options...
dencorso Posted March 13, 2012 Share Posted March 13, 2012 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 More sharing options...
CoffeeFiend Posted March 13, 2012 Share Posted March 13, 2012 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.txtI 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 More sharing options...
gunsmokingman Posted March 13, 2012 Share Posted March 13, 2012 I really could not get the so called one line solution to work correctlyThe only output I could was from my last try with Power ShellContents Of Test1.txt[section 01 Test]Line 01 TestLINE 01 TESTLINE 01 TestLine 01 TESTline 01 testlINE 01 tESTLine 01 TestLINE 01 TESTLINE 01 TestLine 01 TESTline 01 testlINE 01 tEST[section 02 Test]Line 02 TestLine 02 Test[section 03 Test]Line 03 TestLine 02 Test[section 04 Test]Line 04 TestLine 03 Test[section 05 Test]Line 05 Test 1Line 05 Test 2[section 06 Test]Line 06 TestLine 03 TestPowerShell Output To New_Test1.txtC:\Users\Gunsmokingman\Desktop\Test1.Txt Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now