473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2915
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Carramba | last post by:
hi! I have simple form like <form method="POST" action="create_db.php"> db name: <input type="text" name="db" size="20"> <br> table name: <input type="text" name="table" size="20"> <br>...
5
by: Rigga | last post by:
Hi I would like to pass a variable to an external program i.e. os.system('cd $variable') However this doesnt work, I cant figure it out, any ideas? Cheers
8
by: Ekim | last post by:
my question is as follows: I've got a DLL in which I have a method GetBuffer (this one is extern, exported, is called from outside this program) which shall pass a char-buffer to the...
2
by: Lu | last post by:
Hello, I am wondering how to protect a global variable in a header file from external access. So I googled and found: "The keyword 'static' has two different uses, depending on whether it is...
1
by: aperez | last post by:
Hi, I need to pass a session variable from an ASP.NET v1.1 page to a v2.0 page, but haven't been able to do it. The reason is because I need to embed the 1.1 page in my intranet portal tool so I...
10
by: Robert Dailey | last post by:
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
11
by: whirlwindkevin | last post by:
I saw a program source code in which a variable is defined in a header file and that header file is included in 2 different C files.When i compile and link the files no error is being thrown.How is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.