Hi, I am tring to automate some tasks using vbscript at my job. Below is a simple version of the code I have so far.
The example code below is using notepad as a test application; it is to run and receive data from vbscript's sendkeys. The data that the vbscript function is sending is received from the javascript function generate().
This worked just fine on my home computer with Windows 2000 but when I opened it up with my work computer running Win NT 4.0 it only ran the FIRST time and then every time after that it generated an error like ActiveX can't CreateObject("WScript.Shell". Actually, when I simplified the program to post on this site it worked a few times and then errored in the same way after.
Please Help!! Thanks,
Jason
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Form
</TITLE>
<META content="text/html; charset=windows-1252">
<META content="Microsoft FrontPage 4.0" name="GENERATOR">
<META content="FrontPage.Editor.Document" name="ProgId">
<SCRIPT language="javascript" type="text/javascript">
<!--
function generate(){
//Form field variables
Client_field_var = ""
AcctMgr_field_var = ""
//Variable to hold all form field variables
Form_1_content = ""
//If a value is entered in the form field, assign it to its variable
if(document.Form_1.Client_field.value != ""{Client_field_var = document.Form_1.Client_field.value}
if(document.Form_1.AcctMgr_field.value != ""{AcctMgr_field_var = document.Form_1.AcctMgr_field.value}
//Compile the 'Form_1_content' variable based on the variables that were assigned a value
if(Client_field_var != ""{Form_1_content += Client_field_var + "\n"}
if(AcctMgr_field_var != ""{Form_1_content += AcctMgr_field_var + "\n"}
//variables that will begin and end in the output
Form_1_start = "Begin Stuff\n"
Form_1_end = "End Stuff"
//Dump value into text area
document.Form_1.output.value = Form_1_start + Form_1_content + Form_1_end
}
//-->
</SCRIPT>
<SCRIPT language="vbscript">
function PassToNotepad
Dim strPassedValue
Dim ss
Dim starttime,waittime,currenttime
strPassedValue = document.Form_1.output.value
waittime = 5
Set ss = CreateObject("WScript.Shell"
ss.run "C:\WINNT\NOTEPAD.EXE",1
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strPassedValue
Set ss = nothing
end function
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM name="Form_1">
<B>Create Job Request</B>
<BR><BR>
Client name: <INPUT size="10" name="Client_field" value="Client Name"><BR>
Account Manager: <SELECT name="AcctMgr_field" size="1">
<OPTION value="1" selected>1 - John Doe</OPTION>
<OPTION value="2">2 - Jane Jones</OPTION>
</SELECT>
<BR><BR>
<INPUT name="button" type="button" onclick="generate()" value="Generate"><BR>
Output: <TEXTAREA name="output" rows="4" cols="25">
</TEXTAREA><BR>
<INPUT type="button" value="Send to Notepad" id="button2" name="button2" onclick="PassToNotepad()">
</FORM>
</CENTER>
</BODY>
</HTML>
The example code below is using notepad as a test application; it is to run and receive data from vbscript's sendkeys. The data that the vbscript function is sending is received from the javascript function generate().
This worked just fine on my home computer with Windows 2000 but when I opened it up with my work computer running Win NT 4.0 it only ran the FIRST time and then every time after that it generated an error like ActiveX can't CreateObject("WScript.Shell". Actually, when I simplified the program to post on this site it worked a few times and then errored in the same way after.
Please Help!! Thanks,
Jason
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
Form
</TITLE>
<META content="text/html; charset=windows-1252">
<META content="Microsoft FrontPage 4.0" name="GENERATOR">
<META content="FrontPage.Editor.Document" name="ProgId">
<SCRIPT language="javascript" type="text/javascript">
<!--
function generate(){
//Form field variables
Client_field_var = ""
AcctMgr_field_var = ""
//Variable to hold all form field variables
Form_1_content = ""
//If a value is entered in the form field, assign it to its variable
if(document.Form_1.Client_field.value != ""{Client_field_var = document.Form_1.Client_field.value}
if(document.Form_1.AcctMgr_field.value != ""{AcctMgr_field_var = document.Form_1.AcctMgr_field.value}
//Compile the 'Form_1_content' variable based on the variables that were assigned a value
if(Client_field_var != ""{Form_1_content += Client_field_var + "\n"}
if(AcctMgr_field_var != ""{Form_1_content += AcctMgr_field_var + "\n"}
//variables that will begin and end in the output
Form_1_start = "Begin Stuff\n"
Form_1_end = "End Stuff"
//Dump value into text area
document.Form_1.output.value = Form_1_start + Form_1_content + Form_1_end
}
//-->
</SCRIPT>
<SCRIPT language="vbscript">
function PassToNotepad
Dim strPassedValue
Dim ss
Dim starttime,waittime,currenttime
strPassedValue = document.Form_1.output.value
waittime = 5
Set ss = CreateObject("WScript.Shell"
ss.run "C:\WINNT\NOTEPAD.EXE",1
starttime = Timer()
currenttime = starttime
Do Until currenttime-starttime > waittime
'Do nothing
currenttime = Timer()
Loop
ss.SendKeys strPassedValue
Set ss = nothing
end function
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM name="Form_1">
<B>Create Job Request</B>
<BR><BR>
Client name: <INPUT size="10" name="Client_field" value="Client Name"><BR>
Account Manager: <SELECT name="AcctMgr_field" size="1">
<OPTION value="1" selected>1 - John Doe</OPTION>
<OPTION value="2">2 - Jane Jones</OPTION>
</SELECT>
<BR><BR>
<INPUT name="button" type="button" onclick="generate()" value="Generate"><BR>
Output: <TEXTAREA name="output" rows="4" cols="25">
</TEXTAREA><BR>
<INPUT type="button" value="Send to Notepad" id="button2" name="button2" onclick="PassToNotepad()">
</FORM>
</CENTER>
</BODY>
</HTML>