r/PowerShell • • Jul 04 '18

Solved Why does my powershell script stop immediantely after being opened...?

New thread is here: https://www.reddit.com/r/PowerShell/comments/8wceh3/why_does_my_script_work_in_iseps_command_but_not/

It used to work but now it suddently terminates less than a second after being opened. I set the execution policy to unrestricted & re-installed Windows yet it still does not work...

The powershell shows up for 1 second in task manager before windows security health service when it's run using .vbs & then disappears: https://i.imgur.com/VNX7NKx.png

When I paste the script code into PowerShell ISE it works, why is this?

Just to clarify a few things:

The .ps1 file worked with task scheduler (it would load a console window before the message showing up) & when I clicked on the .ps1 file it would also load a console window before the message showed up. When I moved to VB it worked when I clicked on the VB file & when I used the VB file with task scheduler; both without the console window popping up before the message showed.

It still works with VB but only if I create a new user account then after like a day or two it stops working...

Here's what the properties of the task look like (when it worked): https://i.imgur.com/bBIS3od.png

0 Upvotes

78 comments sorted by

View all comments

Show parent comments

1

u/Level-Impression Jul 04 '18 edited Jul 05 '18

Script just loads notification messages, here is an example:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$notifyobj = New-Object System.Windows.Forms.NotifyIcon
$notifyobj.icon = "c:/users/work/Pictures/icon.ico"
$notifyobj.BalloonTipTitle = "New Message"
$notifyobj.BalloonTipText = "C"
$notifyobj.Visible = $True
$notifyobj.ShowBalloonTip(1000)
$notifyobj.Dispose()

6

u/Lee_Dailey [grin] Jul 04 '18

howdy Level-Impression,

it looks like you used the New.Reddit.com Inline Code button. it's the 4th 5th from the left & looks like </>.

on Old.Reddit.com, the above does NOT line wrap, nor does it side-scroll.

for long-ish single lines OR for multiline code, please, use the Code Block button. it's the 11th 12th one from the left, & is just to the left of the ... more menu.

that will give you fully functional code formatting, from what i can tell so far. [grin]

take care,
lee

7

u/Lee_Dailey [grin] Jul 05 '18

howdy anonymous coward downvoter,

four downvotes for pointing out that the poster used the wrong code button when posting code. the button that makes it seriously difficult to read the code in question on anything other than w-i-d-e screens or in New.Reddit ... what a delightful indicator that you are still alive! [grin]

there are times when i wonder if perhaps i have made a serious error in a downvoted post. then i note the extra no-reason-given downvotes and realize that you are still alive.

it is good to know that you need someone to annoy to give some slight meaning to your shallow, nearly pointless life - and that i am the one you can't stop pestering. if you weren't pestering me then you might be hassling others ...

bad cess to you! [grin]

lee

2

u/skypeforbiz Jul 05 '18

Lee, you are my favorite poster.

1

u/Lee_Dailey [grin] Jul 05 '18

howdy skypeforbiz,

thanks! [grin] my fave posters here vary from day to day. mostly folks who post nifty blog links or who go deep into the guts of PoSh. fun stuff that is well beyond my skill level - but still enjoyable to read.

take care,
lee