开发者

Execute file from Powershell without getting "Do you want to run this file?" dialog

I'm looping through .exe files in a directory and extracting the .msp files.

Ideally it would happen silently.

This batch file command works perfectly.

for %%g in ("C:\test\"*.exe) do %%g /quiet /extract:"C:\test"

This powershell script almost gets it done.

$exeFiles = Get-ChildItem -path $directory -recurse -include *.exe
foreach($file in $exeFiles) 
{ 
    $appArgs = '/quiet /extract:"' + $directory + '"'
    Start-Process $exeFiles $appArgs -PassThru | Wait-Process
}

However, Windows 7 throws up the "Do you wa开发者_开发百科nt to run this file?" dialog.

How do I make the powershell truly silent?


Not sure if this is your problem but you're calling Start-Process on the $exeFiles variable rather than

for ($file in $exeFiles)
{
    start-process $file (...etc)
}

You're also passing the args as a string so i suspect they're not getting through to the exe. if you pass arguments to start-process they must be in the form of an array, one string per element in the array. Not only that, but powershell uses $args and it appears to be immutable, so you need a different variable name:

So your code should look more like this:

$directory = "C:\test"
$exeFiles = Get-ChildItem -path $directory -recurse -include *.exe
foreach($file in $exefiles) 
{ 
    $myArgs = '/quiet', ('/extract:"' + $directory + '"')
    Start-Process $file $myArgs -PassThru | Wait-Process
}


The problem you are having is trust relationship between the machine and the resource its getting the file from. if both machines belong to the same domain, you should not be getting this dialog. if they are not in a domain (ie intrernet or extranet) go to:Control Panel-> Internet Options -> Security -> Local Intranet -> Sites click "add", type in the resource you want to trust

file://servername.domainname

click OK, and try again. Personally I'm trying to do this via WMI, anyone know how?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