OVH Cloud OVH Cloud

[VBSCRIPT] Script pour connecter une imprimante lors de la connexi

14 réponses
Avatar
David
Bonjour le forum,

Pourriez-vous me dire où je pourrais trouver un script en vbscript qui me
permettrait de se connecter à l'imprimante réseau.

Tous les PC du domaine commence par SalleInfoPC ça va de SalleInfoPC04 à
SalleInfoPC18

Je suis sous Windows Server 2003 pour le serveur et sous Windows XP Pro pour
les clients.

Merci d'avance pour votre aide.

David

4 réponses

1 2
Avatar
David
Bonjour Gilles,

En plein dans le mille !

Merci beaucoup pour ton aide !

Pourrais-tu me dire pourquoi il faut mettre les noms des ordi en MAJUSCULE ?

Merci encore pour ton aide.



"Gilles LAURENT" wrote:

"David" a écrit dans le message de
news:
| Bonjour Michel,
|
| Merci pour ta réponse.
|
| oui c'est uniquement pour se connecter.
|
| j'ai trouvé un script vbs qui me permet de le faire mais il dit à
| chaque fois que le nom de mon imprimante réseau est inccorect.
|
| Sais-tu comment je peux connaitre le nom à mettre dans le script ?
|
| J'ai fais un net share et je vois RICOHAfi (c'est le nom du partage),
| est-ce ce nom que je dois utiliser ?
|
| Voici mon script :
|
| Option Explicit
| Dim oNetwork, sPrintPath
| Set oNetwork = CreateObject("WScript.Network")
| Select Case oNetwork.ComputerName
| Case "SalleInfoPC02"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC03"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC04"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC05"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC06"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC07"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC08"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC09"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC10"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC11"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC12"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC13"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC14"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC15"
| sPrintPath = "pharmacieRICOH Aficio AP410N PS"
| Case "SalleInfoPC16"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC17"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC18"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC19"
| sPrintPath = "pharmacieRICOHAfi"
| End Select
| oNetwork.AddWindowsPrinterConnection sPrintPath
| oNetwork.SetDefaultPrinter sPrintPath
|
| J'espère que tu pourras encore m'aider car je suis réellement
| désespéré.
|
| Merci encore
| David
|
|
|| Bonjour !
||
|| Juste pour se connecter ? Simple : NET USE
|| Avec NET USE /? tu auras plus de renseignements.
||
|| Mais, AMHA, le besoin doit être plus large, car, sous XP, par défaut,
|| les reconnexions sont automatiques.
||
|| --
|| @-salutations
||
|| Michel Claveau

Bonjour,

Le message est du au fait que la clause "SELECT CASE" n'est jamais
vérifée donc la variable sPrintPath n'est jamais assignée. Pour corriger
le problème, il suffit de spécifier le nom de poste en MAJUSCULE.

Option Explicit
Dim oNetwork, sPrintPath
Set oNetwork = CreateObject("WScript.Network")
Select Case oNetwork.ComputerName
Case "SALLEINFOPC02"
sPrintPath = "pharmacieRICOHAfi"
Case "SALLEINFOPC03"
sPrintPath = "pharmacieRICOHAfi"
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath

--
Gilles LAURENT
Me contacter : http://cerbermail.com/?zoTY7ZkLcD





Avatar
David
Gilles,

J'aurais pu aussi mettre un else (donc si c'est un autre nom de PC que celui
dans le end select) et là il aurait aussi trouvé je pense.

Qu'en penses-tu ?

David

"Gilles LAURENT" wrote:

