468,505 Members | 1,760 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

Pass Variable to external VBS

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.

Dec 6 '07 #1
2 2743
On Dec 6, 3:42 pm, mrmwal...@yahoo.co.uk wrote:
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
Dec 7 '07 #2
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.
Dec 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Carramba | last post: by
8 posts views Thread by Ekim | last post: by
1 post views Thread by aperez | last post: by
10 posts views Thread by Robert Dailey | last post: by
12 posts views Thread by Bryan Parkoff | last post: by
112 posts views Thread by istillshine | last post: by
11 posts views Thread by whirlwindkevin | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.