私は自分のアプリケーションに助けが必要なので、更新ボタンを押すといくつかの機能を実行するPsExecファイルを実行するアプリケーションを作成した。私のマシンでローカルでうまくいくという問題が起こりますが、私のアプリケーションは多くのユーザーに共有されます。 PsExecファイルをすべてのユーザーにコンピュータにインストールしたくない場合は、自分のプログラムを自分のコンピュータにインストールして問題なくプログラムを実行するだけです。C#Windowsアプリケーションのフルパスを知らずにPsExecを実行する。
私のコードはすべてのアプリケーションに対応しています。プログラム全体がPathを知らずにPsExecを呼び出すコードを追加するだけです。今はPsExecファイルをDebugフォルダにインストールしました。私のプロジェクトにあります。
ので、代わりに私のディレクトリにある全PsExecはパスを使用して、私はこの
string leMars21StArguments = @"/C C:\PowerShellRemotly\PsExec.exe " +
@"-i \\VML-2012-QBOOK2 -u mydomain\" + userInfo.Username + " -p " +
userInfo.Password + " -d C:\\batch\\myfile.bat";
を使用したくない
私が何かをしたいと思います私のプロジェクトのいずれかを使用するようになりますこのようなプロジェクトのデバッグフォルダーが、動作しません。これを行う別のものはありますか?
string leMars21StArguments = @"/C Debug\PsExec.exe " +
@"-i \\VML-2012-QBOOK2 -u mydomain\" + userInfo.Username + " -p " +
userInfo.Password + " -d C:\\batch\\myfile.bat";
ここでは完全なコードは次のとおりです。
Process p = new Process();
//assigned from the form txtboxes to the UserInformation class
userInfo.Username = txt_Username.Text;
userInfo.Password = txt_Password.Text;
//string variabes for the cmd arguments
string leMars21StArguments = @"/C C:\PowerShellRemotly\PsExec.exe -i " +
@"\\VML-2012-QBOOK2 -u mydomain\" + userInfo.Username + " -p " +
userInfo.Password + " -d C:\\batch\\myfile.bat";
if (userInfo.Username == string.Empty)
{
MessageBox.Show("Username cannot be null, please try again");
}
if (userInfo.Password == string.Empty)
{
MessageBox.Show("Password cannot be null, please try again");
}
if (cmb_DatabaseSelection.SelectedItem == "location")
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.Arguments = leMars21StArguments;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.Start();
string output = p.StandardOutput.ReadToEnd();
string errOutput = p.StandardError.ReadToEnd();
p.Close();
MessageBox.Show(errOutput);
}
つまり、あなたのプログラムでPSEXEC.EXEを含めるするつもりはないですか?彼らはそれを持っていない場合はどうなりますか? –
はいプログラムにPsExecプログラムが追加されました。使用するためにディレクトリパス全体を追加せずに使用したいと思っています。私は自分のプロジェクトにインストーラプログラムを作って、ファイルが常にプロジェクト内にあるようにします。 – AndresBryan29