Trigger IFTT from Windows Command Line - ifttt

I have a Tuya-based smart outlet and want to be able to trigger it on/off via windows command line. It appears all of the Tuya API is built for Linux. If I link my outlet to IFTTT is there a user-friendly way to control that outlet via batch file/command line?
Thanks,
Mike

I ended up using CURL to call the IFTTT webhook, one for an the outlet's "on" command and another for an "off" command. I can then use these CURL calls in my batch file and trigger the outlet on/off as needed.

Related

Create different MSIX installers using a flag parameter on a .NET MAUI app

I want to automatically create different MSIX packages/installers for the same MAUI app, so that each one runs a specific code snippet according to a flag parameter.
The user does not have to interact with the app. An installer per flag value has to be created, an once the app is installed and the user double clicks the app icon, the specific piece of code has to be run.
So far, I've tried without success the following approach, trying to create a script that passes the possible values of the flag as installation parameters using the app installer and a protocol, and then trying to publish the different packages in a local path.
I would like to know whether that's feasible or there may be any other approach to get it done.
You can check this comment about .NET MAUI Windows target publishing/archiving.
In the article, the right way to set the MSIX is that you had to create a self-signed certificate and then You could add a couple of extra parameters to also add the sign the MSIX and then trust that cert manually.

Can I execute an executable file from a webview?

Is there a way to execute an executable file(.bat/.sh) from a webview? I have a button on a webview and would like to run the executable when that button is clicked. I looked into window.open(...) and ActiveXObject() but since a webview is not a browser window, they are irrelevant.
You could do this by contributing a Command which executes the script, and then creating a link that runs that command using a command URI in the WebView.
Let's call the command my.ext.runScript. Then we can add in our webview:
Run Script
Clicking that link will then invoke the script.
edit: Example
edit 2: You can also pass a message from the webview to your extension to invoke the command - documentation here.
Good luck!
I believe this is not possible. You don't have any browser or Node.js environment available in the web view. Also for security reasons the webview is pretty limited in what it can do, besides showing HTML content.
I was able to find a way. A webview communicates with your node env using the vscode api using the postMessage function. In the node env, you can spawn and handle a child process.
Docs:
VSCode postMessage
Node childProcess
Edit 1:
Example: VSCode Extension Tutorial
Let me know if you need further help. Thanks (:

I want to call an installer class on a button click in C#. Is it possible?

How can I call an installer class on a button click event which read from the registry and also write a value in the registry in C#?
This cannot be done with a single custom action. You should have 2 separate custom actions:
one which is executed on button click and reads information from registry
another one which writes information in registry during install
The second action needs Administrator privileges and should run as deferred with no impersonation in InstallExecuteSequence.
Assuming you want to set installer properties based on what is read from registry, using an Installer Class is not really an option. I recommend using a DLL custom action which gets a handle to the installer session. You can find a tutorial here:
http://www.codeproject.com/KB/install/msicustomaction.aspx

Easily reuse views, controller, layout in a command line interface

My Zend application is going to get an command line php script that should email reports. There generation depends on Zend_View, Zend_Layout and is currently already working fine in the web interface.
How can I reuse this whole MVC functionality in the command line?
Should I add a new controller CommandLineController and call this somehow from the commandline?
How can I kick of such a Controller manually, without having a HTTP request?
I would recommend to check out this excelent tutorial for the Zend Framework from the command line:
Tutorial

How to run my program on before logout on windows XP?

I am looking for an inverse version of "RunOnceEx".
RunOnceEx does run some program, before the user's shell(desktop&taskbar) start. The login progress will not continue before the runonceex complete.
I want to do exact the same but on user logout.
When she/he logout, all running program shutdown, leaving shell(desktop&taskbar), then ""I wish my program will be execute this moment"", finally logout.
I think it is possible because the "mobsync.exe" is doing that. But I cannot find where and how to do it.
Warning, as said here, gpedit.msc will allow you to configure a logoff script for all users.
If you need that script only for one user, you need to declare it directly in the registry, both in HKCU and HKLM.
To run this only for the current user, you can use WMI to get an information when a shutdown/logout occurs.
Either you write a small C# (or any other language that can use WMI) application or vbs script to listen on the Win32_ComputerShutdownEvent WMI event.
An example C# app can be found here in this question: Get Log off event from system
found in the first result on google for me
To execute a program you can create a script to run it and use group policy to enforce it.
In Group Policy Editor navigate to User Configuration-->Windows Settings-->Scripts (Logon/Logoff)
more information here
If you want a running program to execute code on logoff, then you should hook the WM_QUERYENDSESSION message and look for an lParam value of ENDSESSION_LOGOFF (0x80000000).
It's important to test for this lParam value because the other ones indicate a "forced close" - i.e. your process may be killed before your code is even allowed to run. In fact, most shutdown/session-end messages are only intended to give you an opportunity to run last-minute cleanup code and aren't that safe to respond to with long-running actions; but this particular combination should be OK.
Note: I've never tried to actually run a separate process in response to the WM_QUERYENDSESSION message. It's possible that the window manager will disallow this, like it does during shutdown. Try it and see, I guess.
If you're in a .NET environment (you didn't specify), a quicker way is to add an event handler to the Microsoft.Win32.SystemEvents.SessionEnding event.
What you need is an implementation of GINA. You can run your custom commands in WlxIsLogoffOk function, which gets called when the user initiates a logoff
Once you create the proper GINA dll you can register it here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\#GinaDLL
Here is an implementation which may fit your needs (it provides a Logoff registry key where you could specify your command):
http://wwwthep.physik.uni-mainz.de/~frink/newgina_pre09/readme.html
As VonC and TFD already mentioned, the Group Policy Editor is just another way to manipulate the registry.
Just make with gpedit the changes (in Userconfig - Windows Settings - Scripts) you like and afterwards take a look in the registry at [HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts]
to find out how you can do that directly.
Also on my PC (hanging in a domain) is a hidden folder C:\WINDOWS\System32\GroupPolicy with subfolders for user and machine. Both having additional subfolders called Shutdown and Startup. Maybe you can also use these ones.
If you need something simple and working for a single (or any) user you can make a simple application in C++ or C# for example.
The simplest is having a C# in tray (by simply adding the tray component to the form) and register and event handler for the FormClosing event. It'd look like this:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason != CloseReason.UserClosing)
{
// It's not the user closing the application,
// Let's do whatever you want here, for example starting a process
Process notePad = new Process();
notePad.StartInfo.FileName = "notepad.exe";
notePad.StartInfo.Arguments = "ProcessStart.cs";
notePad.Start();
}
}
So your application will be started with Windows or with the user. It'll wait (using a little bit of memory) and will do something when the system shuts down, or the user log off, etc (by checking "CloseReason" above).