Hello Guest it is March 28, 2024, 08:58:13 PM

Author Topic: Plugin to run script on Shutdown  (Read 12065 times)

0 Members and 1 Guest are viewing this topic.

Plugin to run script on Shutdown
« 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: [Select]
Declare Sub SetShutdownScriptNum Lib "ShutdownScript" (ByVal Num As Integer)
The plugin does not need to be activated via the "config Plugins" menu.


currently two parameters are passed to the shutdown script.
Parameter 1 = path of Mach3 install folder
Parameter 2 = profile name
« Last Edit: January 06, 2018, 08:10:26 AM by X-TRA78 »
Plugin to run script on Shutdown
« Reply #1 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: [Select]

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.
« Last Edit: January 06, 2018, 08:31:03 AM by X-TRA78 »

Offline Tweakie.CNC

*
  • *
  •  9,196 9,196
  • Super Kitty
    • View Profile
Re: Plugin to run script on Shutdown
« Reply #2 on: January 06, 2018, 11:08:12 AM »
That sounds very interesting, thanks for sharing.

Tweakie.
PEACE
Update: Plugin to run script on Shutdown
« Reply #3 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: [Select]
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)
Re: Plugin to run script on Shutdown
« Reply #4 on: April 27, 2018, 06:50:59 PM »
Hi, can u show us your Sinumerik screenset please?
Re: Plugin to run script on Shutdown
« Reply #5 on: April 30, 2018, 01:00:55 AM »
unfortunately, the ScreenSet isn't finished yet  :(
but i'm still working on it.
Re: Plugin to run script on Shutdown
« Reply #6 on: May 04, 2018, 10: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!!
Re: Plugin to run script on Shutdown
« Reply #7 on: May 07, 2018, 03: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
Re: Plugin to run script on Shutdown
« Reply #8 on: May 07, 2018, 07: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!
Re: Plugin to run script on Shutdown
« Reply #9 on: May 09, 2018, 11: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