PC Review


Reply
Thread Tools Rate Thread

Call API from vbscript via excel.

 
 
camille.reeves@gmail.com
Guest
Posts: n/a
 
      28th Jun 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to call a vbscript within a vbscript Karuna Microsoft Access VBA Modules 1 6th Oct 2008 02:12 PM
Call API from vbscript via excel. camille.reeves@gmail.com Microsoft Excel Programming 3 29th Jun 2007 02:10 PM
Call API from vbscript via excel. camille.reeves@gmail.com Microsoft Excel Programming 0 28th Jun 2007 07:42 PM
Call VBScript From .NET Jordan S. Microsoft C# .NET 16 11th Aug 2006 11:57 AM
Call VBScript from C# Art Vandelay Microsoft C# .NET 1 9th Feb 2004 03:24 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:57 PM.