"David" a écrit dans le message de
news:
| Bonjour Michel,
|
| Merci pour ta réponse.
|
| oui c'est uniquement pour se connecter.
|
| j'ai trouvé un script vbs qui me permet de le faire mais il dit à
| chaque fois que le nom de mon imprimante réseau est inccorect.
|
| Sais-tu comment je peux connaitre le nom à mettre dans le script ?
|
| J'ai fais un net share et je vois RICOHAfi (c'est le nom du partage),
| est-ce ce nom que je dois utiliser ?
|
| Voici mon script :
|
| Option Explicit
| Dim oNetwork, sPrintPath
| Set oNetwork = CreateObject("WScript.Network")
| Select Case oNetwork.ComputerName
| Case "SalleInfoPC02"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC03"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC04"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC05"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC06"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC07"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC08"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC09"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC10"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC11"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC12"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC13"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC14"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC15"
| sPrintPath = "pharmacieRICOH Aficio AP410N PS"
| Case "SalleInfoPC16"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC17"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC18"
| sPrintPath = "pharmacieRICOHAfi"
| Case "SalleInfoPC19"
| sPrintPath = "pharmacieRICOHAfi"
| End Select
| oNetwork.AddWindowsPrinterConnection sPrintPath
| oNetwork.SetDefaultPrinter sPrintPath
|
| J'espère que tu pourras encore m'aider car je suis réellement
| désespéré.
|
| Merci encore
| David
|
|
|| Bonjour !
||
|| Juste pour se connecter ? Simple : NET USE
|| Avec NET USE /? tu auras plus de renseignements.
||
|| Mais, AMHA, le besoin doit être plus large, car, sous XP, par défaut,
|| les reconnexions sont automatiques.
||
|| --
|| @-salutations
||
|| Michel Claveau

Bonjour,

Le message est du au fait que la clause "SELECT CASE" n'est jamais
vérifée donc la variable sPrintPath n'est jamais assignée. Pour corriger
le problème, il suffit de spécifier le nom de poste en MAJUSCULE.

Option Explicit
Dim oNetwork, sPrintPath
Set oNetwork = CreateObject("WScript.Network")
Select Case oNetwork.ComputerName
Case "SALLEINFOPC02"
sPrintPath = "pharmacieRICOHAfi"
Case "SALLEINFOPC03"
sPrintPath = "pharmacieRICOHAfi"
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath

--
Gilles LAURENT
Me contacter : http://cerbermail.com/?zoTY7ZkLcD





Avatar
David
Benoit,

La solution est trouvée, il fallait que je mette les noms d'ordi en
majuscule...

Merci pour ta précieuse aide et bonne journée.
David

"Benoit" wrote:

si tu n'as pas lpt1: déclarée sur le poste :


"net use lpt1: pharmacieRICOHAfi"

c'est tout !


L'erreur est sur tous les postes.

Avec les informations que tu as ci-dessous (non du share...) pourrais-tu stp
m'écrire la commande net use ?

Merci d'avance.
David
"Benoit" wrote:

l'erreur apparaît sur tous les postes ? pas seulement le pc15 ?
as-tu la même erreur quand tu fais un "Net Use" ?


Bonjour Benoit,

Tu as dû répondre à mon message, merci, mais ta réponse n'apparaît pas.

David





Bonjour Michel,

Merci pour ta réponse.

oui c'est uniquement pour se connecter.

j'ai trouvé un script vbs qui me permet de le faire mais il dit à chaque
fois que le nom de mon imprimante réseau est inccorect.

Sais-tu comment je peux connaitre le nom à mettre dans le script ?

J'ai fais un net share et je vois RICOHAfi (c'est le nom du partage), est-ce
ce nom que je dois utiliser ?

Voici mon script :

Option Explicit
Dim oNetwork, sPrintPath
Set oNetwork = CreateObject("WScript.Network")
Select Case oNetwork.ComputerName
Case "SalleInfoPC02"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC03"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC04"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC05"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC06"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC07"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC08"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC09"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC10"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC11"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC12"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC13"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC14"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC15"
sPrintPath = "pharmacieRICOH Aficio AP410N PS"
Case "SalleInfoPC16"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC17"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC18"
sPrintPath = "pharmacieRICOHAfi"
Case "SalleInfoPC19"
sPrintPath = "pharmacieRICOHAfi"
End Select
oNetwork.AddWindowsPrinterConnection sPrintPath
oNetwork.SetDefaultPrinter sPrintPath

J'espère que tu pourras encore m'aider car je suis réellement désespéré.

