标签: processstartinfo

Win32Exception:目录名无效

我正在尝试作为一个不同的用户运行一个进程,该用户在运行Vista并启用了UAC的2台不同计算机上具有管理员权限但在其中一个中我得到一个Win32Exception,其中显示"目录名称无效"

谁能告诉我我的代码有什么问题?

var myFile = "D:\\SomeFolder\\MyExecutable.exe";
var workingFolder = "D:\\SomeFolder";
var pInfo = new System.Diagnostics.ProcessStartInfo();
pInfo.FileName = myFile;
pInfo.WorkingDirectory = workingFolder;
pInfo.Arguments = myArgs;
pInfo.LoadUserProfile = true;
pInfo.UseShellExecute = false;
pInfo.UserName = {UserAccount};
pInfo.Password = {SecureStringPassword};
pInfo.Domain = ".";

System.Diagnostics.Process.Start(pInfo);
Run Code Online (Sandbox Code Playgroud)

UPDATE

执行上述代码的应用程序具有requireAdministrator执行级别.我甚至将工作文件夹设置为"Path.GetDirectoryName(myFile)""New System.IO.FileInfo(myFile).DirectoryName"

c# processstartinfo win32exception

13
推荐指数
2
解决办法
3万
查看次数

同步启动进程,并"输出"输出

我正在尝试从F#开始一个进程,等到它完成,但还要逐步读取它的输出.

这是正确/最好的方式吗?(在我的情况下,我正在尝试执行git命令,但这与问题相关)

let gitexecute (logger:string->unit) cmd = 
    let procStartInfo = new ProcessStartInfo(@"C:\Program Files\Git\bin\git.exe", cmd) 

    // Redirect to the Process.StandardOutput StreamReader.
    procStartInfo.RedirectStandardOutput <- true
    procStartInfo.UseShellExecute <- false;

    // Do not create the black window.
    procStartInfo.CreateNoWindow <- true;

    // Create a process, assign its ProcessStartInfo and start it
    let proc = new Process();
    proc.StartInfo <- procStartInfo;
    proc.Start() |> ignore

    // Get the output into a string
    while not proc.StandardOutput.EndOfStream do
        proc.StandardOutput.ReadLine() |> logger
Run Code Online (Sandbox Code Playgroud)

我不明白的是proc.Start()如何返回一个布尔值,也足够异步,让我逐步获得输出.

不幸的是,我目前没有足够大的存储库 - 或者足够慢的机器,以便能够分辨出事情的顺序......

UPDATE

我试过Brian的建议,它确实有效.

我的问题有点模糊.我的误解是,我假设的Process.Start()返回进程的成功作为一个整体,而不是仅仅的"开始",因此我看不出它如何能 …

.net f# processstartinfo synchronous

11
推荐指数
1
解决办法
2116
查看次数

Process.Start()启动的应用程序没有得到参数

使用C#,我试图使用Process.Start()将命令行参数传递给新进程:

string path = @"C:\Demo\Demo.exe";
string arguments = "one two three";
ProcessStartInfo startInfo = new ProcessStartInfo
   {
      FileName = path,
      Arguments = arguments
   };
var process = Process.Start(startInfo);
Run Code Online (Sandbox Code Playgroud)

我的C应用程序Demo.exe只是回显命令行参数:

int main( int argc, char *argv[] )
{
   int count=0;

   // Display each command-line argument.
    printf( "\nCommand-line arguments:\n" );
    for( count = 0; count < argc; count++ )
        printf( "  argv[%d]   %s\n", count, argv[count] );

    while(1);
}
Run Code Online (Sandbox Code Playgroud)

如果我从cmd.exe启动我的应用程序,我得到合理的输出:

Command-line arguments:
 argv[0]   Demo.exe
 argv[1]   one
 argv[2]   two
 argv[3]   three
Run Code Online (Sandbox Code Playgroud)

当我使用C#应用程序时,我唯一得到的是argv [0]中的path参数:

Command-line …
Run Code Online (Sandbox Code Playgroud)

c# processstartinfo process.start

11
推荐指数
2
解决办法
4800
查看次数

在没有UAC提示的情况下从.NET应用程序执行进程

我有一个场景,我需要从我的.NET应用程序启动一个EXE,但我无法解决弹出的UAC提示.即使在启动其他EXE之前,也会触发提示 - 可能是在通话时Process.Start.

我使用此代码启动应用程序:

            var info = new ProcessStartInfo(path, "params");
            info.Verb = "runas";
            try
            {
                Process.Start(info);
            }
            catch (System.ComponentModel.Win32Exception)
            {
                // Person denied UAC escallation
                return false;
            }
Run Code Online (Sandbox Code Playgroud)

两个EXE(我的应用程序和其他EXE)都在其清单中定义了:

    <requestedExecutionLevel level="asInvoker" uiAccess="false" />
Run Code Online (Sandbox Code Playgroud)

如何在不触发UAC提示的情况下执行其他EXE,并使其具有与调用应用程序相同的访问令牌(因此它可以更改app文件夹中的文件等)?

.net c# uac processstartinfo

8
推荐指数
1
解决办法
4895
查看次数

使用Asp.Net Web应用程序中的sysinternals PSExec执行脚本

我试图PSExec从我的Asp.Net Web应用程序执行连接到远程服务器.它"Access Denied Error -5"以某种方式提供没有凭据设置,并通过设置它给出的PSEXEC命令中的凭据 "2250 Network connection could not be found".我是服务器上的管理员,我已Windows authentication and Asp.Net Impersonation启用(IIS7.5).更有趣的是,当我尝试从一个console application或甚至只是使用command prompt它执行它只是工作正常.我试图做一个ping操作作为测试.

