0
votes

I'm trying to run a ps1 script that makes a "beep" alert when you lock or unlock your session on windows xp. I already got it and I'm trying to call that script through a VBS script. Problem is that if I execute the VBS manually, the power shell window appears and obviously, when i closed it, the script stop running. Here's my code:

This is the ps1:

$sysevent = [microsoft.win32.systemevents]

Register-ObjectEvent -InputObject $sysevent -EventName SessionSwitch -Action {[console]::Beep();Write-host ($args[1]).Reason}

And this is the VBS:

Set objShell = CreateObject("Wscript.Shell") objShell.Run("powershell.exe -noexit c:\beep.ps1")

Does anybody know how to prevent the power shell window and running the script in the background?

1
Did you know that there is a windows system call to make a beep? because there is. msdn.microsoft.com/en-us/library/windows/desktop/… Might help to simplify your approach. - Wug
@Wug and how would you make that call from vbscript ? - peter
@peter you could write like a 6 liner com wrapper for it. You can do com calls from vba - Wug
writing com objects is something most vbscript programmers are not capable of, also it's not vba but vbs but you could use a com omject there too and last you have to register that com on every machine you are going to use that script what makes it difficult to roll out - peter

1 Answers

0
votes

There is no need for a ps1 script, i use this one liner

WScript.CreateObject ("WScript.Shell").Run "cmd /c " & chr(7),0,False

Also found some usefull suggestions at http://forums.mozillazine.org/viewtopic.php?p=11616563 like the little c program that you can compile or the nircmd command.