Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Launch .VBS file from button on HTML page 1

Status
Not open for further replies.

Jerz

MIS
Sep 10, 2004
102
US
Can this be done?

I have 3 scripts, .VBS files. The first builds an HTML page and a working file. The other 2 take the working file and perform actions. I need code on the HTML that invokes the other 2 VBS files.

Code:
objPendRpt.writeline "<INPUT TYPE=BUTTON OnClick=" & Chr(34) & "discomp.vbs" & Chr(34) & " VALUE=" & Chr(34) & "Disable" & Chr(34) & "> " & count & " Computers from " & Dom & "<br>"

gives me HTML line:
<INPUT TYPE=BUTTON OnClick="discomp.vbs" VALUE="Disable"> 4 Computers from TestDomain<br>

But that's a syntax error. Any way to do this without putting the contents of the VBS into the HTML as a subroutine? I'd like to keep them seperate if at all possible.
 
Stick this code above the body section and set the onclick event to run the sub.

You can change the strCMD string to:

strCMD = "cmd /c cscript.exe discomp.vbs"

Code:
<script language="vbscript">

Public Sub RunScript()
  Set objWSH = CreateObject("WSCript.Shell")
  strCMD = "cmd /c notepad.exe"
  objWSH.Run(strCMD)
  Set objWSH = Nothing
End Sub 
</script>

<body>

NB the web page will want you to agree to running the activex objects on the page. Just click OK as it is safe.

let me know

cheers
 
Excellent response! I had to make minor modifications, but essentially this works. Time to get out of here today, but I'll post working sample code tommorow.

Thanks again!
 
OK, Here's the VBScript that writes the VBScript subroutine into an HTML file:
Code:
'***************************************************
'*       Verification page header creation         * 
'***************************************************
Set objFSO1 = CreateObject ("Scripting.FileSystemObject")
strOutputDir = Path & "Pending\"
strOutputFile = "PendingComputers.htm"
strFullName = strOutputDir & strOutputFile
Set objPendRpt = objFSO1.CreateTextFile (strFullName, True)
objPendRpt.WriteLine "<html>"
objPendRpt.WriteLine "<head>"
objPendRpt.WriteLine "<title>Computers Pending Disablement/Deletion Report</title>"
objPendRpt.WriteLine "<title>Created " & now & "</title>"
objPendRpt.WriteLine "</head>"
objPendRpt.WriteLine "<script language=" & Chr(34) & "vbscript" & Chr(34) & " RUNAT=" & Chr(34) & "Server" & Chr(34) & ">"
objPendRpt.WriteLine "strDel = " & Chr(34) & "DelComp.vbs" & Chr(34) & ""
objPendRpt.WriteLine "strDis = " & Chr(34) & "DisComp.vbs" & Chr(34) & ""
objPendRpt.WriteLine "dim scriptname"
objPendRpt.WriteLine "Public Sub RunScript(scriptname)"
objPendRpt.WriteLine "  Set objWSH = CreateObject(" & Chr(34) & "WSCript.Shell" & Chr(34) & ")"
objPendRpt.WriteLine "  strCMD = " & Chr(34) & "cmd /c cscript.exe " & path & Chr(34) & " & scriptname"
objPendRpt.WriteLine "  objWSH.Run(strCMD)"
objPendRpt.WriteLine "  Set objWSH = Nothing"
objPendRpt.WriteLine "End Sub"
objPendRpt.WriteLine "</script>"
objPendRpt.WriteLine "<body>"
objPendRpt.WriteLine "<h1>Computers Pending Disablement/Deletion Report</h1>" & vbCrLf
objPendRpt.WriteLine "<h1>Created " & now & "</h1>" & vbCrLf
This is the HTML File Result:
Code:
<html>
<head>
<title>Computers Pending Disablement/Deletion Report</title>
<title>Created 10/12/2004 3:41:16 PM</title>
</head>
<script language="vbscript" RUNAT="Server">
strDel = "DelComp.vbs"
strDis = "DisComp.vbs"
dim scriptname
Public Sub RunScript(scriptname)
  Set objWSH = CreateObject("WSCript.Shell")
  strCMD = "cmd /c cscript.exe V:\vbscripts\oldpcs\" & scriptname
  objWSH.Run(strCMD)
  Set objWSH = Nothing
End Sub
</script>
<body>
<h1>Computers Pending Disablement/Deletion Report</h1>

<h1>Created 10/12/2004 3:41:16 PM</h1>

Had to store the names of the external .VBS files into variables - could not get them passed to the subroutine any other way (and I tried several....)

And here's a button:
Code:
objPendRpt.WriteLine "<br>"
objPendRpt.writeline "<INPUT TYPE=BUTTON OnClick=" & Chr(34) & "RunScript strDis" & Chr(34) & " VALUE=" & Chr(34) & "Disable" & Chr(34) & "> " & count & " Computers in the " & Dom & " Domain?<br>"
objPendRpt.WriteLine "<br>"

Resulting in HTML:

Code:
<br>
<INPUT TYPE=BUTTON OnClick="RunScript strDis" VALUE="Disable"> 829 Computers in the ******** Domain?<br>
<br>

Now if only I could get the disable computer script to disable the computers........

"It just goes to show you, it's always somethin'" - Roseanne Roseannadanna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top