简体   繁体   中英

Trouble with process.start()

I am making a program that works on a domain. Visual Basic (Visual Studio 2012)

At the start of the program it prompts the user for user name and password The reason being some of the things I am running requires to be run as Admin.

I am having trouble with the following.

Dim passwordRemote As SecureString = ConvertToSecureString(form1.PCMU.Text)
    Dim DomainRemote As String = "xxxxxxx"
    Dim UserNameRemote As String = "xxxxxx"
    Dim FileNameRemote As String = "cmrcviewer.exe" 
    Dim directoryRemote As String = "c:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\i386"

    process.StartInfo.WorkingDirectory = directoryRemote
    process.StartInfo.FileName = FileNameRemote 
    process.StartInfo.Domain = DomainRemote
    process.StartInfo.UserName = UserNameRemote
    process.StartInfo.Password = passwordRemote
    process.StartInfo.UseShellExecute = False

    process.Start()

The issue is I get is:

The system cannot find the file specified

I have put cmd.exe into that directory and that works correctly. "cmrcviewer.exe" which sits in the same directory does not work..

"cmrcviewer.exe" is part file related to sccm2012

Please help it would be greatly appreciated

WorkingDirectory isn't the path where the .exe is located, it's the path that will be used as the "current" directory for the application once it starts. By default, it's the same folder as the folder where the .exe is located.

For example, when you open a console window to your project folder and execute a command like msbuild , the working directory is your project folder while the executable's path is always somewhere in the .NET SDK.

Your code uses only a relative path name for the executable, which means that Windows will try to find it in your application's working directory. If it can't find it there, it will look for it in the user's path environment variable.

To get your code to work, you need write:

process.StartInfo.FileName = Path.Combine(directoryRemote,FileNameRemote)

or just pass the entire path as a single string to FileName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM