Link to home
Start Free TrialLog in
Avatar of LordSM
LordSM

asked on

WScript object not found on runing command to add group name

Hi

I am trying to write a script that will automatically add group names to my local group. There are couple of commands which I do manually but I want to automate. I tried to do it, but some how it does not work and gives me "WScript" not found.Please suggest if I am going wrong somewhere:

<head>
<title>Website Creator</title>
<HTA:APPLICATION
     APPLICATIONNAME="Website Creator"
     SCROLL="no"
     SINGLEINSTANCE="yes"
   
     MaximizeButton ="yes"
     MinimizeButton = "yes"
     Border="thick"
>
</head>

<script language="VBScript">
   
    Sub TestSub
    dim GroupNameValue
 
    Set WshShell = WScript.CreateObject("WScript.Shell")
    GroupNameValue = InputForm.GroupName.Value
   
   
    WshShell.Run("net localgroup "+GroupNameValue+" /add")

    document.write("Group Name is " + GroupNameValue)
   
   
     
    End Sub

</script>

<body>
<form name="InputForm">
Group Name <INPUT TYPE="text" NAME="GroupName" SIZE=10>
<input type="button" value="Run Script" name="run_button"  onClick="TestSub"><p>

</body>

The command works fine and I am running it on Win 2000/2003
Thanks a ton in advance. Any alternate approach is appreciated
Avatar of tim_mcgue
tim_mcgue

first change this:
Set WshShell = WScript.CreateObject("WScript.Shell")

to this:
Set WshShell = CreateObject("WScript.Shell")

then report back here what happens next
Avatar of LordSM

ASKER

Thanks for the suggestion it worked. But I am confused on 1 thing in the following script
 the code for adding a group name works fine when I run - WshShell.Run("net localgroup "+GroupNameValue+" /add")
and even
WshShell.Run("net localgroup Turtle /add am\"+UserNameValue)                       -----(Code Line 1)
workes fine, given that Turtle is an existing group in there.

However, when I run

    WshShell.Run("net localgroup "+GroupNameValue+" /add")
    WshShell.Run("net localgroup "+GroupNameValue+" /add am\"+UserNameValue)

The group is being created but User Name is not being added. The commands work fine and it can be seen from previous -----(Code Line 1).

Please suggest, am I missing something. I feel, is it something like, when it runs the script it updates the group name, but on adding the user name its not able to see it in existing Groups


<head>
<title>Website Creator</title>
<HTA:APPLICATION
     APPLICATIONNAME="Website Creator"
     SCROLL="no"
     SINGLEINSTANCE="yes"
   
       MaximizeButton ="yes"
       MinimizeButton = "yes"
       Border="thick"
>
</head>

<script language="VBScript">
   
    Sub TestSub
    dim GroupNameValue
    dim UserNameValue
    GroupNameValue = InputForm.GroupName.Value
    UserNameValue = InputForm.UserName.Value
   
    Set WshShell = CreateObject("WScript.Shell")
   
   
    WshShell.Run("net localgroup "+GroupNameValue+" /add")
    WshShell.Run("net localgroup "+GroupNameValue+" /add am\"+UserNameValue)

    document.write("User Name is " + UserNameValue)
    document.write("Group Name is " + GroupNameValue)
   

       
    End Sub

</script>

<body>
<form name="InputForm">
Group Name <INPUT TYPE="text" NAME="GroupName" SIZE=10>
User Name <INPUT TYPE="text" NAME="UserName" SIZE=10>
<input type="button" value="Run Script" name="run_button"  onClick="TestSub"><p>
</body>
Avatar of LordSM

ASKER

I found the way

    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run("net localgroup "+GroupNameValue+" /add")
     
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run("net localgroup "+GroupNameValue+" /add am\"+UserNameValue)

It works fine this. Can you suggest me someway by which I can obtain the output of the commands? Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LordSM

ASKER

awesome it works fine
Great, so are you able to accept an answer to close the question?

Regards,

Rob.