Calling win32 API from script
This is a quick tutorial that will show you by examples various ways to call win32 API using Vbs2Exe.
It is recommended not to spik any example as they depend on each other.
Example: Calling Win32 API using XNScript.Call
VBS Example:
Then we called MessageBox API using XNScript.call, and as you may already noticed we first pass it the win32 Dll name that contains this function then the Function Name followed by the function paramters.
Below is another example that shows the command line of the current process
Example: XNHost.Loaddll as equivalent to XNHost.Call
VBS Example:
Then we call MessageBox API using the User32 object
This way makes the code more readable, and very handy if you are going to make many calls to the same dll
Tutorial finished!
You may take a look at Creating Win32 Struct tutorial inorder to be able to call Win32 API that requires a pointer to struct.
It is recommended not to spik any example as they depend on each other.
Example: Calling Win32 API using XNScript.Call
VBS Example:
XNHost.call "user32.dll" , "MessageBox", 0 , "Calling MessageBox API using XNScript.call", "Example", 0As you can see above first we used an already defined object named XNHodst ( same as WScript ).
Then we called MessageBox API using XNScript.call, and as you may already noticed we first pass it the win32 Dll name that contains this function then the Function Name followed by the function paramters.
Below is another example that shows the command line of the current process
Dim CmdPointer CmdPointer = XNHost.Call( "kernel32.dll", "GetCommandLine" ) XNHost.Call "User32.dll", "MessageBox", 0, CmdPointer , "Example", 0
Example: XNHost.Loaddll as equivalent to XNHost.Call
VBS Example:
Dim User32 Set User32 = XNHost.LoadDll( "user32.dll" ) User32.MessageBox 0 , "Calling MessageBox API using XNScript.Loaddll", "Example", 0As you can see we first load the dll where the API is located using XNHost.Loadddll and save the returned value in User32 object.
Then we call MessageBox API using the User32 object
This way makes the code more readable, and very handy if you are going to make many calls to the same dll
Tutorial finished!
You may take a look at Creating Win32 Struct tutorial inorder to be able to call Win32 API that requires a pointer to struct.