• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 590
  • Last Modified:

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
0
LordSM
Asked:
LordSM
  • 3
  • 2
1 Solution
 
tim_mcgueCommented:
first change this:
Set WshShell = WScript.CreateObject("WScript.Shell")

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

then report back here what happens next
0
 
LordSMAuthor Commented:
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>
0
 
LordSMAuthor Commented:
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RobSampsonCommented:
Hi LordSM,
Since you are using the Run command without hiding the window, you will benefit from using the Exec method instead, to get the output.

Try this:
    Set WshShell = CreateObject("WScript.Shell")
    Set objExec1 = WshShell.Exec("net localgroup "+GroupNameValue+" /add")
    Set objExec2 = WshShell.Exec("net localgroup "+GroupNameValue+" /add am\"+UserNameValue)
    strOutput1 = objExec1.StdOut.ReadAll
    strOutput2 = objExec2.StdOut.ReadAll
    MsgBox "Output of first command:" & vbCrLf & strOutput1 & vbCrLf & vbCrLf & "Output of second command:" & vbCrLf & strOutput2

Regards,

Rob.
0
 
LordSMAuthor Commented:
awesome it works fine
0
 
RobSampsonCommented:
Great, so are you able to accept an answer to close the question?

Regards,

Rob.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now