I am having a problem running a program from a text box with admin rights...

NEvara

New member
Joined
Feb 16, 2011
Messages
4
Programming Experience
Beginner
.. i have in my form a text box and 3 buttons one is for browsing the other is to execute what i browse and the other is to exit the program when there was a program set to run from my hard drive it was running smoothly with admin rights now that i have setup in order to run ffrom the text box value it will just run it will show the command line for a sec or two and it wont run the program that i have selected can someone help me??

Thanks

Here's the code that i have written and salvaged some from the internet.


VB.NET:
  Option Explicit On
  Public Class Form1
   
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim EMA
          Dim readtext As String
          readtext = TextBox1.Text
          EMA = CreateObject("WScript.Shell")
          'Replace the path with the program you wish to run c:\program files...
          EMA.Run("RunAs /noprofile /user:administrator ""readtext""")
   
          'Replace the string --> yourpassword~ with the
          'password used on your system. Include the tilde "~"
          EMA.Sendkeys("password~")
      End Sub
      Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
          Dim neo As OpenFileDialog = New OpenFileDialog()
          ' Name of the open dialog Box
          neo.Title = "Drive C"
          ' The Directory from where it starts searching the file
          neo.InitialDirectory = "c:\"
          ' The filter of files that you wish to show
          neo.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
          neo.FilterIndex = 2
          neo.RestoreDirectory = True
          If neo.ShowDialog() = DialogResult.OK Then
              TextBox1.Text = neo.FileName
          End If
      End Sub
   
      Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
          End
      End Sub
  End Class
 
Last edited by a moderator:
well that helped and it didnt because i am quite new in vb what i am trying to do is run a program that i browse as administrator and what you have given me i am not sure how to input in it the text box value that i get from the pc that i will be in, in order to run it as administrator.

What i mean is this i have created a module in order to house a public variable
and i am not sure how to at this stage myProcess.StartInfo.FileName = readtext from ehat you've given me Process Class (System.Diagnostics)
i can input the in the readtext the variable the textbox1 and how to use the my MyProcessSample
does that make any sense?
 
You have to set more StartInfo properties than FileName. In your case at least Username and Password, and UseShellExecute to False as the help pages explain, probably also WorkingDirectory.
 
Hi i am not sure whats you mean by
You have to set more StartInfo properties than FileName. In your case at least Username and Password, and UseShellExecute to False as the help pages explain, probably also WorkingDirectory.
and i am not sure how to do half of what you are saying to me i read the stuff you linked to me and most of it didnt make any sense to me in the other program that i have supplied i have been able to get the browsing window the only problem is that when i press the execute button it will require me to write a password which i have supplied in my program and the other is that if i do supply it it wont run.

If you can help that will be appreciated

and this line
EMA.Run("RunAs /noprofile /user:administrator ""readtext""")

has been replaced with this one

EMA.Run("RunAs /noprofile /user:%computername%\administrator " & """ & text & """)
 
You did see the code example for the Process class help page? Also help pages for specific members (methods, properties, events) of a class may have additional code samples to get you started.

If the process you're starting doesn't have a GUI, ie is a console, then you can configure the StartInfo to redirect your input to it.
If it has a GUI then you may have to use the SendKeys class to send keystrokes to it. If that is so the Process class provides further help in the WaitForInputIdle method, in order to wait till the appropriate time to send input.
 
i gets whats you mean and i am trying to read what you saying to me to see if i can make something up but my problem is that i copy paste the examples that the msdn has and trying to modify them to suit my needs but everytime i try to run the program too see if i get a result i get the namespace statements can only occur at a file or namespace lvl and i am stonewalled because i am not sure what it means by that i tried searching namespace for vb didnt help much this is a procedure Namespace MyProcessSample that doesnt go inside the form and you call it?

Well thanks again for the help John.
 
Back
Top