start-process

How to start a 32-bit process in C# without using shell execute on 64-bit machine?

邮差的信 提交于 2019-12-11 02:18:44
问题 I have an ASP .NET web application on a 64-bit machine that needs to run a legacy 32-bit reporting application. When I run the program with UseShellExecute = false , the program exits with exit code: -1073741502 I can't use Shell Execute because I have to run the process as a different user. Yet, when Shell Execute is true, the process will run fine (although I have to change the user that ASP .NET is executing under). How can I start this 32-bit program using C# without use shell execute?

How to run a process as non-admin from an elevated PowerShell console?

百般思念 提交于 2019-12-09 04:46:33
问题 Maybe there is a way to do it with Start-Process cmdlet that I cannot find? The other related Q/A's I found on StackOverflow such as this, this and this all give a solution to do this with a custom C# code. My question is specifically, is there any straightforward way to do this in PowerShell? i.e. you are in an elevated PS console and want to run a process as non-admin. 回答1: You can specify the TrustLevel with runas.exe , effectively running "restricted" runas /trustlevel:0x20000 "powershell

How to handle file paths with special characters?

有些话、适合烂在心里 提交于 2019-12-07 19:01:51
问题 I've got a PowerShell script that needs to be able to call another PS script from within the same directory with elevated credentials. Because the scripts need to be portable, the file path of the scripts isn't known ahead of time and needs to be able to handle spaces and special characters in the file path without failing. Since elevating a PS session will cause the current working directory to change to "C:\Windows\System32", I need to be able to pass the current directory to the script as

PowerShell Executing a function within a Script Block using Start-Process does weird things with double quotes

时间秒杀一切 提交于 2019-12-04 06:29:35
I have a PowerShell script that edits the registry, so it needs to run as admin. To do this, I start up a new PowerShell process from my running PowerShell script, and pass in part of the registry key path using a Script Block with a function in it. When I use double quotes within that function, PowerShell tries to interpret them as commands, rather than a string. If I use single quotes though, then everything works fine. I've created a little stripped down sample powershell script that reproduces the problem. Here's the snippet: $ScriptBlock = { function Test { $status = "This is a string"

Process.Start filename using %temp%

百般思念 提交于 2019-12-04 04:11:26
问题 For some odd reaseon this code fails: p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; and this code succes: p.StartInfo.FileName = @"C:\Users\USERNAME\AppData\Local\Temp\SSCERuntime_x86-ENU.msi"; Is there any reason I am missing? Note I just copied the path, I don't think the rest of the code is needed but I'll put it anyway: Process p = new Process(); p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; p.StartInfo.Arguments = "/passive"; p.Start(); 回答1: The Process class does

Process.Start filename using %temp%

为君一笑 提交于 2019-12-01 23:28:36
For some odd reaseon this code fails: p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; and this code succes: p.StartInfo.FileName = @"C:\Users\USERNAME\AppData\Local\Temp\SSCERuntime_x86-ENU.msi"; Is there any reason I am missing? Note I just copied the path, I don't think the rest of the code is needed but I'll put it anyway: Process p = new Process(); p.StartInfo.FileName = @"%temp%\SSCERuntime_x86-ENU.msi"; p.StartInfo.Arguments = "/passive"; p.Start(); The Process class does not expand strings with environment variables (i.e. %temp% ). If you want to use environment variables to

Start-Process -wait doesn't work when script is launched from command prompt opened with runas or as a scheduled task

最后都变了- 提交于 2019-12-01 03:25:21
I've got a script that's I want to run as a scheduled task, but it's not doing the thing it's supposed to. I'm trying to call an executable with Start-Process and the -Wait switch before continuing. Line is Start-Process -FilePath "C:\Pfx Engagement\Admin\Utilities\Backup Restore\BackupRestoreUtil.exe" -ArgumentList "/f "$backup_directory "" -Wait If I call it from a command prompt, ie: powershell .\script.ps1 it works. It runs the command and waits for it to finish before moving on. There's more to the script that has to be run after that command is finished. The problem is that when it's a

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment

人走茶凉 提交于 2019-11-30 19:00:31
I'm running into a strange behavior with a powershell Start-Process call. Here is the call: $process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -Credential $defaultCredential ` -Wait ` -WorkingDirectory "C:\somepath" ` -LoadUserProfile if ($process.ExitCode -ne 0) { #do something } This call always return with the exit code - 1073741502 . After a quick search, this exit code seems related to a generic error when the program could not load its required dll (aka. STATUS_DLL_INIT_FAILED ). When I run it without -Credential $credential the program runs correctly. In order to

Powershell Opening File Path with Spaces

懵懂的女人 提交于 2019-11-30 13:47:47
Im my PS script I want to be able to run another script in another PS instance by doing the following: $filepath = Resolve-Path "destruct.ps1" start-process powershell.exe "$filepath" destruct.ps1 is in the same folder as this script However when running this script in a location which includes spaces ("C:\My Scripts\") i will get the following error: The term 'C:\My' is not recognized as a cmdlet, function, operable program, or script file. Verify the term and try again. I know by using a '&' with the Invoke-Expression method solves this problem, how can i do the same but by using the start

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment

陌路散爱 提交于 2019-11-30 03:24:10
问题 I'm running into a strange behavior with a powershell Start-Process call. Here is the call: $process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -Credential $defaultCredential ` -Wait ` -WorkingDirectory "C:\somepath" ` -LoadUserProfile if ($process.ExitCode -ne 0) { #do something } This call always return with the exit code - 1073741502 . After a quick search, this exit code seems related to a generic error when the program could not load its required dll (aka. STATUS_DLL_INIT