Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 859351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:40:12+00:00 2026-05-15T08:40:12+00:00

I am really frustrated by the snippet below: Dim objFSO, varSrc, varDest, varExt Set

  • 0

I am really frustrated by the snippet below:

Dim objFSO, varSrc, varDest, varExt

Set objFSO = CreateObject("Scripting.FileSystemObject")

varSrc = WScript.Arguments(0)
varDest = WScript.Arguments(1)
varExt = WScript.Arguments(2)

If objFSO.FolderExists(varSrc) Then
    WScript.Echo varSrc
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
        ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
            & "Targetinstance ISA 'CIM_DirectoryContainsFile' AND " _
                & "TargetInstance.GroupComponent= " _
                    & "'Win32_Directory.Name=""c:\\\\kk ""'")
    Do
        Set objLatestEvent = colMonitoredEvents.NextEvent
        WScript.Echo objLatestEvent.TargetInstance.PartComponent
    Loop
Else
    WScript.Echo "Bazinga"
End If

I tried to replace c:\\kk with varSrc however it seems impossible for WSH to recognize it in WMI query – not to mention it was within a single quote!

I have tried chr(34) and it didn’t work. Please help if possible. Much appreciated!

UPDATE:

Thank you so much for the answer and apologies for ambiguities.

varSrc is supposed to be “C:\\\\kk“. and the WMI query couldn’t recognize it. Let me explain by example:

The query should be parsed in such:

SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE Targetinstance ISA 'CIM_DirectoryContainsFile' AND TargetInstance.GroupComponent= 'Win32_Directory.Name= ""c:\\\\KK""'

I have tested the query above and it works! However what I need is to replace c:\\\\kk with an argument taken from user input, which in this case, is varSrc. The problem I have encountered is either the syntax is correct however WMI Query would be taking varSrc literally as the ‘Directory.Name‘; Or the other way – the syntax error or unparsable query.

If the query is:

("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
            & "Targetinstance ISA 'CIM_DirectoryContainsFile' AND " _
                & "TargetInstance.GroupComponent= " _
                    & "'Win32_Directory.Name=""varSrc""'")

The script will run without any error however it’s not doing its job monitoring the newly created files. Because it parse the ‘Directory.Name’ as literal ‘varSrc’ instead of user-input argument.

If the query is:

Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
    ("SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE " _
        & "Targetinstance ISA 'CIM_DirectoryContainsFile' AND " _
            & "TargetInstance.GroupComponent= " _
                & "'Win32_Directory.Name="""""&varSrc&"""""'")

It will generate an error:

vmove.vbs(15, 2) SWbemServicesEx: Invalid query
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:40:12+00:00Added an answer on May 15, 2026 at 8:40 am

    Most probably, varSrc contains the folder path with single backslashes, while your WMI query requires four backslashes as the path separator. Try doing a replace of \ with \\\\ in varSrc before inserting it into the query, like this:

    varSrc = Replace(varSrc, "\", "\\")
    Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
        ("SELECT * FROM __InstanceOperationEvent WITHIN 10 WHERE " _
            & "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
                & "TargetInstance.GroupComponent= " _
                    & "'Win32_Directory.Name=""" & varSrc & """'")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting increasingly frustrated with Flex's Dictionary (which is really just an array with
I'm really frustrated in this case. While developing with Adobe Flex, I'm working on
I'm really frustrated with this one. A few weeks ago I got it working
hey guys im really frustrated im looking for a way to retrieve back my
I am using jquery and am really frustrated at how I write my code.
I know I've had this problem before so I'm really frustrated. I've got the
hi I'm really frustrated, First I have no idea how to code the very
I'm really frustrated with this one. I'm trying to extend a C# created interface
I'm working on a parser and I'm really frustrated. In the language, we can
I've never had close experiences with Java IO API before and I'm really frustrated

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.