Zhorn Software
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty How to create a Sticky in a VBS script

Sun Nov 22, 2020 8:07 am
Hello,

I'd like to be able to create a new text sticky from within a vbs script (the goal is to be warned of error that coud occur in a script automatically launched in background thanks to task scheduler).

I saw the "API" chapter on Zhorn website, but provided examples are only with C# ad C++
Is there any way to do the same in a VBS script ?
avatar
Guest
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Sun Nov 22, 2020 9:00 am
I am not familiar with vbs but you can use the apicmd.exe to create a sticky (with text if needed ).

you will find the apicmd.exe on the webpage for api :  https://www.zhornsoftware.co.uk/stickies/api/sample_apicmd.zip

Code:
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim exeName
Dim statusCode
exeName = "c:\Users\admin\AppData\Roaming\stickies\apicmd.exe do new sticky hello"
statusCode = WshShell.Run (exeName, 1, true)


How to create a Sticky in a VBS script 42410
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Sun Nov 22, 2020 3:21 pm
It works fine ! Thanks
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Sun Nov 22, 2020 5:10 pm
I enjoyed too fast !

It works fine.... except when script is launched in background (thanks to task scheduler), in which case, nothing happens (no sticky created)
This makes it no usable in my case.

Any idea on why it doesn't work in such environment (and how to remediate...) ?
avatar
Guest
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Sun Nov 22, 2020 7:03 pm
How to create a Sticky in a VBS script 41410

Maybe setting to highest privileges ? Your program is not set to run in a locked desktop mode ?


update:  i created a scheduled task just the vbs script to create a sticky and even without elevated permissions today it showed up at the right time . There must be something special in the conditions to block it ?
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Mon Nov 23, 2020 7:47 am
Thanks for suggestion, but it's already the case "Run with highest privileges"

I added in my script the logging of the returned statuscode (statusCode = WshShell.Run (exeName, 1, true)), and it is 0.... but the Sticky is NOT created (while running the same script "in direct", statuscode is also 0 AND the sticky IS created)

I also did the test to switch in mode "On Error resume next" and log at the end Err object... but no error detected, neither "in direct" (which was likely) nor run as task...
avatar
Guest
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Mon Nov 23, 2020 8:11 am
How to create a Sticky in a VBS script 41710

If you enable the debug logging in stickies you can see if it received a command or if their is an error.
You can try with just the small vb script to create a sticky from within scheduler.
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Mon Nov 23, 2020 9:00 am
I have understood why It works in your case, and not in mine.

It is because I have checked "Run wether user is logged on or not" while you checked "Run only when user is logged on"

On the other hand, since I have defined the right user to run the task, I could understand that the task runs whatever the selected user is logged or not but that its "sticky" part works only is this user is logged on (otherwise, Sticky is not running and APIcmd probably do not succeed in its communication), but if this user is actually logged on, I do NOT understand why APIcmd do not work....

It's a little bit annoying since the main part of the task is designed to be able to run whatever the user is logged on or not...

I'll try to install Sticky in portable mode (with db in same directory than executable) and launch it at windows startup (rather than at user logging) to see if it changes anything or not. Result of test in a couple of hours !

PS : I set the logging mode, and there is logging in all cases where Sticky is created by API, but no logging in any other case.
avatar
LaurentGrenet
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Mon Nov 23, 2020 9:49 am
Result of test : to have Stickies in portable mode do not change anything... Actually, even in this mode, it runs only when user is logged on...

Next test : To have Stickies launched as a Windows service. More complex to implement, so I'll do the test later... and on a virtual machine (I do not want to risk to break everything....)
avatar
Guest
Guest

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Mon Nov 23, 2020 3:31 pm
Ha , i admire your tenacity ! Coding in the twilight zone of NOLOGON is like entering the wastelands of Mordor pale pale no friends , no desktop to create windows only invisible bits moving following instructions by the almighty SYSTEM  .......
avatar
LaurentG
Posts : 104
Join date : 2020-01-16

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Tue Nov 24, 2020 5:10 pm
I eventually did the test.... and it is not a success  Sad

I've been able to launch STICKIES as a service, thanks to SrvStart program (see https://www.howtogeek.com/50786/using-srvstart-to-run-any-application-as-a-windows-service/)
STICKIES starts OK... but, even if I select in service parameters the option"Allow service to interact with desktop" (or something like that : my windows speaks french, and the "french" option is "Autoriser le service à interagir avec le bureau") STICKIES "as a service" do not actually interact with desktop, and do not displays stickies, nor accepts keyboad shortcuts to create new stickies.

As a result, in such environment, STICKIES "technically" runs... but is not usable...

So I give up here my tests.

I'll just post another post in "Features request" to ask for enhancements to apicmd
Admin
Admin
Admin
Posts : 532
Join date : 2018-03-30
Location : London
http://www.zhornsoftware.co.uk

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Thu Dec 03, 2020 10:40 pm
Sookye is right (as usual!) - this is murky territory.  Stickies is designed to run in the user session on the desktop.  When you set the "whether user is logged on or not" then I suspect the task gets run in another context/session, which doesn't have access to the desktop.  That's probably because the desktop isn't guaranteed to exist.

However, you might instead look at networking.  Yes, Stickies may or may not be present to receive a message, but you can run network code in the scheduled task which will speak to whatever is listening on a port, and that can include a process running on the interactive desktop.

Tom
avatar
LaurentG
Posts : 104
Join date : 2020-01-16

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Fri Dec 04, 2020 10:57 am
Hi Tom,


I suspect the task gets run in another context/session, which doesn't have access to the desktop

I am very surprised of that... since (I verified it...) ALL environment variables are exactly the same whatever the task runs in mode "Run wether user is logged on or not" or "Run only when user is logged on"....


However, you might instead look at networking

I did such a test, using the Sticky.exe you provide on the Tools part of your website... and it works !
Whatever the mode the task is running, if Stickies is running, it receives the network sticky, creates it, and Sticky.exe gets a Rc=0
And if for any reason Stickies is not running, of course the network message is not received by anyone and the sticky is not created, but Sticky.exe gets a Rc=1... and then I can implement, only in this case, an alternative method of warning.
Sponsored content

How to create a Sticky in a VBS script Empty Re: How to create a Sticky in a VBS script

Back to top
Permissions in this forum:
You can reply to topics in this forum