The following files are in the same folder.
Testing.cmd
Toast notification.ps1
Run [Toast notification].vbs
When I run Toast notification.ps1, it works. However, when I run Run [Toast notification].vbs, the .ps1 file is not run.
The following is the PowerShell script:
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
# notify.icon type: Information, Warning or Error.
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"", "The CPU is hot.",
[system.windows.forms.tooltipicon]::None)
$notify.dispose()
The following is the VBScript:
Path = split(wscript.scriptFullName, wscript.scriptname)(0)
Item1 = Path & "Toast notification.ps1"
Item2 = Path & "Testing.cmd"
Set Action = CreateObject("Wscript.shell")
Action.run ("powershell -executionpolicy bypass -file ""& Item1 &""")
Action.run ("""" & Item2 & ""), 0
When I double-click on the VBScript file, the .ps1 file is not run. The "Path" can be used to run Testing.cmd, but I cannot make it work with a .ps1 file. How can I fix the problem?
The following is the Testing.cmd file:
(ncpa.cpl)
When you run the PowerShell script it should look more like this:
The chr(34) represents quotes in case your path contains spaces. I'd also recommend more error checking, and checking that the files exist etc. The above example hides the PowerShell and CMD windows too...