VBScript and Scheduled Tasks

Discussion in 'Scripting' started by Steph, Jul 27, 2005.

  1. Steph

    Steph Guest

    Hi,

    I've created the script below, if I launch the script manully, no problem.
    If I create a scheduled tasks and set a domain admin account in "Run as" ,
    no problem. But if I set a local administrator in "Run as", the folder is
    not created and I don't have any error message.
    Thanks for your help.


    FolderName = date
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run ("cmd /c md c:\test\"& FolderName &""),1,TRUE
     
    Steph, Jul 27, 2005
    #1
    1. Advertisements

  2. Steph

    Marty List Guest

    On most systems, the Date() function will return a string with forward slashes
    like "7/27/2005". You can't use a forward slash in folder name, the file system
    won't allow it.

    Also, it looks like you're trying to get double quotes around the folder name,
    but you need to double the double quotes for that to work. For example, ""
    becomes " like this:
    objShell.Run ("cmd.exe /c md ""c:\test\" & FolderName & """"),1,TRUE

    If you fix the quotes around the name you might end up with a folder tree like
    this: "C:\Test\7\27\2005\".

    When you run this manually, what is the format of Date, and what does the folder
    in C:\Test look like?

    Also, consider using the FileSystemObject in the Script Runtime instead of
    shelling out to cmd.exe:
    http://msdn.microsoft.com/library/en-us/script56/html/jsmthCreateFolder.asp
     
    Marty List, Jul 27, 2005
    #2
    1. Advertisements

  3. Steph

    Steph Guest

    Thanks for your answer.
    My date format is 2005-7-27

    Stephane
     
    Steph, Jul 28, 2005
    #3
  4. Steph

    Steph Guest

    In fact, my problem is :

    This script is performed correctly with a scheduled task and manually only
    if I'm using an domain admin account (Run as or login).
    With an user, member of the Administrators group, it doesn't work. It's not
    a problem with rights.
    I don't understand!!

    Startdate = date
    Set objShell = WScript.CreateObject("WScript.Shell")
    objShell.Run ("cmd /c md c:\test\"& startdate &""),1,TRUE
     
    Steph, Jul 29, 2005
    #4
  5. Hi,

    I would think that the user account uses a date format that includes
    characters that are illegal in folder names.

    Try this script instead, it will have a correct folder name regardless
    of what date format the user account have:

    '--------------------8<----------------------
    dDate = Now
    strStartdate = Year(dDate) & "-" & Right(100 + Month(dDate), 2) & "-" _
    & Right(100 + Day(dDate), 2)

    Set objShell = CreateObject("WScript.Shell")
    objShell.Run "%comspec% /c md c:\test\" & strStartdate, 1, True
    '--------------------8<----------------------
     
    Torgeir Bakken \(MVP\), Jul 29, 2005
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.