How to use paths with pauses in PowerShell code inserted to VBS file?

Microsoft Windows
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

How to use paths with pauses in PowerShell code inserted to VBS file?

Post by SS##66 »

I have this OK working PS1 file

Code: Select all

Start-Process "C:\q\Mp3tag\Mp3tag.exe" -ArgumentList '"C:\q\! AUDIO\MMMM.m3u8"'
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('*Mp3Tag')
$wshell.SendKeys('(%(" "(n)))')
but the problem with it is that PowerShell is of course unable to execute it in a hidden window, so that it will not flash itself

I tried inserting it to VBS like so

Code: Select all

On Error Resume Next

ReDim args(WScript.Arguments.Count - 1)

For i = 0 To WScript.Arguments.Count - 1
    If InStr(WScript.Arguments(i), " ") > 0 Then
        args(i) = Chr(34) & WScript.Arguments(i) & Chr(34)
    Else
        args(i) = WScript.Arguments(i)
    End If
Next

command = "Start-Process 'C:\q\Mp3tag\Mp3tag.exe' -ArgumentList '""C:\q\! AUDIO\MMMM.m3u8""'"

Set shell = CreateObject("WScript.Shell")
shell.Run "powershell.exe -WindowStyle Hidden -Command " & Chr(34) & command & Chr(34), 0, False

Set wshell = CreateObject("WScript.Shell")
wshell.AppActivate("*Mp3Tag")
and the PowerShell window did got hidden, but Mp3tag after opening says
C:\q\! was not found.
I tried using different amounts of >>"<< and >>`<< but I always get the such messages
Last edited by Simon Sheppard on 2023-Jul-11, 12:47 am, edited 1 time in total.
Reason: spelling
User avatar
Simon Sheppard
Posts: 189
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to use paths with pauses in PowerShell code insirted to VBS file?

Post by Simon Sheppard »

have you tried
-ArgumentList 'C:\q\! AUDIO\MMMM.m3u8'
or
-ArgumentList '`"C:\q\! AUDIO\MMMM.m3u8`"'

That said, I think you could simplify this a lot by just saving a PowerShell .ps1 script and calling that with powershell.exe -WindowStyle Hidden ...
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by SS##66 »

Using

Code: Select all

command = "Start-Process 'C:\q\Mp3tag\Mp3tag.exe' -ArgumentList 'C:\q\! AUDIO\MMMM.m3u8'"
or

Code: Select all

command = "Start-Process 'C:\q\Mp3tag\Mp3tag.exe' -ArgumentList '`"C:\q\! AUDIO\MMMM.m3u8`"'"
does nothing - i.e. Poweshell window flashes and nothning happens


As for using just

Code: Select all

powershell.exe -WindowStyle Hidden
It is just impossible to run or re-run the same file PS1 in already minimized or hidden PowerShell window, right? That is the reason why I need to use intermediary in form of VBS- so that a PowerShell window will not show itself at all and I will have just one file and not two
Last edited by SS##66 on 2023-Jul-16, 10:33 am, edited 1 time in total.
User avatar
Simon Sheppard
Posts: 189
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by Simon Sheppard »

SS##66 wrote: 2023-Jul-11, 10:34 am It is just impossible to run or re-run the same file PS1 in already minimized or hidden PowerShell window, right? That is the reason why I need to use intermediary in form of VBS- so that a PowerShell window will not show itself at all and I will have just one file and not two
You can create a shortcut to PowerShell.exe with the arguments needed and then set that shortcut to run minimised.

To make it completely invisible use a utility like CMDOW.
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by SS##66 »

The simple trick of going to

Shortcut > Target

of the LNK leading and adding

Code: Select all

-WindowStyle Minimized
thus using

Code: Select all

C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -WindowStyle Minimized -File "C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1"
only alleviates the issue by making the PowerShell window appear for a split second instead of around 1 second


Then I opened a PowerShell window as Administrator, executed in it

Code: Select all

Set-ExecutionPolicy RemoteSigned
and simply executed in it

Code: Select all

'C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1'
and then also

Code: Select all

"C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1"
but nothing happened. So for whatever reason running in CMD window

Code: Select all

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 'C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1'
also does nothing for me


And when I tried using NirCmd by executing in CMD window

Code: Select all

C:\q\NirSoft\NirCmd\nircmd.exe exec min "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle Minimized -File "C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1"
then window of PowerShell did open minimized - but the file with this script also did nothing
User avatar
Simon Sheppard
Posts: 189
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by Simon Sheppard »

SS##66 wrote: 2023-Jul-16, 12:50 pm only alleviates the issue by making the PowerShell window appear for a split second instead of around 1 second
You also need to set the shortcut properties to run minimised.
Then all you should see is a box on the task bar but no window.

When running from CMD you have to use double quotes, not single.
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by SS##66 »

Both below versions

Code: Select all

C:\q\NirSoft\NirCmd\nircmd.exe exec min "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle Minimized -File ""C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1""

Code: Select all

C:\q\NirSoft\NirCmd\nircmd.exe exec min ""C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"" -WindowStyle Minimized -File ""C:\q\! SCRIPTS\Mp3tag Opening With Playlist.ps1""
also open window of PowerShell minimized - but then it closes and nothing happens


As for adding to LNK the system rule of running its Target as Minimized instead of Normal- it works without any additional command line parameters. But as I said for whatever reason it produces the system sound of blockade when executed. But as it comes out it happens only sometimes, so I will use it. But I still would like would prefer to have instructions for opening minimized within a script of a single file


Nevertheless I thank thee for thy help
User avatar
Simon Sheppard
Posts: 189
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by Simon Sheppard »

The system sound is probably part of the sound scheme, with some digging you should be able to find it and turn off.

https://www.howtogeek.com/273/turn-off- ... ows-vista/
SS##66
Posts: 28
Joined: 2023-Jan-24, 4:51 pm

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by SS##66 »

Oh, come on...

Do you really expect power users to turn informative system sound for blockade due to some unknown and only sometimes occurring glitch somehow related to PowerShell? And you assume they do not know how to do that?


But once again: I do appreciate the time spent by you on this issue
User avatar
Simon Sheppard
Posts: 189
Joined: 2021-Jul-10, 7:46 pm
Contact:

Re: How to use paths with pauses in PowerShell code inserted to VBS file?

Post by Simon Sheppard »

I try to be mindful that other people will probably find these discussions via a Google search in the future and might have no idea where the sounds come from :|

Thanks
Post Reply