Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
288 views
in Technique[技术] by (71.8m points)

windows - powershell start-process as admin, am i misssing something

Im trying to create a script where a domain user would be able to run IIS service on windows as a local admin using stored credentials.

$adminerpath = 'c:programdataadminer'

Function StoreCreds(){
    $credential = Get-Credential
    $credential | Export-CliXml -Path  $adminerpathdata.dat
}

if (Test-Path $adminerpath){
    $credential = Import-CliXml -Path $adminerpathdata.dat
    Start-Process C:windowsSystem32inetsrvInetMgr.exe -Credential ($credentials)
}

else {
    New-Item -Path $adminerpath -ItemType "directory"
    attrib +h c:programdataadminer | Out-Null
    StoreCreds
    }

very simple, should see if the credential is stored and then run process with -credential. it works with anything else (like note.exe or pwoershell.exe), but when i try running this with InetMgr.exe im getting: start-process : This command cannot be run due to the error: The requested operation requires elevation. any help would be much appriciated

question from:https://stackoverflow.com/questions/65882218/powershell-start-process-as-admin-am-i-misssing-something

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...