Pass Variable to external VBS

M

mrmwalter

Hi,

I have a simple form. On it is a Text Box that asks for "Username to
be entered". It also has a Radio Button that asks if the user needs to
be added to the local admin account.

I have an external vbs that adds user to local admin account, but how
do I pass the vbs the "UserName" that is entered on the form, if also
admin radio button is selected?

To launch the vbs, on the form, I will be using:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim p As Process
p = Process.Start("C:\VB\Test\BasicUsername.vbs")
p.WaitForExit()
End Sub

The vbs I use (BasicUsername.vbs) to add username to local admin
account is:

strComputer = "project"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://offline/abc")
objGroup.Add(objUser.ADsPath)
msgbox "done."

where username is manually set to "abc".

So what I am looking for is a way to replace the "abc" with the
username that was added on the form. As the vbs is an external file -
is it possible?

Hope you can help!

Many thanks.
 
H

heintz.larry

Hi,

I have a simple form. On it is a Text Box that asks for "Username to
be entered". It also has a Radio Button that asks if the user needs to
be added to the local admin account.

I have an external vbs that adds user to local admin account, but how
do I pass the vbs the "UserName" that is entered on the form, if also
admin radio button is selected?

To launch the vbs, on the form, I will be using:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim p As Process
p = Process.Start("C:\VB\Test\BasicUsername.vbs")
p.WaitForExit()
End Sub

The vbs I use (BasicUsername.vbs) to add username to local admin
account is:

strComputer = "project"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://offline/abc")
objGroup.Add(objUser.ADsPath)
msgbox "done."

where username is manually set to "abc".

So what I am looking for is a way to replace the "abc" with the
username that was added on the form. As the vbs is an external file -
is it possible?

Hope you can help!

Many thanks.

Is there any reason why you are not doing this whole procedure either
all in vbnet or vbscript? You can accomplish this all in one fail
swope with either one.

Larry
http://www.windowsadminscripts.com
 
M

mrmwalter

Hi Larry,

Thanks for taking time to reply.

Good question, the only reason I was going to pass it to vbs is
because I have more knowledge of VBS. And as I need a GUI, I though
Visual Basic would be easiest to create the form.

If I could figure out the code to add user to local domain in Visual
Basic, I would keep it all in Visual Basic.

But if I insert the code:

strComputer = "project"
Set objGroup = GetObject("WinNT://" & strComputer & "/
Administrators")
Set objUser = GetObject("WinNT://offline/abc")
objGroup.Add(objUser.ADsPath)
msgbox "done."

into the form - it doesn't work.

Sorry - I am new to Visual Basic.

Someone else has mentioned the way to do it may be to add the user
name to the string in my VBA procedure, you will add the user name to
the string that
I use to start the process . That is:

command: p = Process.Start("C:\VB\Test\BasicUsername.vbs" & " " &
TextBox.Text)

2. In the script, I use the WshArguments object to retrieve the
parameters passed to the script.

Set objArgs = WScript.Arguments
Set objUser = GetObject("WinNT://offline/" & opbjArgs(0))


For some reason, I am still having issues with passing whatever is
typed in the text box to the vbs.
To make this as simple as possible, I have recreated from scratch. On
my Visual Basic form, I just have a text box and a button.
On the vbs, I just want a MessageBox to display the UserName that was
entered on the text box.
Here is the Visual Basic Form:
Public Class Form1

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles TextBox1.TextChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim p As Process

p = Process.Start("C:\VB\Test\PassVar.vbs" & " " & TextBox1.Text)

p.WaitForExit()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub
End Class

Here is the VBS (I've rem'd 2 lines out), where I just want it to
display the username that was entered:
Set objArgs = WScript.Arguments
'Set objUser = GetObject(objArgs(0))
'Set objUser = GetObject("WinNT://offline/" & objArgs(0))
MsgBox (objArgs)

Can you see where I'm going wrong? I get an error saying file doesn't
exist, but if I take the "" & " " & TextBox1.Text" away, it does
launch the VBS, which proves the vbs does exist.

I hope you can help me?!

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top