Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 在ScriptBlock上使用凭据导致连接到应用程序的COM错误_Powershell_Com - Fatal编程技术网

Powershell 在ScriptBlock上使用凭据导致连接到应用程序的COM错误

Powershell 在ScriptBlock上使用凭据导致连接到应用程序的COM错误,powershell,com,Powershell,Com,好的,我有一个用于连接iTunes的概念验证脚本: $username = Read-Host "Please enter your userid for the local machine" $password = Read-Host "Please enter a password to be encrypted" -AsSecureString $cred = New-Object System.Management.Automation.PSCredential -ArgumentLis

好的,我有一个用于连接iTunes的概念验证脚本:

$username = Read-Host "Please enter your userid for the local machine"
$password = Read-Host "Please enter a password to be encrypted" -AsSecureString
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,$password)

Invoke-Command -ScriptBlock { 
    $iTunes = New-Object -ComObject iTunes.application
    $itunes | gm
} -ComputerName localhost -Credential $cred
但是,它返回以下错误:

Retrieving the COM class factory for component with CLSID {DC0C2640-1415-4644-875C-6F4D769839BA} failed due to the following error: 80080005.
    + CategoryInfo          : ResourceUnavailable: (:) [New-Object], COMException
    + FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Commands.NewObjectCommand
有趣的是,如果我从脚本块中删除
-ComputerName localhost-Credential$cred
,它可以正常工作:

   TypeName: System.__ComObject#{9dd6680b-3edc-40db-a771-e6fe4832e34a}

