Use sendMessage and Findwindow with VBscript
-
Hi, I have an web application running on a applicationserver. Now I want to shutdown local software on the client from the browser. I use asp.net but I realized I needed av VBscript to execute on the local client to be able to get a handle for the local applicaition that I want to shutdown. But how do I use the WINAPI methods sendMessage and findWindow in VBscript. I know I have to import user32.dll. Im really bad at scripting...) THANKS! Ibana
-
Hi, I have an web application running on a applicationserver. Now I want to shutdown local software on the client from the browser. I use asp.net but I realized I needed av VBscript to execute on the local client to be able to get a handle for the local applicaition that I want to shutdown. But how do I use the WINAPI methods sendMessage and findWindow in VBscript. I know I have to import user32.dll. Im really bad at scripting...) THANKS! Ibana
VBScript, or any script running in a browser for that matter, has absolutely no access to the Win32 Api. It's impossible to do what you want from inside a browser session without the user downloading, installing, and allowing script to execute, a custom COM object that does the same thing. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
VBScript, or any script running in a browser for that matter, has absolutely no access to the Win32 Api. It's impossible to do what you want from inside a browser session without the user downloading, installing, and allowing script to execute, a custom COM object that does the same thing. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
thanks for your replay, Do you have any suggestion how to access the winapi on the local machine from my asp.net/C# application running on a server. I need to use the winapi to shutdown a local installed software. Should a make a small app that runs on the local machine that calls the winapi? Are there any better solutions? /ibana
-
thanks for your replay, Do you have any suggestion how to access the winapi on the local machine from my asp.net/C# application running on a server. I need to use the winapi to shutdown a local installed software. Should a make a small app that runs on the local machine that calls the winapi? Are there any better solutions? /ibana
There is NOTHING in your ASP.NET code that can get to the client machine. It's IMSPOSSIBLE. Your app will have absolutely no permissions onthe local machine. Also, script running inside a browser session will not have any access to other processes running outside the browser session and has no access to any client hardware or system resources. The user MUST install a component to do this, and it will ONLY work if security inside the browser is stripped down to nothing! Your web app cannot stop a process outside the browser, period, unless the user turns the security for the zone your code came from down to nothing! This is something that no sane network admin on earth would do! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
VBScript, or any script running in a browser for that matter, has absolutely no access to the Win32 Api. It's impossible to do what you want from inside a browser session without the user downloading, installing, and allowing script to execute, a custom COM object that does the same thing. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
I know this is a bit old discussion, but thought of sharing this: Info/Theory: ~~~~~~~~~~~ User32.dll is the source of many of the most common Windows API's, that allow you to interact with the operating system at a lower level. Please check: https://social.msdn.microsoft.com/Forums/windows/en-US/b04153ff-e4fb-4500-a8e4-3a685208af57/when-to-use-user32dll-and-how?forum=winforms Following is the code to access Win32 API using VBSCript. --------------------------------------------------------- ' --------------- Start of Code ------------------------------------------------------------ Dim excel Set excel = CreateObject("Excel.Application") Dim strMacro strMacro = "CALL('user32', 'MessageBoxA', 'JJCCJ', 0, 'Hello, Win32 API(VBScript) World - My call via User32 dll!', 'Hello, World!', 0)" strMacro = Replace( strMacro, "'", """" ) excel.ExecuteExcel4Macro( strMacro ) '---------------- End of Code -------------------------------------------------------------- Copy the above to a notepad & save it as : myMessage.vbs and double click it. Expected Result: Please see the script in action : Windows API VBScript Calling User32 DLL directly - YouTube[^]
-
I know this is a bit old discussion, but thought of sharing this: Info/Theory: ~~~~~~~~~~~ User32.dll is the source of many of the most common Windows API's, that allow you to interact with the operating system at a lower level. Please check: https://social.msdn.microsoft.com/Forums/windows/en-US/b04153ff-e4fb-4500-a8e4-3a685208af57/when-to-use-user32dll-and-how?forum=winforms Following is the code to access Win32 API using VBSCript. --------------------------------------------------------- ' --------------- Start of Code ------------------------------------------------------------ Dim excel Set excel = CreateObject("Excel.Application") Dim strMacro strMacro = "CALL('user32', 'MessageBoxA', 'JJCCJ', 0, 'Hello, Win32 API(VBScript) World - My call via User32 dll!', 'Hello, World!', 0)" strMacro = Replace( strMacro, "'", """" ) excel.ExecuteExcel4Macro( strMacro ) '---------------- End of Code -------------------------------------------------------------- Copy the above to a notepad & save it as : myMessage.vbs and double click it. Expected Result: Please see the script in action : Windows API VBScript Calling User32 DLL directly - YouTube[^]
That's cute and all, but it also requires Office be installed on the machine in order to work and that's not going to be the case on every machine. Frankly, using Excel as an intermediary just to run a single line of code is a very heavy cost and a bit ridiculous.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
That's cute and all, but it also requires Office be installed on the machine in order to work and that's not going to be the case on every machine. Frankly, using Excel as an intermediary just to run a single line of code is a very heavy cost and a bit ridiculous.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThis only happens if you have any of the following type of laptops: a) Mac / MacBook with IoS b) Laptop used exclusively for non-MS office testing c) New Laptop with no MS Office Installed d) Loaner laptop with no MS Office e) Sometimes if you have had a crash of MS Office on your laptop - then also the Excel Application will not work - for this. f) if your enterprise IT has disabled using MS Office COM Objects and/or restricted authorization to use MS Office COM objects/APIs. ELSE I do not know of any other reason - any laptop not having MS Office installed. But the solution does work - and you do not need to use any other tools. :thumbsup: Good luck.
-
This only happens if you have any of the following type of laptops: a) Mac / MacBook with IoS b) Laptop used exclusively for non-MS office testing c) New Laptop with no MS Office Installed d) Loaner laptop with no MS Office e) Sometimes if you have had a crash of MS Office on your laptop - then also the Excel Application will not work - for this. f) if your enterprise IT has disabled using MS Office COM Objects and/or restricted authorization to use MS Office COM objects/APIs. ELSE I do not know of any other reason - any laptop not having MS Office installed. But the solution does work - and you do not need to use any other tools. :thumbsup: Good luck.
First, using a heavy weight application, like Excel, to call a couple of Win32 API's is ridiculous. Also, going back to the original context of the question, the script, running in a browser, can NOT create an instance of Excel. COM-interop is off-limits because of security concerns. It's also the reason ActiveX is no longer supported by browsers.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak