Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run VBScript from Excel Amy M Excel Discussion (Misc queries) 4 September 19th 08 09:07 PM
Call API from vbscript via excel. [email protected] Excel Programming 3 June 29th 07 02:10 PM
Call API from vbscript via excel. [email protected] Excel Programming 0 June 28th 07 07:42 PM
Call VBScript from VBA, pass variable, return result to macro? Ed Excel Programming 26 July 11th 06 07:07 PM
Can you call VBScript code from VBA? John Keith[_2_] Excel Programming 1 June 15th 05 12:18 AM


All times are GMT +1. The time now is 12:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"