Run External Program .net
Hi I want to make a VB program that able to run another exe with administrator credentials. The problem is I have a user log in to pc which has XP OS, and he log in using AD account as user, the program he want to run (from another company) require that he should have administrator privileges. I want to make a program that when he double click on it it will run that program c: company file.exe with administrator privileges. I search the internet and most of what I found is very lengthy code, i read the below if a fast way since this is new to me. All I want is my vb program run an external exe as administrator. I want some guidance about what should I use and which one of the above is the nearest of what I want. Thanks in advance.
Give More Feedback
Thank you Cor and kaymaf for your friendly help and support. Hi Samir, Here is the RunAs class for you to try running a process or application with Administrator privilege. Firstly, add reference to the RunAs.dll assembly and include the namespace VastAbyss. Imports VastAbyss Imports System.ComponentModel Dim username As String = 'Administrator' Dim domain As String = 'SomeDomain' Dim password As String = ' AdminPassword ' Dim commandline As String = 'C: yourApp.exe' Try Dim proc As System.Diagnostics.Process = RunAs.StartProcess(username, domain, password, commandline) Try proc.EnableRaisingEvents = True 'AddHandler proc.Exited, AddressOf Me.processExited Catch As System. Exception 'The process started but you don't have access to it. End Try Catch w32e As Win32Exception ' The process didn't start.
End Try Best regards, Martin Xie Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have any feedback on our support, please contact. Hi Martin, I want to thank you for posting this code with detail on how to use it, which emphasize to me that my code (after little adjustment) of what Kaymaf point to is correct, but there is strange error in my code as well your example. I understand Cor advice, so to be honest, I afraid to post my problem again in order for not accusing or doubting that I need a code to crack the windows security. I was doing research in silent and when I found an answer I will mark this thread as solved without posting the solution. Now I have 2 vb code with 2 different error's Your example give this error System.IO.FileNotFoundException: Could not load file or assembly 'RunAs, Version=1.0.1869.28854, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
How to set a button to run an external program from a windows form. Visual Studio Languages,.NET Framework > Visual Basic.
The system cannot find the file specified. This is the error of my code System.ComponentModel.Win32Exception: The parameter is incorrect Can I post a code about this subject? Thanks in advance.
Hi Kaymaf The software I want to run suppose to load access db and read from a com port a device that read the temperature and humidity. I could not run it using the code you provide, but I managed to run 'regedit, notepad and calc' the same thing happened with Martin code. The above error I post was when I run the UseRunAsControl.exe downloaded from the codeproject RunAsdemo.zip Yes, I add the reference, I managed to run 'regedit.exe','notepad.exe', 'calc.exe' except the software I want to run. It gives 'could not find file 'cs82.mdb' and this file exist in the same folder where my exe exist. Thank you for your help and follow up.
I managed to add runas.dll correctly, and also managed to run many exe except the exe I want to run, It seem it need special treatment. I finally managed to solve this, the code from Kaymaf plus little adjustment plus PUTTING the vb.exe in the same folder where my exe exist solve it, if I put it in different folder it will give 'the parameter is incorrect' I tried to put the project from codeproject in the same folder where my exe exist, and it fail. Thank you very much Kaymaf and Martin for your support and help.Did you provide the full path to the exe you are trying to spawn? Also this is important, I think, if you change directories to the one that contains the exe before spawning the exe, it will probably work fine. Many exes expect to know which directory is the current directory when they are spawned, and in most cases, it needs to be the one the reside in.On the other hand, a VB application can tell the current working directory quite readily, using: My.Computer.FileSystem.CurrentDirectory. Hi Jinzai There is only 2 places to provide the full path using both code of Kaymaf which require myprocessinfo.WorkingDirectory and i store the complete exe path, or Martin code which I split it to this Dim commandline As String = Me.TextBox2.Text + ' ' + Me.TextBox1.Text but you was right about the changing the current directory, i used ChDir with Kaymaf code, and the applications runs fine where the vb application was not in the same follder of my exe. Thank you for the Tip.
Store. But now, i am interrested why the other code from Martin (codeproject) is still asking for runas.dll when i try to run my exe, and when I try to run notepad.exe it works fine. I put my vb app RunAsAdministrator.exe plus the runas.dll in folder c: cs where my exe 'cs.exe' is exist.
Run External Program From Linux
I have a program that I am working on and I would like to have it embed and run an AntiVirus program, but I am not sure if this can be accomplished with the use of a button. Below is my code within VB2010 so far. Public Class Form1 Private Sub Form1Load( ByVal sender As System. Object, ByVal e As System. Well avast has slow repsonse with their Forums. If I put my code like this Sub VirusScanner Process.Start( 'aswRunDLL32.exe', ' AVAST Software Avast ') End Sub It still will not function.
You should go back to where you got that code from and ask for some additional details. I can't see that it could possibly work. Based on the information at the site referred to, I would have thought it would be something like this: Dim P As Process = New Process P.StartInfo.FileName = IO.Path.Combine(Environment.SpecialFolder.ProgramFiles, 'Avast Aswcmd.exe' ) P.StartInfo.Arguments = '/. /a /d B P /p4' P.Start. The code to run your application will be the same as you are already using: Process.Start(, ) The details will depend on the application you choose. Your best source for details about command line arguments available in the various ant-virus programs will be the forums dedicated to each application.
For instance: If the batch file has the correct commands and still does not work then that is a problem with the batch file or the machine configuration or user privileges, not your VB code. Well avast has slow repsonse with their Forums. If I put my code like this Sub VirusScanner Process.Start( 'aswRunDLL32.exe', ' AVAST Software Avast ') End Sub It still will not function. You should go back to where you got that code from and ask for some additional details. I can't see that it could possibly work. Based on the information at the site referred to, I would have thought it would be something like this: Dim P As Process = New Process P.StartInfo.FileName = IO.Path.Combine(Environment.SpecialFolder.ProgramFiles, 'Avast Aswcmd.exe' ) P.StartInfo.Arguments = '/. /a /d B P /p4' P.Start.