Click to See Complete Forum and Search --> : Communication between .vbs files and Javascript
Caliban
07-24-2003, 09:05 PM
Hi,
these are the facts:
1) I have a .vbs file, called profile.vbs; this is this content:
dim shell, WshNetwork
dim oprinters, env, strprnt, strprntnme, maxprnt, i, n
set shell = Wscript.createobject("Wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
set env = shell.Environment
msgbox wshNetwork.username 'This is the username
msgbox WshNetwork.computername 'This is the internal computer name what my PC is called in My Computer => Properties => Computer Name.
2) The .vbs file has 2 out parameters: wshNetwork.username and WshNetwork.computername. I want these 2 out parameters to assign its values in two variables in JavaScript
Any ideas? Is it possible?
T.I.A.
Khalid Ali
07-24-2003, 09:51 PM
I sense foul play,why would you need such information using javascript???
Exuro
07-24-2003, 09:52 PM
You could always stick them in some Hidden form elements and have JavaScript grab them from there...
Caliban
07-25-2003, 08:40 AM
Khalid:
I need this info, because I'm developing a PC inventory app, which needs to retrieve the PC of the user who enters to the page. The closest code I found was this, but in VBScript.
I've seen it's possible to do this in JavaScript, if the browser=Netscape ...
I'm not trying to hack anybody (I don't have knowledgement enough to be a hacker, not even want to become it), just to capture the PC name for app purposes only ...
Exuro:
I thought the same you wrote, but ... how to do it? just a simple piece of code...
I think i'm close of what I need, just a li'l push in this direction is what i need.
Thanx both of you, for your kind interest. Still keep on recieving ideas/li'l sample code ...
Exuro
07-26-2003, 12:41 AM
Maybe something like this:
<html>
<body onload="alert(document.frm1.var1.value)">
<form name="frm1">
<input id="var1" type="hidden">
</form>
<script type="text/vbscript">
<!--
document.frm1.var1.value = inputbox("Enter Variable Value:")
//-->
</script>
</body>
</html>
Caliban
07-28-2003, 08:51 PM
Hi JS gurues,
This piece of code is driving me crazy! :(
When I try to execute it, an error is displayed: "An object is required:Wscript".
What can I do?
This is the code as follow:
=============================
<html>
<head>
<title>Test Page - VBScript Version</title>
<style TYPE="text/css">
.Arial9 { font-family: Arial; font-size: 9pt; }
.ColorList { font-family: Arial; font-size: 9pt; width: 120px; background-color: ECECEC; }
.MoveButton { font-family: Arial; font-size: 9pt; width: 80px; }
</style>
<script language="vbscript">
dim RS, MainMenu,objConn, shell, WshNetwork
dim oprinters, env, strprnt, strprntnme, maxprnt, i, n
set shell = Wscript.createobject("Wscript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
set env = shell.Environment
msgbox wshNetwork.username
msgbox WshNetwork.computername
</script>
</head>
<body>
</html>
==================
... but if I execute the script "profile.vbs" .... it works fine .... :confused: I dunno why ...!!!
I attach a .zip file in this message -if you want to take a look at it-, with:
1) The file "profile.vbs"
2) The error screen with the message "Se requiere un objeto" (an object is required)
Any ideas?
T.I.A.
neenach2002
07-28-2003, 09:05 PM
weird...I've seen that error message before...
when I run the webpage that has the script embedded in it, it gives me a dialog box, in which I can "input" something...when I input it, it gives me an alert, saying whatever I input...
By-The-Way...I used Exuro's code when I got the diaog box/alert popup!
When I ran your code, Caliban, I got a blank screen, are you sure that you have put in script to run "profile.vbs" in your version of the script?
Exuro
07-28-2003, 09:24 PM
Only thing I can think of is that IE doesn't give you access to the WScript object, for security reasons...
neenach2002
07-28-2003, 09:26 PM
oh...I'll try to remember that...too bad...cuz I HATE netscape...it ALWAYS crashes...ALWAYS
Caliban
07-29-2003, 09:08 AM
Hi JS gurues,
here are my responses:
==========
neenach2002:
==========
In the web page, there's no more than the text of the script "profile.vbs"
So, the blank screen is OK for you to display.
The web page only displays the values of the user, internal PC name. No more.
==========
Exuro:
==========
The IE restrictions you said ... sounds me, I'll try to investigate ...
By the way, my security level in "internet" (as my IE properties said) is "halfway" (between "high" and "low" - I hope you to understand my English-writing :)
T.I.A. ... keep on investigating and/or receiving your ideas/li'l sample codes :D
Caliban
07-29-2003, 10:25 AM
Hi JS gurues,
in another forum i realized myself that I was running the HTML code in my PC, so I put this HTML code in my web server and it works.
It displays the username and the PC name in a message box.
But, i can't get their values in the input text fields USER and PC_NAME. An error ocurred, this is the message:
"The object does not accept this property or method:
document.USERDATA"
So, how can I put these values in a form fields, using VBScript?
This is the right code:
======
<HTML>
<HEAD>
<TITLE>TEST PAGE - VBSCRIPT VERSION</TITLE>
<STYLE TYPE="TEXT/CSS">
.ARIAL9 { FONT-FAMILY: ARIAL; FONT-SIZE: 9PT; }
.COLORLIST { FONT-FAMILY: ARIAL; FONT-SIZE: 9PT; WIDTH: 120PX; BACKGROUND-COLOR: ECECEC; }
.MOVEBUTTON { FONT-FAMILY: ARIAL; FONT-SIZE: 9PT; WIDTH: 80PX; }
</STYLE>
<SCRIPT LANGUAGE="VBSCRIPT">
DIM RS, MAINMENU,OBJCONN, SHELL, WSHNETWORK, ENV
SET SHELL = CREATEOBJECT("WSCRIPT.SHELL")
SET WSHNETWORK = CREATEOBJECT("WSCRIPT.NETWORK")
SET ENV = SHELL.ENVIRONMENT
MSGBOX WSHNETWORK.USERNAME
MSGBOX WSHNETWORK.COMPUTERNAME
document.USERDATA.USER.value = WSHNETWORK.USERNAME
document.USERDATA.PC_NAME.value = WSHNETWORK.COMPUTERNAME
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME='USERDATA'>
USER :<INPUT TYPE='TEXT' NAME='USER' ID='USER' ><BR>
PC NAME:<INPUT TYPE='TEXT' NAME='PC_NAME' ID='PC_NAME'><BR>
</FORM>
</BODY>
</HTML>
======
Any ideas?
T.I.A.
Caliban
07-29-2003, 10:34 AM
<HTML>
<FORM NAME='USERDATA'>
USER :<INPUT TYPE='TEXT' NAME='USER' ID='USER' ><BR>
PC NAME:<INPUT TYPE='TEXT' NAME='PC_NAME' ID='PC_NAME'><BR>
</FORM>
<SCRIPT LANGUAGE="VBSCRIPT">
DIM RS, MAINMENU,OBJCONN, SHELL, WSHNETWORK, ENV
//SET SHELL = WSCRIPT.CREATEOBJECT("WSCRIPT.SHELL")
//SET WSHNETWORK = WSCRIPT.CREATEOBJECT("WSCRIPT.NETWORK")
SET SHELL = CREATEOBJECT("WSCRIPT.SHELL")
SET WSHNETWORK = CREATEOBJECT("WSCRIPT.NETWORK")
SET ENV = SHELL.ENVIRONMENT
MSGBOX WSHNETWORK.USERNAME
MSGBOX WSHNETWORK.COMPUTERNAME
document.USERDATA.USER.value = WSHNETWORK.USERNAME
document.USERDATA.PC_NAME.value = WSHNETWORK.COMPUTERNAME
</SCRIPT>
<BODY>
</BODY>
</HTML>
=======
The form input fields must be declared before the script
Comments are welcome.
T.I.A.
Exuro
07-29-2003, 10:41 AM
That works great... I was just about to reply and say that you needed to move your vbscript after the form declaration, then when I hit "Preview Reply" you had already posted an update :-p. Anyway, yeah, now all you need to do is change the form elements from Text to Hidden, and then call your JavaScript to work on them from an onLoad, or a Button, or something... Nice job!
Caliban
07-29-2003, 11:00 AM
Thanx for your kind comment :cool:
The last thing I have to say, is that I have to activate all the parameters under "ActiveX" in my intranet security profile (in IE's Tools-> Options-> Security -> Intranet )
because another co-worker tried to execute the page and he didn't get anything, so I activated all the parms in ActiveX and it works for him. So, I think the security guys have a work with this code, because I don't have to cause a collateral damage with this one :)
If you know/hear how to register this VBScript code, I'll appreciate it.
Finally, thanx for your kind support and patient, and I also hope this code to be helpful for you in any moment.
Best regards.