PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms..win.server.scripting > Problems with escaping ' with WMI query
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Problems with escaping ' with WMI query

Réponse
 
LinkBack Outils de la discussion
Vieux 11/09/2007, 17h31   #1 (permalink)
bryons@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Problems with escaping ' with WMI query

I am trying to fix some code that MS released to recursively list
files in folders (http://www.microsoft.com/technet/scriptcenter/
resources/qanda/feb05/hey0218.mspx) so that it handles ' and } when
they are in the paths. I have been successful with the } but the ' is
giving me fits! Here's the offending line:

Set colSubfolders2 = objWMIService.ExecQuery _
("Associators of {Win32_Directory.Name='" & strFolderName &
"'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent")

When the query is:
Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
photos\\john'} Where AssocClass = Win32_Subdirectory ResultRole =
PartComponent
Everything works fine.

When I try to escape the ' in mike's pix I get the error below
Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
photos\\mike\'s pix'} Where AssocClass = Win32_Subdirectory ResultRole
= PartComponent
C:\Temp\test2.vbs(46, 5) (null): 0x8004103A

Am I not escaping the ' correctly?

  Réponse avec citation
Vieux 12/09/2007, 07h59   #2 (permalink)
Sam Hobbs
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems with escaping ' with WMI query

I would change that code to something such as:

Query = "Associators of {Win32_Directory.Name='" & strFolderName & "'} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent"
MsgBox Query
Set colSubfolders = objWMIService.ExecQuery(Query)


So I could see what I actually get. I could see if the escaped characters
are processed as I assume they would be.

My guess is that you are confusing JavaScript with VBScript. I do not
remember if WMI uses the backslash as an escape character but VBScript does
not.


<bryons@gmail.com> wrote in message
news:1189528262.595513.271600@r29g2000hsg.googlegr oups.com...
>I am trying to fix some code that MS released to recursively list
> files in folders (http://www.microsoft.com/technet/scriptcenter/
> resources/qanda/feb05/hey0218.mspx) so that it handles ' and } when
> they are in the paths. I have been successful with the } but the ' is
> giving me fits! Here's the offending line:
>
> Set colSubfolders2 = objWMIService.ExecQuery _
> ("Associators of {Win32_Directory.Name='" & strFolderName &
> "'} " _
> & "Where AssocClass = Win32_Subdirectory " _
> & "ResultRole = PartComponent")
>
> When the query is:
> Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> photos\\john'} Where AssocClass = Win32_Subdirectory ResultRole =
> PartComponent
> Everything works fine.
>
> When I try to escape the ' in mike's pix I get the error below
> Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> photos\\mike\'s pix'} Where AssocClass = Win32_Subdirectory ResultRole
> = PartComponent
> C:\Temp\test2.vbs(46, 5) (null): 0x8004103A
>
> Am I not escaping the ' correctly?
>



  Réponse avec citation
Vieux 12/09/2007, 08h24   #3 (permalink)
David Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems with escaping ' with WMI query

Hello bryons@gmail.com,

I found someone else with the same problem:
http://www.scriptinganswers.com/foru...=1028&PID=6176

Rather than using the single-quote (') as a delimiter, you can use the double-quote
(") if you escape it. In VBS you escape a character by doubling it, so ""
.. For some reason, this seems to work better in this situation.

Using the following revision, I was able to get folders with ' or } in them,
but I had to escape the backslashes ( \\ )

strFolderName = "c:\\quote_test\\b{o't}h"

"Associators of {Win32_Directory.Name=""" & strFolderName & """} " _
& "Where AssocClass = Win32_Subdirectory " _
& "ResultRole = PartComponent"





> I am trying to fix some code that MS released to recursively list
> files in folders (http://www.microsoft.com/technet/scriptcenter/
> resources/qanda/feb05/hey0218.mspx) so that it handles ' and } when
> they are in the paths. I have been successful with the } but the ' is
> giving me fits! Here's the offending line:
>
> Set colSubfolders2 = objWMIService.ExecQuery _
> ("Associators of {Win32_Directory.Name='" & strFolderName &
> "'} " _
> & "Where AssocClass = Win32_Subdirectory " _
> & "ResultRole = PartComponent")
> When the query is:
> Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> photos\\john'} Where AssocClass = Win32_Subdirectory ResultRole =
> PartComponent
> Everything works fine.
> When I try to escape the ' in mike's pix I get the error below
> Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> photos\\mike\'s pix'} Where AssocClass = Win32_Subdirectory ResultRole
> = PartComponent
> C:\Temp\test2.vbs(46, 5) (null): 0x8004103A
> Am I not escaping the ' correctly?
>




  Réponse avec citation
Vieux 12/09/2007, 16h20   #4 (permalink)
bryons@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Problems with escaping ' with WMI query

On Sep 12, 2:24 am, David Brown <david.br...@infor.com> wrote:
> Hello bry...@gmail.com,
>
> I found someone else with the same problem:http://www.scriptinganswers.com/foru...=1028&PID=6176
>
> Rather than using the single-quote (') as a delimiter, you can use the double-quote
> (") if you escape it. In VBS you escape a character by doubling it, so ""
> . For some reason, this seems to work better in this situation.
>
> Using the following revision, I was able to get folders with ' or } in them,
> but I had to escape the backslashes ( \\ )
>
> strFolderName = "c:\\quote_test\\b{o't}h"
>
> "Associators of {Win32_Directory.Name=""" & strFolderName & """} " _
> & "Where AssocClass = Win32_Subdirectory " _
> & "ResultRole = PartComponent"
>
> > I am trying to fix some code that MS released to recursively list
> > files in folders (http://www.microsoft.com/technet/scriptcenter/
> > resources/qanda/feb05/hey0218.mspx) so that it handles ' and } when
> > they are in the paths. I have been successful with the } but the ' is
> > giving me fits! Here's the offending line:

>
> > Set colSubfolders2 = objWMIService.ExecQuery _
> > ("Associators of {Win32_Directory.Name='" & strFolderName &
> > "'} " _
> > & "Where AssocClass = Win32_Subdirectory " _
> > & "ResultRole = PartComponent")
> > When the query is:
> > Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> > photos\\john'} Where AssocClass = Win32_Subdirectory ResultRole =
> > PartComponent
> > Everything works fine.
> > When I try to escape the ' in mike's pix I get the error below
> > Associators of {Win32_Directory.Name='d:\\inetpub\\content\\india
> > photos\\mike\'s pix'} Where AssocClass = Win32_Subdirectory ResultRole
> > = PartComponent
> > C:\Temp\test2.vbs(46, 5) (null): 0x8004103A
> > Am I not escaping the ' correctly?


Thanks David, I was able to make a few modifications based on your
comments and get a working script!

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h55.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12916 seconds with 12 queries