How to hide / get rid of showing .cmd console and icon powershell while executing .vbs script?

Discussion in 'Scripting' started by RemixPL1994, Dec 27, 2020.

  1. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #1 RemixPL1994, Dec 27, 2020
    Last edited: Dec 27, 2020
    Hello, I would like to hide any visible activity while executing .bat / .vbs and powershell. When writing the activity, the point here is that the console window .cmd / powershell, etc., should not be visible when opening / using / executing the script, and that the icons on the start bar should not appear during the work itself.

    All code for .bat:

    REM. >"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^If GetNumlockState() = True Then>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^Else>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^set WshShell = CreateObject("WScript.Shell")>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^WshShell.SendKeys "{NUMLOCK}">>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^End If>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^Function GetNumlockState()>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^strResult = WScript.CreateObject("WScript.Shell").Exec("powershell.exe -command [console]::NumberLock").StdOut.ReadLine>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^If strResult = "True" Then GetNumlockState = True Else GetNumlockState = False>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"
    ECHO ^End Function>>"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\On_NumLock_For_Start_Windows.VBS"

    Only code for VBS:

    If GetNumlockState() = True Then
    Else
    set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{NUMLOCK}"
    End If
    Function GetNumlockState()
    strResult = WScript.CreateObject("WScript.Shell").Exec("powershell.exe -command [console]::NumberLock").StdOut.ReadLine
    If strResult = "True" Then GetNumlockState = True Else GetNumlockState = False
    End Function

    My point is that the .cmd / powershell console window itself should not be visible, but also that there are no icons showing the console's work activity, i.e.

    [​IMG] [​IMG]

    Do any of you have the knowledge and know how to modify the code and rewrite it or add new lines to it so that the whole thing is very silent and not visible in the background while working and executing the script code?

    @abbodi1406 I know you have a lot of knowledge about windows scripts. Could I ask you for an answer?
     
  2. Windows_Addict

    Windows_Addict MDL Expert

    Jul 19, 2018
    1,245
    3,407
    60
    https://stackoverflow.com/a/20055362
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. use
    start "" filename.anysuffix
     
  4. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    I tried to use the Hidden Start and SilentBatch programs provided in the topic and read the answers with the given methods and codes, but unfortunately I still do not know how to use it in practice on my example on the .vbs file because the .vbs file that is just being launched shows me the powershell icon on the start bar which I want to get rid of. Maybe you know what the edited code should look like, can I ask you for help in showing the finished solution for me, how it should look like?

    Unfortunately, my knowledge on this subject is poor, even reading the perhaps ready-made solution and the way I do not understand it, maybe I can ask for a more precise way and explanation. Thank you in advance.
     
  5. abbodi1406

    abbodi1406 MDL KB0000001

    Feb 19, 2011
    16,141
    84,318
    340
    My knowledge in vbs is limited :)

    but you can use two vbs scripts

    C:\Windows\NumLockON_Run.vbs
    Code:
    If GetNumlockState() = True Then
    Else
    set WshShell = CreateObject("WScript.Shell")
    WshShell.SendKeys "{NUMLOCK}"
    End If
    Function GetNumlockState()
    strResult = WScript.CreateObject("WScript.Shell").Exec("powershell.exe -NoProfile -Command [console]::NumberLock").StdOut.ReadLine
    If strResult = "True" Then GetNumlockState = True Else GetNumlockState = False
    End Function
    "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\NumLockON_Hide.vbs"
    Code:
    CreateObject("Wscript.Shell").Run "cscript %windir%\NumLockON_Run.vbs", 0, False
     
  6. RemixPL1994

    RemixPL1994 MDL Junior Member

    Jul 16, 2017
    52
    6
    0
    #6 RemixPL1994, Dec 27, 2020
    Last edited: Dec 27, 2020
    (OP)
    Hello, I understood what you mean. I tried it and it works.

    Thank you very much! But I wonder if there is a way to do the same with a single .vbs file. Hmm.

    Nevertheless, I am satisfied with the current effect and thank you very much. Best regards.