by smadon at 2013-02-27 09:12:50
Hi all,by jonhtyler at 2013-02-27 09:22:20
I would like to run a program with admin right.
So I write theses lines, but I have a elevation right error.
How can I give the elevation right to run my program ???
$Username = "Administrator"
$Password = "MYPASSWORD"
$MyProg = "C:/MyFolder/MyProgr.exe"
$Credential = New-Object System.Management.Automation.PSCredential ("$UserName",(ConvertTo-SecureString -String $Password -AsPlainText -Force))
Start-Process -filePath $MyProg -Credential $Credential
Error Message
Start-Process : This command cannot be executed due to the error: The requested operation requires elevation.
Thanks for your help
Smadon
Please see the following article…this should help you…by smadon at 2013-02-28 04:05:17
http://social.technet.microsoft.com/For … 7bfccd39ea
Hi,by jonhtyler at 2013-02-28 04:15:31
Thanks jonhtyler for the link.
I added the code :
$Username = "Administrator"
$Password = "MYPASSWORD"
$MyProg = "C:/MyFolder/MyProgr.exe"
$Credential = New-Object System.Management.Automation.PSCredential ("$UserName",(ConvertTo-SecureString -String $Password -AsPlainText -Force))
Start-Process powershell -Credential $Credential -ArgumentList ‘-NoNewWindows -noprofile -command &{start-process $MyProg -wait -verb runas -RedirectStandardError C:\temp\temp2.txt}’
And I still have the error message about the Elevation,
Any Idea ???
Smadon
I don’t know right off. Let me play with it when I get set up a little later this morning, and I will see if I can reproduce the error with a little testing.by yesffan at 2013-02-28 07:53:42
You’re mixing up parameters for Powershell.exe and parameters for the Start-Process cmdlet. Try this code:by smadon at 2013-02-28 22:28:50$Username = "Administrator"
$Password = "MYPASSWORD"
$MyProg = "C:/MyFolder/MyProgr.exe"
$Credential = New-Object System.Management.Automation.PSCredential ("$UserName",(ConvertTo-SecureString -String $Password -AsPlainText -Force))
$argList = @(‘-noprofile’, "-command"&{ $MyProg }
" ")
Start-Process powershell -Credential $Credential -ArgumentList $argList -Wait -RedirectStandardError C:\temp\temp2.txt}’
$argList contains the parameters for Powershell (the process you’re starting)
Fernando
Hi all,by happysysadm at 2013-03-01 01:26:24
Thanks Fernando for your helpm it works
But I have one last problem with my variable
$MyProg is normaly in C:\Program Files (x86)\MyFolder\MyProg.exe
$MyProg = "${Env:ProgramFiles(x86)}" + "\MyFolder\MyProgr.exe"
When I run the script, I have this error Message
[quote]
The term ‘C:\Program’ is not recognized as the name of a cmdlet, function, scri
pt file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At line:1 char:14
+ &{ C:\Program <<<< Files (x86)\MyFolder\MyProg.exe }
+ CategoryInfo : ObjectNotFound: (C:\Program:String) , CommandN
otFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
[/quote]
What should i do to resolve the space problem ???
Thanks for your help
Hi there,by AlexBrassington at 2013-03-01 02:16:22
Have you tried testing path validity?
[code2=powershell]test-path $MyProg[/code2]
Also, even if it does not solve your problem, try to use join-path instead of string concatenation.
Carlo
At a guess you might passing the program files string without the quotation marks that tell powershell that it’s a single string. You might want to manually format the argument value.by yesffan at 2013-03-01 07:10:04
Try this:by smadon at 2013-03-01 08:38:31$Username = "Administrator"
$Password = "MYPASSWORD"
$MyProg = "C:/MyFolder/MyProgr.exe"
$Credential = New-Object System.Management.Automation.PSCredential ("$UserName",(ConvertTo-SecureString -String $Password -AsPlainText -Force))
$argList = @(‘-noprofile’, "-command"&{ & '$MyProg' }
" ")
Start-Process powershell -Credential $Credential -ArgumentList $argList -Wait -RedirectStandardError ‘C:\temp\temp2.txt’
That way, Powershell will interpret what’s in single quotes as an OS command.
Fernando.
PERFECT
Thank you guys for quick reply and your help