Pass Variable to external VBS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mrmwalter@yahoo.co.uk

    #1

    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(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim p As Process
    p = Process.Start(" C:\VB\Test\Basi cUsername.vbs")
    p.WaitForExit()
    End Sub

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

    strComputer = "project"
    Set objGroup = GetObject("WinN T://" & strComputer & "/Administrators" )
    Set objUser = GetObject("WinN T://offline/abc")
    objGroup.Add(ob jUser.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.

  • heintz.larry@gmail.com

    #2
    Re: Pass Variable to external VBS

    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(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim p As Process
    p = Process.Start(" C:\VB\Test\Basi cUsername.vbs")
    p.WaitForExit()
    End Sub
    >
    The vbs I use (BasicUsername. vbs) to add username to local admin
    account is:
    >
    strComputer = "project"
    Set objGroup = GetObject("WinN T://" & strComputer & "/Administrators" )
    Set objUser = GetObject("WinN T://offline/abc")
    objGroup.Add(ob jUser.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

    Comment

    • mrmwalter@yahoo.co.uk

      #3
      Re: Pass Variable to external VBS

      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("WinN T://" & strComputer & "/
      Administrators" )
      Set objUser = GetObject("WinN T://offline/abc")
      objGroup.Add(ob jUser.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\Basi cUsername.vbs" & " " &
      TextBox.Text)

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

      Set objArgs = WScript.Argumen ts
      Set objUser = GetObject("WinN T://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_TextCh anged(ByVal sender As System.Object, ByVal
      e As System.EventArg s) Handles TextBox1.TextCh anged

      End Sub

      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click

      Dim p As Process

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

      p.WaitForExit()

      End Sub

      Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
      System.EventArg s) 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.Argumen ts
      'Set objUser = GetObject(objAr gs(0))
      'Set objUser = GetObject("WinN T://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.

      Comment

      Working...