Name                               MemberType            Definition                                                
----                               ----------            ----------                                                
Authorize                          Method                void Authorize (int, Variant, string)                     
BackTrack                          Method                void BackTrack ()                                         
CheckVersion                       Method                bool CheckVersion (int, int)                              
ConvertFile                        Method                IITOperationStatus ConvertFile (string)                   
ConvertFile2                       Method                IITConvertOperationStatus ConvertFile2 (string)           
ConvertFiles                       Method                IITOperationStatus ConvertFiles (Variant)                 
ConvertFiles2                      Method                IITConvertOperationStatus ConvertFiles2 (Variant)         
ConvertTrack                       Method                IITOperationStatus ConvertTrack (Variant)                 
ConvertTrack2                      Method                IITConvertOperationStatus ConvertTrack2 (Variant)         
ConvertTracks                      Method                IITOperationStatus ConvertTracks (Variant)                
ConvertTracks2                     Method                IITConvertOperationStatus ConvertTracks2 (Variant)        
CreateEQPreset                     Method                IITEQPreset CreateEQPreset (string)                       
CreateFolder                       Method                IITPlaylist CreateFolder (string)                         
CreateFolderInSource               Method                IITPlaylist CreateFolderInSource (string, Variant)        
CreatePlaylist                     Method                IITPlaylist CreatePlaylist (string)                       
CreatePlaylistInSource             Method                IITPlaylist CreatePlaylistInSource (string, Variant)      
FastForward                        Method                void FastForward ()                                       
GetITObjectByID                    Method                IITObject GetITObjectByID (int, int, int, int)            
GetITObjectPersistentIDs           Method                void GetITObjectPersistentIDs (Variant, int, int)         
GetPlayerButtonsState              Method                void GetPlayerButtonsState (bool, ITPlayButtonState, bool)
GotoMusicStoreHomePage             Method                void GotoMusicStoreHomePage ()                            
NextTrack                          Method                void NextTrack ()                                         
OpenURL                            Method                void OpenURL (string)                                     
Pause                              Method                void Pause ()                                             
Play                               Method                void Play ()                                              
PlayerButtonClicked                Method                void PlayerButtonClicked (ITPlayerButton, int)            
PlayFile                           Method                void PlayFile (string)                                    
PlayPause                          Method                void PlayPause ()                                         
PreviousTrack                      Method                void PreviousTrack ()                                     
Quit                               Method                void Quit ()                                              
Resume                             Method                void Resume ()                                            
Rewind                             Method                void Rewind ()                                            
SetOptions                         Method                void SetOptions (int)                                     
Stop                               Method                void Stop ()                                              
SubscribeToPodcast                 Method                void SubscribeToPodcast (string)                          
UpdateIPod                         Method                void UpdateIPod ()                                        
UpdatePodcastFeeds                 Method                void UpdatePodcastFeeds ()                                
CanSetShuffle                      ParameterizedProperty bool CanSetShuffle (Variant) {get}                        
CanSetSongRepeat                   ParameterizedProperty bool CanSetSongRepeat (Variant) {get}                     
ITObjectPersistentIDHigh           ParameterizedProperty int ITObjectPersistentIDHigh (Variant) {get}              
ITObjectPersistentIDLow            ParameterizedProperty int ITObjectPersistentIDLow (Variant) {get}               
AppCommandMessageProcessingEnabled Property              bool AppCommandMessageProcessingEnabled () {get} {set}    
BrowserWindow                      Property              IITBrowserWindow BrowserWindow () {get}                   
ConvertOperationStatus             Property              IITConvertOperationStatus ConvertOperationStatus () {get} 
CurrentEncoder                     Property              IITEncoder CurrentEncoder () {get} {set}                  
CurrentEQPreset                    Property              IITEQPreset CurrentEQPreset () {get} {set}                
CurrentPlaylist                    Property              IITPlaylist CurrentPlaylist () {get}                      
CurrentStreamTitle                 Property              string CurrentStreamTitle () {get}                        
CurrentStreamURL                   Property              string CurrentStreamURL () {get}                          
CurrentTrack                       Property              IITTrack CurrentTrack () {get}                            
CurrentVisual                      Property              IITVisual CurrentVisual () {get} {set}                    
Encoders                           Property              IITEncoderCollection Encoders () {get}                    
EQEnabled                          Property              bool EQEnabled () {get} {set}                             
EQPresets                          Property              IITEQPresetCollection EQPresets () {get}                  
EQWindow                           Property              IITWindow EQWindow () {get}                               
ForceToForegroundOnDialog          Property              bool ForceToForegroundOnDialog () {get} {set}             
FullScreenVisuals                  Property              bool FullScreenVisuals () {get} {set}                     
LibraryPlaylist                    Property              IITLibraryPlaylist LibraryPlaylist () {get}               
LibrarySource                      Property              IITSource LibrarySource () {get}                          
LibraryXMLPath                     Property              string LibraryXMLPath () {get}                            
Mute                               Property              bool Mute () {get} {set}                                  
PlayerPosition                     Property              int PlayerPosition () {get} {set}                         
PlayerState                        Property              ITPlayerState PlayerState () {get}                        
SelectedTracks                     Property              IITTrackCollection SelectedTracks () {get}                
SoundVolume                        Property              int SoundVolume () {get} {set}                            
SoundVolumeControlEnabled          Property              bool SoundVolumeControlEnabled () {get}                   
Sources                            Property              IITSourceCollection Sources () {get}                      
Version                            Property              string Version () {get}                                   
Visuals                            Property              IITVisualCollection Visuals () {get}                      
VisualsEnabled                     Property              bool VisualsEnabled () {get} {set}                        
VisualSize                         Property              ITVisualSize VisualSize () {get} {set}                    
Windows                            Property              IITWindowCollection Windows () {get}                      
有人知道为什么脚本块上的凭据会导致此问题吗


原因是我正在研究一种从本地系统服务调用时运行某些iTunes任务的方法,因此在某种程度上,我正在尝试将调用提升回登录用户。

您是从提升的(管理员)PowerShell控制台运行此任务吗?如果我从提升的PowerShell控制台尝试此操作并指定localhost和cred,我就能够启动COM对象(我尝试的就是Excel.Application)。顺便说一句,这是在加入域的系统还是家庭/工作组PC上?嗨@keith hill,它以我自己的身份运行,我是这台机器上的本地管理员,但我没有专门设置任何东西使powershell以管理员的身份运行。我在家里和工作电脑上都试过,一台是独立电脑,另一台是网络电脑,但两者的连接问题都是一样的。但是,这样运行时,替换iTunes for Excel,COM对象将连接。看起来它可能特定于iTunes?我将Powershell设置为以管理员身份运行,方法是:右键单击Powershell,选择快捷方式选项卡,单击高级按钮,选择以管理员身份运行。再次尝试调出iTunes COM对象,但出现相同错误。我想知道它是否真的在完成之前超时了?它似乎思考了很长一段时间,但如果您放弃凭证,它会相当快。