Question Créer raccourci sur le bureau (Résolu)

Plus d'informations
il y a 18 ans 1 mois #2154 par bill_
Bonjour,

Je cherche comment créer un raccourci sur le bureau d'un dossier partager en réseau

[code:1]$strNomPartage = \"test\"
net share gpmc=C:\test /users:25 /remark:\"Dossier de partage\"
#net share tempshare /delete
$strComputer = \".\"
$strShtCut = \"\test.lnk\"
$Shortcut = New-Object -ComObject WScript.Shell
$DesktopPath = $Shortcut.SpecialFolders(\"Desktop\"«»)
$ShtCut = $Shortcut.CreateShortcut($DesktopPath + $strShtCut)
$ShtCut.TargetPath = \"\\\" + $strComputer + $strNomPartage
$ShtCut.Save

Write-Host \"Success !!!\"[/code:1]

Seulement il m'indique une erreur au niveau de :

[code:1]$DesktopPath = $Shortcut.SpecialFolders(\"Desktop\"«»)[/code:1]

Le message d'erreur :
[code:1]
L'appel de la méthode a échoué parce que [System.__ComObject#{41904400-be18-11d3-a28b-00104bd35090}] ne contient pas de
méthode nommée « SpecialFolders ».
Au niveau de C:\Users\Public\Scripts-PowerShell\essai.ps1 : 8 Caractère : 40
+ $DesktopPath = $Shortcut.SpecialFolders( <<<< \"Desktop\"«»)[/code:1]

Voilà, merci encore du coup demain :)

Pourtant quand je tape :

[code:1]New-Object -ComObject WScript.Shell | Get-Member[/code:1]

[code:1]Name MemberType Definition
----

AppActivate Method bool AppActivate (Variant, Variant)
CreateShortcut Method IDispatch CreateShortcut (string)
Exec Method IWshExec Exec (string)
ExpandEnvironmentStrings Method string ExpandEnvironmentStrings (string)
LogEvent Method bool LogEvent (Variant, string, string)
Popup Method int Popup (string, Variant, Variant, Variant)
RegDelete Method void RegDelete (string)
RegRead Method Variant RegRead (string)
RegWrite Method void RegWrite (string, Variant, Variant)
Run Method int Run (string, Variant, Variant)
SendKeys Method void SendKeys (string, Variant)
Environment ParameterizedProperty IWshEnvironment Environment (Variant) {get}
CurrentDirectory Property string CurrentDirectory () {get} {set}
SpecialFolders Property IWshCollection SpecialFolders () {get}[/code:1]

La dernière ligne contient pourtant SpecialFolders, mais c'est une propriété et non une méthode, comment faire pour utiliser cette propriété ?

Message édité par: spz, à: 10/04/08 15:16<br><br>Message édité par: spz, à: 10/04/08 16:51

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 1 mois #2161 par xyz
Réponse de xyz sur le sujet Re:Créer raccourci sur le bureau
Salut,
spz écrit:

La dernière ligne contient pourtant SpecialFolders, mais c'est une propriété et non une méthode, comment faire pour utiliser cette propriété ?

Oui mais c'est une propriété de type collection et sous PowerShell elles ne peuvent être adressées directement, il faut passer par la propriété Item ajouté par PowerShell :
[code:1]$Shell.SpecialFolders.Item(\&quot;Desktop\&quot;«»)[/code:1]

J'en profite pour placer un lien sur une doc des objets du shell
The Windows Script Host Object Diagram <br><br>Message édité par: Laurent Dardenne, à: 7/11/08 14:36

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 18 ans 1 mois #2162 par bill_
Réponse de bill_ sur le sujet Re:Créer raccourci sur le bureau
D'accord je ne savais pas :P

Plus aucune erreur maintenant, mais je ne vois pas de raccourci sur le bureau, j'ai du faire une erreur quelque part :S

Edit : C'est bon j'ai trouvé, en fait c'était ça pour sauvegarder :

[code:1]$ShtCut.Save()[/code:1]

Il manquait la double parenthèse :)

Merci pour ton aide BatchMan ;)<br><br>Message édité par: spz, à: 10/04/08 16:51

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.036 secondes
Propulsé par Kunena