Announcement

Collapse
No announcement yet.

Help with VBS

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with VBS

    Greetings,

    I need to have the following .Bat command run in a VBS script and have not been successful. Does someone know the syntax to make this command run in a VBS script?

    Touch "C:\Documents and Settings\Administrator\NTUSER.dat"

    Touch "C:\Documents and Settings\Vendor\NTUSER.dat"

    Thank you.
    Last edited by Jonny; 4th December 2006, 18:58.

  • #2
    Re: Help with VBS

    Now I'm not very good with scripting (and I guessing that others will probably want to see what your script looks like so far and what you're trying to do) but is this what you're looking for?
    Code:
    Set objShell = CreateObject("WScript.Shell")
    objShell.Run PathAndName.bat
    Regards,
    Jeremy

    Network Consultant/Engineer
    Baltimore - Washington area and beyond
    www.gma-cpa.com

    Comment


    • #3
      Re: Help with VBS

      Thanks for the response I did not consider calling the .bat file but that would work too. I am trying to delete unused local profiles without deleting the my Vendor or Administrator accounts. I was hoping that there was a way to call touch.exe using VBS so it would all run from a VBS script.

      The .bat that I wanted to convert to VBS code for touch is above and here is the VBS I have so far that calls delprof.exe.

      <this is where the VBS code to run the touch utility would be>

      WScript.SLeep 6000

      Const MAXIMIZE_WINDOW = 3
      Set objShell = WScript.CreateObject("WScript.Shell")
      objShell.Run "delprof.exe /q /i /d:60", MAXIMIZE_WINDOW

      Thank you so much for taking the time to help me this problem was dropped in my lap and I a scripting noob.
      Last edited by Jonny; 4th December 2006, 20:19.

      Comment


      • #4
        Re: Help with VBS

        You have the Run and Exec methods on the WScript.Shell object. Either should work. "Run" is equivalent to the traditional Shell in VB.

        These are samples from the WSH documentation:

        Run Method (Windows Script Host)

        Runs a program in a new process.

        object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

        intWindowStyle Description
        0
        Hides the window and activates another window.

        1
        Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

        2
        Activates the window and displays it as a minimized window.

        3
        Activates the window and displays it as a maximized window.

        4
        Displays a window in its most recent size and position. The active window remains active.

        5
        Activates the window and displays it in its current size and position.

        6
        Minimizes the specified window and activates the next top-level window in the Z order.

        7
        Displays the window as a minimized window. The active window remains active.

        8
        Displays the window in its current state. The active window remains active.

        9
        Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.

        10
        Sets the show-state based on the state of the program that started the application.

        The following VBScript code opens a copy of the currently running script with Notepad.

        Set WshShell = WScript.CreateObject("WScript.Shell")
        WshShell.Run "%windir%\notepad " & WScript.ScriptFullName

        The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down.

        Set WshShell = WScript.CreateObject("WScript.Shell")
        Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
        So in your example, you may wish to add , TRUE to the back end of your call so your script will wait till the command completes.

        Exec Method (Windows Script Host)

        Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.

        object.Exec(strCommand)

        Example

        Dim WshShell, oExec
        Set WshShell = CreateObject("WScript.Shell")

        Set oExec = WshShell.Exec("calc")

        Do While oExec.Status = 0
        WScript.Sleep 100
        Loop

        WScript.Echo oExec.Status
        The "Do While" bit makes Exec synchronous (waits till the shell completes).

        Hope this helps.
        Last edited by rvalstar; 4th December 2006, 20:54. Reason: , true on run method
        Cheers,

        Rick

        ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

        2006-2099 R Valstar. This post is offered "as is" for discussion purposes only with no express or implied warranty of any kind including, but not limited to, correctness or fitness for use. Nothing herein shall be construed as advice. Attempting any activity based on information in this post is done at your own risk.

        Comment

        Working...
        X