Merci encore
David


Bonjour !

Juste pour se connecter ? Simple : NET USE
Avec NET USE /? tu auras plus de renseignements.

Mais, AMHA, le besoin doit être plus large, car, sous XP, par défaut,
les reconnexions sont automatiques.

--
@-salutations

Michel Claveau

















Avatar
Gilles LAURENT
"David" a écrit dans le message de
news:
| Gilles,
|
| J'aurais pu aussi mettre un else (donc si c'est un autre nom de PC
| que celui dans le end select) et là il aurait aussi trouvé je pense.
|
| Qu'en penses-tu ?

David,

Une solution consiste à définir la variable sPrintPath avec le nom d'une
imprimante par défaut. Comme cela, si aucun poste n'est vérifié dans la
clause SELECT, celui-ci se verra attribuer cette imprimante par défaut.

Option Explicit
Dim oNetwork, sPrintPath

' définition de l'imprimante par défaut pour les postes non inventoriés
dans la clause SELECT
sPrintPath = "pharmacieRICOHAfi"

Set oNetwork = CreateObject("WScript.Network")
...

| David
|
| "Gilles LAURENT" wrote:
|
|| "David" a écrit dans le message de
|| news:
||| Bonjour Michel,
|||
||| Merci pour ta réponse.
|||
||| oui c'est uniquement pour se connecter.
|||
||| j'ai trouvé un script vbs qui me permet de le faire mais il dit à
||| chaque fois que le nom de mon imprimante réseau est inccorect.
|||
||| Sais-tu comment je peux connaitre le nom à mettre dans le script ?
|||
||| J'ai fais un net share et je vois RICOHAfi (c'est le nom du
||| partage), est-ce ce nom que je dois utiliser ?
|||
||| Voici mon script :
|||
||| Option Explicit
||| Dim oNetwork, sPrintPath
||| Set oNetwork = CreateObject("WScript.Network")
||| Select Case oNetwork.ComputerName
||| Case "SalleInfoPC02"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC03"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC04"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC05"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC06"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC07"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC08"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC09"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC10"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC11"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC12"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC13"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC14"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC15"
||| sPrintPath = "pharmacieRICOH Aficio AP410N PS"
||| Case "SalleInfoPC16"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC17"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC18"
||| sPrintPath = "pharmacieRICOHAfi"
||| Case "SalleInfoPC19"
||| sPrintPath = "pharmacieRICOHAfi"
||| End Select
||| oNetwork.AddWindowsPrinterConnection sPrintPath
||| oNetwork.SetDefaultPrinter sPrintPath
|||
||| J'espère que tu pourras encore m'aider car je suis réellement
||| désespéré.
|||
||| Merci encore
||| David
|||
|||
|||| Bonjour !
||||
|||| Juste pour se connecter ? Simple : NET USE
|||| Avec NET USE /? tu auras plus de renseignements.
||||
|||| Mais, AMHA, le besoin doit être plus large, car, sous XP, par
|||| défaut, les reconnexions sont automatiques.
||||
|||| --
|||| @-salutations
||||
|||| Michel Claveau
||
|| Bonjour,
||
|| Le message est du au fait que la clause "SELECT CASE" n'est jamais
|| vérifée donc la variable sPrintPath n'est jamais assignée. Pour
|| corriger le problème, il suffit de spécifier le nom de poste en
|| MAJUSCULE.
||
|| Option Explicit
|| Dim oNetwork, sPrintPath
|| Set oNetwork = CreateObject("WScript.Network")
|| Select Case oNetwork.ComputerName
|| Case "SALLEINFOPC02"
|| sPrintPath = "pharmacieRICOHAfi"
|| Case "SALLEINFOPC03"
|| sPrintPath = "pharmacieRICOHAfi"
|| End Select
|| oNetwork.AddWindowsPrinterConnection sPrintPath
|| oNetwork.SetDefaultPrinter sPrintPath
||
|| --
|| Gilles LAURENT
|| Me contacter : http://cerbermail.com/?zoTY7ZkLcD
1 2