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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot RUN wscript from HTML 2

Status
Not open for further replies.

solomongrundy

IS-IT--Management
Dec 3, 2010
5
US
Hello all,


I currently have a .vbs script that I use to create user accounts in Active directory. I usually execute 'wscript Script.exe' from the cmd line to execute it. I want to make a webpage that has an 'onClick' event from a button that will execute this action. However, whenever I try to, nothing happens. Can anybody please show me where I am going wrong. Thank you for your time. I am pasting some simple HTML code below:


<html>
<head>
<title>test</title>
</head>
<script language="vbscript">

Public Sub RunScript
Set objShell = CreateObject("WScript.Shell")
objShell.Run = "wscript.exe C:\Scripts\Script.vbs"


End Sub

</script>
<body>
<h1>testing</h1>

<h1>testing things</h1>

<br>
<INPUT TYPE=BUTTON OnClick="RunScript" VALUE="RUN"> text<br>

<br>
</body>
</html>


This HTML file resides in the Scripts folder with the .vbs file.


Thanks,


Solomon
 
>objShell.Run = "wscript.exe C:\Scripts\Script.vbs"[/i
At least this.
[tt]objShell.Run "wscript.exe C:\Scripts\Script.vbs"[/tt]
When creating objShell you may or may not be asked for expressed permission.
 
tsuji,

I cannot tell what I am supposed to do by your thread. Can you please clarify? Error, I tried your approach but to no avail..
 
I meant simply thism as far as the proper syntax is concerned.
[tt]
<script language="vbscript">

Public Sub RunScript
Set objShell = CreateObject("WScript.Shell")
objShell.Run "wscript.exe C:\Scripts\Script.vbs"
End Sub

</script>
[/tt]
 
I do not see the difference between what you have posted and what i have in the code I have above...
 
[tt]objShell.Run[highlight] [/highlight]"wscript.exe C:\Scripts\Script.vbs"[/tt]
 
Anyway, for permission issue, I'd use an HTA instead of an HTML.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
THANKS GUYS. PHV, I had changed it to an hta before which was a trick but it didn't work until that '=' was removed. Friggin '='!! Now it works.

I have another question that I don't know the answer to and was kind of seeking some guidance because I am new to VBS. So, my VBS script simply creates 'User Accounts' from data from an Excel Sheet. However I have to manually change the 'OU' in the script everytime I want to run it.

I have a script that will create the OU and I want to put that in the script that will create the Accounts. Yet, I want a User input to go to a variable which will represent the OU. I have tried but the script will not wait for the input of the user before finishing, therefore does not work.
Any ideas?
Here is the code:
---------------------------------


Function UserInput( myPrompt )
' This function prompts the user for some input.
' When the script runs in CSCRIPT.EXE, StdIn is used,
' otherwise the VBScript InputBox( ) function is used.
' myPrompt is the the text used to prompt the user for input.
' The function returns the input typed either on StdIn or in InputBox( ).

' Check if the script runs in CSCRIPT.EXE
If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then
' If so, use StdIn and StdOut
WScript.StdOut.Write myPrompt & " "
UserInput = WScript.StdIn.ReadLine
Else
' If not, use InputBox( )
UserInput = InputBox( myPrompt )
End If
End Function

Option Explicit
Dim objRoot, objDomain, objOU
Dim Name

strInput = UserInput( "Enter an OU:" )
Name ="OU= & strInput"

' Section to bind to YOUR Active Directory.
Set objRoot = GetObject("LDAP://rootDSE")
objDomain = objRoot.Get("defaultNamingContext")
Set objDomain = GetObject("LDAP://" & objDomain)

' Section to create the OU defined by strContainer
' Also note the use of: .SetInfo

'On Error Resume next
Set objOU = objDomain.Create("organizationalUnit", Name)
objOU.SetInfo

WScript.Echo "New Top Level OU created = " & Name
WScript.quit

'This script inputs info from an Excel Sheet to create AD Users. Make Sure the 'ou' is
'correct and accordingly.
'If any of the attributes do not contain values and the On Error Resume Next statement
'is not present, the script returns the following ADSI error message when the Get or
'GetEx method attempts to read values of the nonexistent attributes:



On Error Resume Next
Set objExcel = CreateObject("Excel.Application")

Set objWorkbook = objExcel.Workbooks.Open("C:\CS310New.xlsx")

'This line starts the script with the second row
intRow = 2

'This value enables the account upon creation
'intAccValue = 512

'Enter Loop
Do Until objExcel.Cells(intRow,1).Value = " "
Set objOU = GetObject("LDAP://ou= & strInput, dc=cub, dc=coyote, dc=net")

Set objUser = objOU.Create("User", "cn=" & objExcel.Cells(intRow, 1).Value)

'Login Name
objUser.sAMAccountName = objExcel.Cells(intRow, 2).Value
'First Name
objUser.GivenName = objExcel.Cells(intRow, 3).Value
'Last Name
objUser.SN = objExcel.Cells(intRow, 4).Value


objUser.AccountDisable = FALSE
objUser.SetInfo
'objUser.Put "userAccountControl", intAccValue

'Increment to next row
intRow = intRow + 1
Loop

objExcel.Quit


THANKS FOR YOUR TIME!
solomon


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top