Machsupport Forum

Mach Discussion => Finished Plugins for Download => Topic started by: X-TRA78 on January 06, 2018, 08:05:30 AM



Title: Plugin to run script on Shutdown
Post by: X-TRA78 on January 06, 2018, 08:05:30 AM
Hello,

For my new ScreenSet (Sinumerik OP47), i have written a plugin with which one can execute a script (*. vbs or * hta) when Mach3 is shut down.
Maybe someone else need such a function and that's why I uploaded the plugin.

The Script should be stored in the following location.:
{Mach3InstallPath}\Macros\{Profile}\Shutdown(x).(vbs|hta)
It will look first for Shutdown(x).hta and if Not found, then Shutdown(x).vbs.

You can use multiple shutdown scripts, e.g. one to shut down Windows and one to modify XML-Profile and reboot Mach3 etc.

1.Shutdown.vbs
2.Shutdown2.vbs
3.Shutdown3.vbs
4....

The number of the shutdown script (x), can be set by using the "SetShutdownScriptNum (wNum)" subroutine.

Code:
Declare Sub SetShutdownScriptNum Lib "ShutdownScript" (ByVal Num As Integer)

The plugin does not need to be activated via the "config Plugins" menu.
(http://)

currently two parameters are passed to the shutdown script.
Parameter 1 = path of Mach3 install folder
Parameter 2 = profile name


Title: Plugin to run script on Shutdown
Post by: X-TRA78 on January 06, 2018, 08:29:30 AM
Example for Shutdown.vbs to get the Params and wait until Mach3 shut down is finish.

Code:

Dim iCount
Dim iArg
Dim sProfileName
Dim sMach3Path

iCount = wScript.Arguments.Count

if iCount >= 2 then

sMach3Path = wScript.Arguments(0)
sProfileName = wScript.Arguments(1)

Else
' ....
End If

Set svc=getobject("winmgmts:root\cimv2")
sQuery="select * from win32_process where name='mach3.exe'"
set cproc=svc.execquery(sQuery)
iniproc=cproc.count   

Do While iniproc = 1
    wscript.sleep 200
    set svc=getobject("winmgmts:root\cimv2")
    sQuery="select * from win32_process where name='mach3.exe'"
    set cproc=svc.execquery(sQuery)
    iniproc=cproc.count
Loop

set cproc=nothing
set svc=nothing

' Mach3 has been fully shut down.
' now modify XML-Profile or something else.


Title: Re: Plugin to run script on Shutdown
Post by: Tweakie.CNC on January 06, 2018, 11:08:12 AM
That sounds very interesting, thanks for sharing.

Tweakie.


Title: Update: Plugin to run script on Shutdown
Post by: X-TRA78 on January 08, 2018, 03:55:33 AM
Hello,

here is a new version of the plugin (v0.2.2.106).
I've adjusted the search paths for the script and added a new feature that lets you set the search path for the script.
In addition, the name of the first ScreenSet will be passed to the script.

The following function can now be used to set the search path
Code:
Declare Sub SetShutdownScriptPath Lib "ShutdownScript" (ByVal szPath As String)

SetShutdownScriptPath "C:\Mach3\ScreenSetMacros\Test.set\Scripts"

if no search path has been set, it is first searched in dir "{Mach3Path}\Macros\{Profile}\" for the file and then in dir "{Mach3Path}\ScreenSetMacros\{ScreenSetName}.set\"

These three parameters are now passed to the script:

Parameter 1 = path of Mach3 install folder
Parameter 2 = profile name
Parameter 3 = main screenset name (currently only first loaded ScreenSet)


Title: Re: Plugin to run script on Shutdown
Post by: Esteb on April 27, 2018, 05:50:59 PM
Hi, can u show us your Sinumerik screenset please?


Title: Re: Plugin to run script on Shutdown
Post by: X-TRA78 on April 30, 2018, 12:00:55 AM
unfortunately, the ScreenSet isn't finished yet  :(
but i'm still working on it.


Title: Re: Plugin to run script on Shutdown
Post by: Esteb on May 04, 2018, 09:19:37 PM
Hi again, I hope you can finish it soon, I'm starting to work on a PC in kiosk mode to run Mach3, trying to hide the title bar, buttons, and other things like turn off the whole machine with the help of your script.

I'll ask you something, when the script is executed (closing Mach3) a popup message appears asking wich user would execute this program, trying to protect my PC from malicious software. I guess it's a permissions problem, don't?

I really don't have much experience with VB, so please, could you help me?

I just need a good scritp to turn off my pc.

Thanks!!


Title: Re: Plugin to run script on Shutdown
Post by: X-TRA78 on May 07, 2018, 02:24:58 PM
I think it's the UAC of Windows.

You must logged on with an account that belongs to the "Admin Group" and set UAC to a lower level.

I personly would never connect the computer with Mach3 to the Internet,
otherwise you will need an antivirus program which can interfere the run of Mach3.

All my control PCs for my machines are not connected to the internet
and Mach3 is installed with an administrator account and UAC is disabled.

I hope I could help you a little bit.
best regards

X-TRA78


Title: Re: Plugin to run script on Shutdown
Post by: Esteb on May 07, 2018, 06:50:43 PM
Yeah, but is Windows XP SP3, there is not UAC

By the way, where I can find VB scripts examples to start to learn?

thanx!


Title: Re: Plugin to run script on Shutdown
Post by: X-TRA78 on May 09, 2018, 10:12:32 AM
Hello,

Quote
Yeah, but is Windows XP SP3, there is not UAC

Did you logged on with an administrator account?

Quote
By the way, where I can find VB scripts examples to start to learn?

there are many Sites to learn VBScript, for example http://www.herongyang.com/VBScript/index.html
or https://www.youtube.com/watch?v=tnXR3Gwr8w8&list=PLyGqUe6Oa_5GCc-hVJ-Nt06OVGuTc0mS9



Title: Re: Plugin to run script on Shutdown
Post by: Esteb on May 10, 2018, 11:18:02 AM
Hi,

Is the plug-in running through Windows Script Host?

I logged in as administrator, but I would like to run as a single user with limitations like a kiosk mode pc, for that I'm using SteadyState on XP.
My project is a Windows XP with a HMI flat panel, running a kind of kiosk mode, and it works perfectly well!!
The only thing I need, is to power off whole system when closing Mach3.

Just for test, running on Windows 10, works fine

Here I left the dialog asking for which user would run the vb script. I have to unchek protect my computer and data from unauthorized program activity, and hit ok to exetute the script. After that all works fine.


So, I would start to read in some vb forums.