none
Why this script doesnt work? (it doesnt give error message) RRS feed

  • Question

  • on error resume next
    
    dim oShell, strComputer, intProcessID
    
    strComputer = InputBox("IP or Host Name:", "DELETER - serdaruzun@outlook.com")
    
    set oShell = WScript.CreateObject("Wscript.shell") & strComputer
    oShell.run "cmd.exe /C rd \\%PC%\Users\1*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\2*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\3*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\4*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\5*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\6*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\7*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\8*.* /s /q", null, null, intProcessID
    oShell.run "cmd.exe /C rd \\%PC%\Users\9*.* /s /q", null, null, intProcessID
    
    set oShell = nothing

    I want to run a cmd command inserted in a vbscript deleting some remote files. But it didnt work.

    Thank you in advance


    \_(ツ)_/ twitter.com/serdaruzun



    • Edited by serdaruzun Tuesday, June 10, 2014 12:06 PM adding
    Tuesday, June 10, 2014 11:53 AM

Answers

  • Posting long scripts in a forum is not really a good way to learn VBScript.

    It sounded more like you want for someone to rewrite a non-working script for you.

    If you want to learn VBScript, there are a lot of good resources. For example, the VBScript Primer section in the Windows 2000 Scripting Guide I think is pretty good.

    However, I would recommend PowerShell instead of VBScript. You can do a lot more with less code.

    It also depends on what problem you are trying to solve. If this question is really about deleting user profiles, there are already solutions (e.g., the aforementioned delprof2 program).


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 11, 2014 2:20 PM
    Moderator

All replies

  • Your script fails for several reasons:

    • The "rd" command does not accept wildcards. You should test it at the Console before inserting it into a script.
    • The line
      set oShell = WScript.CreateObject("Wscript.shell") & strComputer
      should read
      set oShell = WScript.CreateObject("Wscript.shell")
    • The environmental variable %PC% is not defined. Inserting the line
      wscript.echo "cmd.exe /C rd \\%PC%\Users\1*.* /s /q"
      would confirm it. Changing
      oShell.run "cmd.exe /C rd \\%PC%\Users\1*.* /s /q", null, null, intProcessID
      to
      oShell.run "cmd.exe /C rd \\" & strComputer & "\Users\1 /s /q", null, null, intProcessID
      might fix the problem.
    • Having the statement On error resume next in your code is a bad idea. I causes the script interpreter to ignore all errors. Get rid of it!
    Since you appear to be unfamiliar with VBScripts you would make things easier for yourself by putting the "rd" commands into a batch file.

    Tuesday, June 10, 2014 12:52 PM
  • Your script fails for several reasons:

    • The "rd" command does not accept wildcards. You should test it at the Console before inserting it into a script.
    • The environmental variable %PC% is not defined. Inserting the line
      wscript.echo "cmd.exe /C rd \\%PC%\Users\1*.* /s /q"
      would confirm it. Changing
      oShell.run "cmd.exe /C rd \\%PC%\Users\1*.* /s /q", null, null, intProcessID
      to
      oShell.run "cmd.exe /C rd \\" & strComputer & "\Users\1 /s /q", null, null, intProcessID
      might fix the problem.

    on error resume next
    
    dim oShell, strComputer, intProcessID
    
    strComputer = InputBox("IP or Host Name:", "DELETER - serdaruzun@outlook.com")
    
    set oShell = WScript.CreateObject("Wscript.shell") & strComputer
    oShell.run "cmd.exe /C rd \\"& strComputer & "\Users\1*.* /s /q", null, null, intProcessID
    
    set oShell = WScript.CreateObject("Wscript.shell") & strComputer
    oShell.run "cmd.exe /C rd \\"& strComputer & "\Users\2*.* /s /q", null, null, intProcessID
    
    set oShell = nothing

    According to you, It must be above?

    \_(ツ)_/ twitter.com/serdaruzun


    • Edited by serdaruzun Tuesday, June 10, 2014 1:04 PM error
    Tuesday, June 10, 2014 1:02 PM
  • I am suspecting you are posting a different message related to the same issues:

    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/69195934-167c-4dee-b075-01124a865817/

    Something to do with deleting user profiles?

    I am not sure you have a scripting question but rather a "how do I manage Windows user profiles" question.

    I would recommend studying about user profiles first. Start with this:

    http://www.google.com/search?&q=manage+windows+user+profiles


    -- Bill Stewart [Bill_Stewart]

    Tuesday, June 10, 2014 2:17 PM
    Moderator
  • According to you, It must be above?


    No, not really. I made several comments but it seems you chose to ignore most of them.
    Tuesday, June 10, 2014 3:36 PM
  • I am suspecting you are posting a different message related to the same issues:

    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/69195934-167c-4dee-b075-01124a865817/

    Something to do with deleting user profiles?

    I am not sure you have a scripting question but rather a "how do I manage Windows user profiles" question.

    I would recommend studying about user profiles first. Start with this:

    http://www.google.com/search?&q=manage+windows+user+profiles


    -- Bill Stewart [Bill_Stewart]

    You are in a bad intention. It can be related to deleting profiles but I try to learn vbscript. 

    \_(ツ)_/ twitter.com/serdaruzun

    Wednesday, June 11, 2014 6:34 AM
  • According to you, It must be above?


    No, not really. I made several comments but it seems you chose to ignore most of them.

    I may write wrongly but I have no detailed information about vbs. I think I do something wrong by asking.

    You dont have to answer my questions if you are disturbed :(

    I think I wont ask questions any more; because you always prefer scolding me instead of helping.

    Anyhow thank allofyou for your good scolding...


    \_(ツ)_/ twitter.com/serdaruzun

    Wednesday, June 11, 2014 6:43 AM
  • People help without a penny.

    Of course understanding and patience is needed.

    Imagine a world where all you have to ask is yourself?

    check out link below, you might get some ideas:

    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/f2cbfd46-b6cc-4595-a731-19021bf5c60d/deleting-files-and-subfolders-how-to?forum=ITCG

    Patience my friend,..  :) 


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.
    IT Stuff Quick Bytes

    Wednesday, June 11, 2014 6:52 AM
  • Posting long scripts in a forum is not really a good way to learn VBScript.

    It sounded more like you want for someone to rewrite a non-working script for you.

    If you want to learn VBScript, there are a lot of good resources. For example, the VBScript Primer section in the Windows 2000 Scripting Guide I think is pretty good.

    However, I would recommend PowerShell instead of VBScript. You can do a lot more with less code.

    It also depends on what problem you are trying to solve. If this question is really about deleting user profiles, there are already solutions (e.g., the aforementioned delprof2 program).


    -- Bill Stewart [Bill_Stewart]

    Wednesday, June 11, 2014 2:20 PM
    Moderator