这是我的代码片段: -

            var startInfo = new ProcessStartInfo{
                CreateNoWindow = true,
                UseShellExecute = false,
                FileName = FilePath,
                Arguments = CommandArgs
            }

            Process vsCommandProcess = Process.Start(startInfo);

            vsCommandProcess.WaitForExit();
            var exitCode = vsCommandProcess.ExitCode;
            if (vsCommandProcess.ExitCode != 0)
            {
                ...rest of the code
Run Code Online (Sandbox Code Playgroud)

这里:-

FilePath --> C:\pstools\psexec.exe
Arguments --> \\servername -accepteula -u domain\userName -p …
Run Code Online (Sandbox Code Playgroud)

c# asp.net process processstartinfo psexec

8
推荐指数
1
解决办法
3090
查看次数

Process.Start权限问题

我正在尝试使用Process.Start从C#运行外部问题,但遇到了权限问题.当我正常打开命令提示符(而不是管理员)并运行我的命令时,它们工作正常,但是当我通过Process.Start打开命令提示符时,我在目录上收到写入错误.("我无法在文件test.log上写")
如果我通过Process.Start以管理员身份运行它可以正常工作,但我获得了权限弹出窗口.有没有人有任何想法可以帮我解决这个问题?谢谢!

这是我正在使用的代码:

Process proc = new Process();
proc.StartInfo.FileName = @"cmd.exe";
proc.StartInfo.Arguments = @"/k latex C:\Users\Shane\Documents\test.tex";
proc.Start();
proc.WaitForExit();
Run Code Online (Sandbox Code Playgroud)

.net c# latex processstartinfo

7
推荐指数
1
解决办法
1万
查看次数

与.NET程序中的ffmpeg交互?

我正在尝试使用ffmepg创建用于媒体文件转换的.NET包装器,这是我尝试过的:

static void Main(string[] args)
{
  if (File.Exists("sample.mp3")) File.Delete("sample.mp3");

  string result;

  using (Process p = new Process())
  {
    p.StartInfo.FileName = "ffmpeg";
    p.StartInfo.Arguments = "-i sample.wma sample.mp3";

    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;

    p.Start();

    //result is assigned with an empty string!
    result = p.StandardOutput.ReadToEnd();

    p.WaitForExit();
  }
}
Run Code Online (Sandbox Code Playgroud)

实际发生的是ffmpeg程序的内容打印到Console应用程序,但result变量是一个空字符串.我希望以交互方式控制转换进度,因此用户甚至不必知道我正在使用ffmpeg,但他仍然知道转换进度的详细信息以及应用程序所需的百分比等.

基本上我也很满意只有P/Invoke到转换函数的.NET包装器(我对整个外部库不感兴趣,除非我可以从中提取PI函数).

有ffmpeg和.NET经验的人吗?

更新 请查看我的进一步问题,如何将输入写入正在运行的ffmpeg进程.

.net interaction ffmpeg process processstartinfo

6
推荐指数
1
解决办法
5029
查看次数

PowerShell 中的 ProcessStartInfo 和 Process - 身份验证错误

我有使用 ProcessStartInfo 和 Process 来调用另一个脚本并返回该脚本输出的代码。

不幸的是,我遇到了错误,我不确定如何解决它们。

#script1.ps1

$abc = $args
$startInfo = $NULL
$process = $NULL
$standardOut = $NULL

<#Previously created password file in C:\Script\cred.txt, read-host -assecurestring | convertfrom-securestring | out-file C:\Script\cred.txt#>
$password = get-content C:\Script\cred.txt | convertto-securestring


$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = "powershell.exe"
$startInfo.Arguments = "C:\script\script2.ps1", $abc

$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $false
$startInfo.Username = "DOMAIN\Username"
$startInfo.Password = $password

$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()

# $standardOut …
Run Code Online (Sandbox Code Playgroud)

powershell process processstartinfo invoke

6
推荐指数
1
解决办法
2万
查看次数

获取与c#中的ProcessStartInfo一起使用的可用动词(文件关联)列表

我正在尝试使用ProcessStartInfo类打开和打印文件.(文件可以是任何东西,但我们假设它是一个PDF文件)

  ProcessStartInfo pi = new ProcessStartInfo(file);
  pi.Arguments = Path.GetFileName(file);
  pi.WorkingDirectory = Path.GetDirectoryName(file);
  pi.Verb = "OPEN";  
  Process.Start(pi);
Run Code Online (Sandbox Code Playgroud)

这适用于pi.Verb = "OPEN";.一些应用程序也使用动词"PRINT"注册自己,但只有一些应用程序注册.在我的情况下(Windows PDF Viewer)我尝试执行时遇到异常pi.Verb = "PRINT";

有没有办法在运行时查看C#中特定类型的所有动词?

多谢

c# processstartinfo file-association

6
推荐指数
2
解决办法
6202
查看次数

从 Azure WebJob 运行 Python 脚本

我正在尝试从 Azure webjob 运行 python 脚本。这是我按照此链接所做的

  1. 通过 url 访问 kudu 工具https://<webapp name>.scm.azurewebsites.netPython 364x86通过站点扩展选项卡安装
  2. 确认Python 364x86安装在以下路径:D:\home\python364x86
  3. 加入我的脚本trading.pyD:\home\python364x86
  4. run.bat用这行代码创建文件D:\home\python364x86\python.exe trading.py
  5. 包括run.battrading.py在webjob zip文件
  6. 已部署,但出现错误
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Initializing
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Run script 'run.bat' with script host - 'WindowsScriptHost'
[09/07/2019 07:02:00 > 0dd02c: SYS INFO] Status changed to Running
[09/07/2019 07:02:00 > 0dd02c: ERR ] The …
Run Code Online (Sandbox Code Playgroud)

c# python processstartinfo azure-webjobs

6
推荐指数
1
解决办法
2883
查看次数