Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Call API from vbscript via excel.
I'm trying to write a script that uses MS Office to make API calls to
prevent logoff/shutdown from happening (I'm using Office as proxy since you can't directly call an API from a script). I found a sample script on the internet that uses MS Excel to make the API call, GetTickCount. What changes do I need to make in order to get this script to work for the API call AbortSystemShutdown. Let me explain why I'm asking. I work at a software company and we use VMware Workstation all the time to do manual QE testing and run automation on virtual machines. Every so often someone will log off a computer while VMs are running. This would always be a real pain when they were shut off without warning. I need to write a script that would check for the vmware-vmx executable file and (if the executable is found) display a message to the user telling them VMs are running and prevent shut down or log off from happening. Otherwise, if the executible isn't found, do nothing, let the shutdown proceed. I have two scripts to do this. The first searches for the executible. The second script below is only for making the API call to prevent shutdown, if the executible is found. How do I get it work? <?xml version="1.0" encoding="ISO-8859-1" ? <package <job <object id="xl" progid="Excel.Application"/ <script language="VBScript" <![CDATA[ ' blatantly stolen from: ' HOWTO: Create and Call an Excel Macro Programmatically from VB ' (Q194611) ' Start Excel ' Make it visible... xl.Visible = True ' Add a new workbook Set xlBk = xl.Workbooks.Add ' Add a module Set xlMod = xlBk.VBProject.VBComponents.Add(1) ' Add a macro to the module... strCode = Getresource("mac") xlMod.CodeModule.AddFromString strCode ' Run the new macro! xl.Run "MyMacro" Set xlMod = Nothing xlBk.Saved = True xl.Quit ]] </script <resource id="mac" <![CDATA[ Declare Function AbortSystemShutdown Lib "advapi32" Alias "AbortSystemSHutdownA" ( _ ByVal lpmachineName As String) As Long Sub MyMacro() AbortSystemShutdown End Sub ]] </resource </job </package |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Run VBScript from Excel | Excel Discussion (Misc queries) | |||
Call API from vbscript via excel. | Excel Programming | |||
Call API from vbscript via excel. | Excel Programming | |||
Call VBScript from VBA, pass variable, return result to macro? | Excel Programming | |||
Can you call VBScript code from VBA? | Excel Programming |