Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Friday, August 24, 2012 12:59 PM
Hello folks
I need help
When i run
Start-Process notepad -Credential $credential
it's ok, this mean that credential used is OK
When I add -wait option , i receive this error message
Start-Process : Access is denied
At line:1 char:14
+ Start-Process <<<< notepad -Credential $credential -wait
+ CategoryInfo : NotSpecified: (:) [Start-Process], Win32Exception
+ FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.StartProcessCommand
Notepad is starting, but also the next command in the script is running without waiting !
Thanks in advance
Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.
All replies (4)
Monday, August 27, 2012 7:00 AM ✅Answered | 1 vote
May be:
Start-Process notepad -Credential $credential -Pass | Out-Null
or
$cred = Get-Credential
$psi = New-Object System.Diagnostics.ProcessStartInfo -Prop @{
RedirectStandardError = $True
RedirectStandardOutput = $True
UseShellExecute = $False
UserName = $cred.GetNetworkCredential().UserName
Domain = $cred.GetNetworkCredential().Domain
Password = $cred.Password
WorkingDirectory = "C:\Windows"
FileName = "notepad.exe"
}
[Diagnostics.Process]::Start($psi).WaitForExit()
Friday, August 24, 2012 1:19 PM
Try:(Start-Process notepad -Credential $credential -Pass).WaitForExit()
Friday, August 24, 2012 1:22 PM
Try Start-Job and Wait-Job
Сазонов Илья http://isazonov.wordpress.com/
Monday, August 27, 2012 6:35 AM
Hi
it;s working with .waitforexit() only if i don't use credentials
________________________________________________________________________________________________________________________________________________________________________PS E:\XXXXXXXXXX> (Start-Process notepad -pass).waitforexit()________________________________________________________________________________________________________________________________________________________________________PS E:\XXXXXXXXXX> (Start-Process notepad -Credential $credential -PassThru).waitforexit()Exception calling "WaitForExit" with "0" argument(s): "Access is denied"At line:1 char:70+ (Start-Process notepad -Credential $credential -PassThru).waitforexit <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Credentials are oK, breacause i can run the command without error
Start-Process notepad -Credential $credential -PassThru
Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.